The second Android 11 Developer Preview is now available, test it out and share your feedback.

CameraX

CameraX is an addition to Android Jetpack that makes it easier to add camera capabilities to your app. The library provides a number of compatibility fixes and workarounds to help make the developer experience consistent across many devices.

For information on how to use the CameraX library in your app or library, see CameraX Overview.

Latest Update Current Stable Release Next Release Candidate Beta Release Alpha Release
April 1, 2020 - - 1.0.0-beta02 -

Declaring dependencies

To add a dependency on CameraX, you must add the Google Maven repository to your project. Read Google's Maven repository for more information.

Add the dependencies for the artifacts you need in the build.gradle file for your app or module:

dependencies {
  // CameraX core library using the camera2 implementation
  def camerax_version = "1.0.0-beta02"
  implementation "androidx.camera:camera-camera2:${camerax_version}"
  // If you want to use the CameraX View class
  implementation "androidx.camera:camera-view:1.0.0-alpha09"
  // If you want to use the CameraX Extensions library
  implementation "androidx.camera:camera-extensions:1.0.0-alpha09"
  // If you want to use the CameraX Lifecycle library
  implementation "androidx.camera:camera-lifecycle:${camerax_version}"
}

Camera-Camera2 and Camera-Core Version 1.0.0

Camera-Camera2 Version 1.0.0-beta02

April 1, 2020

androidx.camera:camera-camera2:1.0.0-beta02 is released. Version 1.0.0-beta02 contains these commits.

Bug Fixes

  • Fixed the ImageInfo.getRotationDegrees() from the ImageProxy produced by ImageCapture so that it matches the EXIF orientation rotational value. (Id4281, b/150802561)
  • Explicit ordering of CameraX dependencies within build.gradle is no longer required to use the default CameraX/Camera2 implementation. For cases where declaring strict dependencies is required, all CameraX dependencies can now be included in the build file. (I46e88)
  • Fixed the IllegalArgumentException issue happening on the devices where the display size is smaller than 640x480. (Ife3f2, b/150506192)
  • Fixed bindToLifecycle so that it only modifies the UseCase if it successfully binds. Previously when calling bindToLifecycle in order to do resolution calculations the UseCase is updated. Now it no longer needs to update the UseCase to do the calculations (I78d9e)

Camera-Core Version 1.0.0-beta02

April 1, 2020

androidx.camera:camera-core:1.0.0-beta02 is released. Version 1.0.0-beta02 contains these commits.

Bug Fixes

  • Fixed the ImageInfo.getRotationDegrees() from the ImageProxy produced by ImageCapture so that it matches the EXIF orientation rotational value. (Id4281, b/150802561)
  • Fixed bindToLifecycle so that it only modifies the UseCase if it successfully binds. Previously when calling bindToLifecycle in order to do resolution calculations the UseCase is updated. Now it no longer needs to update the UseCase to do the calculations (I78d9e)
  • Fixed an issue where the Preview use case's capture session wasn't being updated when the preview surface changed after calling Preview.setSurfaceProvider() more than once.

Camera-Camera2 Version 1.0.0-beta01

February 26, 2020

androidx.camera:camera-camera2:1.0.0-beta01 is released. Version 1.0.0-beta01 contains these commits.

Bug Fixes

  • Renamed SurfaceRequest.setSurface(Surface) to SurfaceRequest.provideSurface(Surface), and SurfaceRequest.setWillNotComplete() to SurfaceRequest.willNotProvideSurface(). (I224fe)
  • Fixed an issue with the aspect ratio of a saved image not being correct after changing the target rotation value using ImageCapture.setTargetRotation(). (I474ea, b/148763432)
  • Fixed initialization of app variants with ProGuard enabled by preserving the flag that sets the default CameraXConfig provider. (I2d6c1)

Camera-Core Version 1.0.0-beta01

February 26, 2020

androidx.camera:camera-core:1.0.0-beta01 is released. Version 1.0.0-beta01 contains these commits.

API Changes

  • Replaced the ListenableFuture on SurfaceRequest.provideSurface() with an Executor and Callback. This simplifies the API by no longer requiring handling of exceptions on provideSurface() and enforces that the provideSurface() callback cannot be cancelled. This is to prevent crashes on older devices caused by prematurely releasing surfaces. The SurfaceRequest.Result object is now used for tracking how a SurfaceRequest uses the provided Surface. (I7854b)
  • Renamed SurfaceRequest.setSurface(Surface) to SurfaceRequest.provideSurface(Surface) and SurfaceRequest.setWillNotComplete() to SurfaceRequest.willNotProvideSurface(). (I224fe)

Bug Fixes

  • Fixed an issue with the aspect ratio of a saved image not being correct after changing the target rotation value using ImageCapture.setTargetRotation(). (I474ea, b/148763432)
  • Fixed initialization of app variants with ProGuard enabled by preserving the flag that sets the default CameraXConfig provider. (I2d6c1)
  • Updated documentation for flash mode APIs to include possible values. (I4a3ec)

Camera-Camera2 Version 1.0.0-alpha10

February 10, 2020

androidx.camera:camera-camera2:1.0.0-alpha10 is released. Version 1.0.0-alpha10 contains these commits.

Bug Fixes

  • Improved stability on INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY devices by ensuring Surfaces are only retained for duration of use by Camera2. (I9dac2)
  • Fixed underexposed preview issue on LEGACY devices by adjusting CONTROL_AE_TARGET_FPS_RANGE properly. (1224638)

Camera-Core Version 1.0.0-alpha10

February 10, 2020

androidx.camera:camera-core:1.0.0-alpha10 is released. Version 1.0.0-alpha10 contains these commits.

API Changes

  • Updated ImageCapture to allow saving images to Uri and OutputStream. Combined overloaded takePicture methods into one. Updated test app to use Uri as the canonical example. (Ia3bec)
  • Preview.PreviewSurfaceProvider has been renamed to Preview.SurfaceProvider. SurfaceProviders no longer require developers to create their own ListenableFuture, and providing a Surface is now done through a new SurfaceRequest object. The Preview.getPreviewSurfaceProvider() method has been removed due to its potential for misuse when Preview is paired with other classes such as PreviewView. (I20105)
  • Added getTargetRotation() and getTargetName() to Preview. (Iceee7)
  • Added getTargetRotation(), getBackpressureStrategy(), and getImageQueueDepth() in ImageAnalysis. (I9d6d9)
  • Added getTargetRotation() and getCaptureMode() in ImageCapture() (I5bc17)
  • The arguments that were previously passed in ImageCapture.OnImageSavedCallback.onError() and ImageCapture.OnImageCapturedCallback.onError() have now been replaced by a single argument ImageCaptureException, which still contains all the information that was previously passed.
  • The file argument previously passed in ImageCapture.OnImageSavedCallback.onImageSaved() has been removed. (I750d2)
  • Preview and ImageCapture classes are now marked final. (I2500b)
  • API updated, with getZoomRatio(), getMaxZoomRatio(), getMinZoomRatio(), and getLinearZoom() methods of CameraInfo merging into getZoomState() which returns a ZoomState instance. (Ib19fe)
  • Removed API fields OPTION_TARGET_CLASS and OPTION_TARGET_NAME from CameraXConfig as they are intended for internal library use only. Removed constructor for CameraXConfig.Builder. (I96912)
  • Removed requirement that app must extend Application in order to initialize CameraX. CameraX will now be initialized with a default Camera2 configuration as long as the camera-camera2 artifact is included in the application's build.gradle. (I58ff5) (b/146923574)

Camera-Camera2 Version 1.0.0-alpha09

January 22, 2020

androidx.camera:camera-camera2:1.0.0-alpha09 is released. Version 1.0.0-alpha09 contains these commits.

API changes

  • Add camera2 interop path for extracting a Camera2 camera ID. You can extract the camera ID from CameraInfo using Camera2CameraInfo.extractCameraId(). The following code sample shows how to use this:

    Camera camera = provider.bindToLifecycle(...);
    String cameraId =
        Camera2CameraInfo.extractCameraId(camera.getCameraInfo());
    

    The Camera2CameraInfo class requires the ExperimentalCamera2Interop markerClass.

Camera-Core Version 1.0.0-alpha09

January 22, 2020

androidx.camera:camera-core:1.0.0-alpha09 is released. Version 1.0.0-alpha09 contains these commits.

API changes

  • The SurfaceOrientedMeteringPointFactory parameter useCaseForSurface was renamed to useCaseForAspectRatio and the reference documentation was expanded.
  • FocusMeteringAction.Builder.from() methods are replaced by the constructors FocusMeteringAction.Builder().
  • Removed DisplayOrientedMeteringPointFactory(android.content.Context, androidx.camera.core.CameraSelector, float, float). Applications should use the constructor that takes a Display parameter and pass in the current display.
  • Javadoc improvements for focus and metering APIs regarding MeteringMode and 3A Flags, and usage of Display parameter.
  • Expanded the reference documentation for setZoomRatio and setLinearZoom.

Bug fixes

  • Fixed issues when closing then opening cameras resulting in "Precondition" check failure.
  • Fixed a ConcurrentModificationException that could occur when using torch and zoom APIs.
  • Fixed issue to now select resolutions closer to requested resolution when a mod16 dimensions size is available.
  • startFocusMetering and cancelFocusMetering APIs now behave as documented, with correct timing and potentially returning errors when they occur.
  • Fixed issue when a specific target resolution was requested with a crop aspect ratio on a device that doesn’t support such sizes. Now, a non-cropped size of sufficient resolution to bound the original request will be selected when available.

Camera-Camera2 Version 1.0.0-alpha08

December 18, 2019

androidx.camera:camera-camera2:1.0.0-alpha08 is released. Version 1.0.0-alpha08 contains these commits.

Known Issues

  • Not all Camera2 capture request options work when using the Camera2 interop. If the requested option is not supported, the session fails to start and an error like this may occur: 09-09 14:04:13.643 10117 26020 26036 E AndroidRuntime: java.lang.IllegalArgumentException: Unsupported session configuration combination

Bug Fixes

  • Fixed an issue in which a preview black screen occurred after rotating or switching the camera for API Levels 21 and 22.

API Changes

  • Experimental: Added a camera2 interop path for extracting the Camera ID.

Camera-Core Version 1.0.0-alpha08

December 18, 2019

androidx.camera:camera-core:1.0.0-alpha08 is released. Version 1.0.0-alpha08 contains these commits.

Known Issues

  • Apps using the PreviewView or CameraView may have the wrong aspect ratio preview. This happens after pause or resume on some FULL devices, such as the Pixel2.

Bug Fixes

  • Updated the documentation for FocusMeteringAction and CameraControl.
  • Implemented TorchControl for enableTorch() and getTorchState().

API Changes

  • Hid IntDefs and moved IntDef constants outside of the IntDef definition.
  • Moved rotationDegrees from class OnImageCaptureCallback to ImageInfo.
  • Moved rotationDegrees from class Analyzer to ImageInfo.

Camera-Camera2 Version 1.0.0-alpha07

December 4, 2019

androidx.camera:camera-camera2:1.0.0-alpha07 is released. Version 1.0.0-alpha07 of camera-camera2 contains these commits

  • Camera2Config is now available for use with initializing and configuring a Camera2-based implementation for CameraX. More details on how to use this in initialization are in the camera-core section of the release notes.
  • The camera2 interop functionally is now marked as experimental and moved to a separate package, androidx.camera.camera2.interop.

Camera-Core Version 1.0.0-alpha07

December 4, 2019

androidx.camera:camera-core:1.0.0-alpha07 is released. Version 1.0.0-alpha07 of camera-core contains these commits

Note that there are some substantial changes in this Alpha release as we prepare for Beta. We recommend you review the changes and share any feedback you may have on the CameraX Google group. For those developers using CameraX in apps that are on the Play store, we recommend waiting for the formal Beta release before upgrading the library within your applications.

API changes

  • Important: CameraX initialization has changed. Applications should implement CameraXConfig.Provider, and use the default Camera2Config provided by androidx.camera.camera2. A typical usage is:

    import androidx.camera.camera2.Camera2Config
    import androidx.camera.core.CameraXConfig
    
    public class MyCameraXApplication : Application(),  CameraXConfig.Provider {
        override fun getCameraXConfig(): CameraXConfig {
                return Camera2Config.defaultConfig(this)
        }
    }
    
  • The CameraX class has been removed. The bindToLifecycle(), unbind(), unbindAll(), isBound(), and hasCamera() previously provided by the CameraX class call are now available via the ProcessCameraProvider.

  • A per-process instance of ProcessCameraProvider is obtained asynchronously using the static method ProcessCameraProvider.getInstance(), which returns a listenable future, which provides the ProcessCameraProvider on completion. Here it is shown in onCreate() for a typical usage. You can place calls to getInstance() later in the activity’s lifecycle to defer initialization latency to a later time (such as when a user action opens a camera UI).

    import androidx.camera.lifecycle.ProcessCameraProvider
    import com.google.common.util.concurrent.ListenableFuture
    
    class MainActivity : AppCompatActivity() {
       private lateinit var cameraProviderFuture : ListenableFuture<ProcessCameraProvider>
       override fun onCreate(savedInstanceState: Bundle?) {
           cameraProviderFuture = ProcessCameraProvider.getInstance(this);
      }
    
  • A listener can be added to the ListenableFuture returned by getInstance(). This ensures the camera provider can be retrieved from the Future without blocking on Future.get()

    cameraProviderFuture.addListener(Runnable {
      val cameraProvider = cameraProviderFuture.get()
      cameraProvider.bindToLifecycle(...)
    }, ContextCompat.getMainExecutor(this))
    
  • Camera selection is now done by a camera selector, instead of per-use case

    val cameraSelector = CameraSelector.Builder().requireLensFacing(LensFacing.BACK).build()
    
  • CameraProvider.bindToLifecycle is given the lifecycle owner, the camera selector, and use cases, which are then bound to the given lifecycle owner and run for the selected camera.

    cameraProvider.bindToLifecycle(this as LifecycleOwner,
           cameraSelector, preview, imageAnalysis)
    
  • Use case “Config” classes are removed. Instead, build use cases directly, setting options on each use case builder. For example:

    preview = Preview.Builder().setTargetAspectRatio(AspectRatio.RATIO_16_9).build()
    
  • The Preview use case has been updated to accept a surface created and managed by the application to ensure Android best practices. It is highly recommended to use the PreviewView view class provided in the camera-view package.

    preview.setPreviewSurfaceProvider(previewView.previewSurfaceProvider)
    
  • See documentation for attaching an app-managed surface. In these cases the app manages the lifecycle of the surface.

  • Important: The ImageAnalysis Analyzer method implementation must call image.close() on received images when finished using them. Otherwise, new images may not be received or the camera may stall, depending on back pressure setting. Refer to the reference docs for details.

  • ImageAnalysis ImageReaderMode is now changed to a backpressure strategy intdef.

  • ImageProxy.getImage() is marked as experimental. Applications should annotate usage for example via @androidx.camera.core.ExperimentalGetImage

  • The UIThread annotation requirement for the Analyzer has been removed.

  • The ImageAnalysis.clearAnalyzer() function is added for removing an analyzer.

  • Listeners with more than 1 method have been renamed to Callback:

    • ImageCapture.OnImageCapturedListener is now ImageCapture.OnImageCapturedCallback
    • ImageCapture.OnImageSavedListener is now ImageCapture.OnImageSavedCallback
    • VideoCapture.OnVideoSavedListener is now VideoCapture.OnVideoSavedCallback
  • Enums have changed to IntDef

  • Zoom controls have been added:

    • CameraControl.setLinearZoom()
    • CameraControl.setZoomRatio()
    • CameraInfo.getLinearZoom()
    • CameraInfo.getMaxZoomRatio()
    • CameraInfo.getZoomRatio()
  • CameraInfo.hasFlashUnit() is added to determine if flash/torch hardware is present.

  • CameraInfo.isFlashAvailable() has been removed. Torch overrides flash functionality. More detail is included in the reference documentation.

  • ImageCapture.Metadata fields are replaced by get/set/is accessors.

  • startFocusMetering and cancelFocusMetering now return ListenableFutures which represent the asynchronous operation of the call.

  • MeteringPoints are now functioning as handles to metering actions, and are produced by factories. Apps should use the existing factories rather than custom factories.

Fixed issues

  • Fixed issue when taking a picture on resuming (after a previous pause had take pictures pending completion).
  • Known Issue: CameraControl.enableTorch() is functional but the returned ListenableFuture<Void> is always an immediate complete(success) future, even if there is no flash unit. Future versions will fix this to the final behavior: When there is no flash unit, enableTorch(true) fails immediately (won't send request to CaptureSession), and TorchState remain Off.
  • Known Issue: startFocusAndMetering and cancelFocusAndMetering start and cancel focus metering, but return an immediately completed (success) future not representing the documented behavior. The FocusMeteringResult from ListenableFuture<FocusMeteringResult> CameraControl.startFocusAndMetering() is a fake result which isFocusSuccessful() and is always "false," differing from intended, documented behavior.
  • Known Issue: A metering point factory for use with PreviewView touch events is being developed. For now, apps connecting custom managed surfaces can use the existing metering point factories, and otherwise no touch focus functionality is available for PreviewView.

Camera-Camera2 and Camera-Core Version 1.0.0-alpha06

October 9, 2019

androidx.camera:camera-camera2:1.0.0-alpha06 and androidx.camera:camera-core:1.0.0-alpha06 are released. These are the commits included in camera-camera2:1.0.0-alpha06 and these are the commits included in camera-core:1.0.0-alpha06.

New features

Changes to setting aspect ratios:

  • setTargetAspectRatioMode() was added and accepts an enum argument. This sets the Aspect Ratio Mode with options RATIO_4_3 or RATIO_16_9 instead of an arbitrary aspect ratio. This closer reflects the fact that only certain aspect ratios are provided from the camera, rather than any arbitrary ratio.
    • Currently, the only available ratios are 16:9 and 4:3. In the case of 1:1, only certain devices have this available from the camera, and then only at limited resolutions. Applications designing a 1:1 interface or processing should use the more flexible 16:9 or 4:3 choices and crop the display or process a subregion.
    • These aspect ratios are oriented to use the maximum sensor area.
  • getTargetAspectRatio() was added to use case config APIs, returning the aspect ratio the use case output is targeted for.
  • The method setTargetAspectRatio(Rational aspectRatio) has been changed for ImageCapture to setTargetAspectRatioCustom(Rational aspectRatio). When set, the ImageCapture output crops accordingly.

Executor APIs

  • The following functions accept an executor parameter, which allows the app to control which executor the function runs on.
    • Preview.setOnPreviewOutputUpdateListener() API. If the executor is not present for that function, it executes on the main thread.
    • Preview.setOnPreviewOutputUpdateListener
    • FocusMeteringAction.Builder.setAutoFocusCallback
    • ImageAnalysis.setAnalyzer
    • ImageCapture.takePicture
    • CameraView.takePicture
    • CameraView.startRecording
    • VideoCapture.startRecording

CameraInfo added with check Flash Available and Sensor Rotation APIs

  • Added CameraInfo and a getCameraInfo method, which allows apps to check if a lens facing CameraInfo is available and if a flash is available on that camera. For example:

    try {
        CameraInfo cameraInfo = CameraX.getCameraInfo(currentCameraLensFacing);
        LiveData<Boolean> isFlashAvailable = cameraInfo.isFlashAvailable();
        flashToggle.setVisibility(isFlashAvailable.getValue() ? View.VISIBLE : View.INVISIBLE);
    } catch (CameraInfoUnavailableException e) {
        Log.w(TAG, "Cannot get flash available information", e);
        flashToggle.setVisibility(View.VISIBLE);
    }
    
  • CameraInfo.getSensorRotationDegrees() was added. It provides the camera sensor orientation relative to the device’s natural orientation, or for convenience, relative to an orientation described by a Surface rotation (which describes an orientation relative to natural orientation).

API changes and bug fixes

  • Aspect Ratios: For each use case, applications should call only one of setTargetResolution() or setTargetAspectRatio(). Calling both on the same builder returns an error.
    • In general it’s recommended to use setTargetAspectRatio() based on the application’s UI design. Specific resolutions are based on the use case. For example, preview is near screen resolutions and image capture provides high resolution stills. See the automatic resolutions table for more information.
    • Use setTargetResolution() for more specific cases, such as when minimum (to save computation) or maximum resolutions (for processing details) are required.
  • Executor API: Removed the setCallbackHandler() call from use case configuration APIs. Instead, applications can set the executor as a parameter in various other APIs that set a callback.
  • Updated null annotations for various functions.
  • Fixed an issue that caused java.lang.IllegalStateException at Camera$StateCallback.onError to be thrown when opening the camera.
  • Fixed issue where resolutions would be selected that were too small (less than 640x480) when app is requesting larger or default resolutions resulting in a blocky or blurry preview image. Applications that specifically need smaller resolutions can explicitly request them.
  • Fixed an issue where the camera would show black screen (failed to start the camera) after returning from an intent that launched another camera application.
  • Fixed a bug that threw the following error when apps are repeatedly started or stopped; java.lang.IllegalArgumentException: CaptureRequest contains unconfigured Input/Output Surface!
  • Fixed the following error that occurs when disabling ImageAnalysis: java.lang.IllegalStateException: maxImages (4) has already been acquired, call #close before acquiring more.
  • Added additional tests for camera disconnect flow.
  • Improved test system robustness when running back-to-back camera tests.

Camera-Camera2 and Camera-Core Version 1.0.0-alpha05

September 5, 2019

androidx.camera:camera-camera2:1.0.0-alpha05 and androidx.camera:camera-core:1.0.0-alpha05 are released. These are the commits included in camera-camera2:1.0.0-alpha05 and these are the commits included camera-core:1.0.0-alpha05.

  • API Change: Renamed use case error variables:

    • ImageCapture.UseCaseError is renamed ImageCapture.ImageCaptureError
    • VideoCapture.UseCaseError is renamed VideoCapture.VideoCaptureError
  • Added CameraControl API w/Tap-to-Focus APIs

    • Added API to get a CameraControl from CameraX for a camera, selected by lens facing:

      CameraX.getCameraControl(LensFacing lensFacing)

    • Added MeteringPointFactory, MeteringPoint, MeteringMode, and FocusMeteringAction to run Tap-to-Focus:

      MeteringPointFactory factory = new SensorOrientedMeteringPointFactory(width, height);
      MeteringPoint point = factory.createPoint(x, y);
      FocusMeteringAction action = FocusMeteringAction.Builder.from(point,
                                       MeteringMode.AF_ONLY)
          .addPoint(point2, MeteringMode.AE_ONLY) // could have many
          .setAutoFocusCallback(new OnAutoFocusListener(){
              public void onFocusCompleted(boolean isSuccess) {
              }
          })
          // auto calling cancelFocusAndMetering in 5 sec.
          .setAutoCancelDuration(5, TimeUnit.Second)
          .build();
      
    • Added API for CameraControl to start and cancel focus metering:

      getCameraControl(lensFacing).startFocusAndMetering(action); getCameraControl(lensFacing).cancelFocusAndMetering();

    • Added APIs for Metering Point Factories that assist translating tap coordinates to sensor coordinates, based on view classes:

      MeteringPointFactory factory = new TextureViewMeteringPointFactory(textureView); MeteringPointFactory factory = new DisplayOrientedMeteringPointFactory(context, lensFacing, viewWidth, viewHeight);

  • Enforce calling the following methods on the Main (UI) thread, throwing an IllegalStateException when they are not. Future versions will allow usage on other threads and ensure serialization.

    • CameraX.bindToLifecycle()
    • CameraX.unbind()
    • CameraX.unbindAll()
    • ImageAnalysis.setAnalyzer()
    • ImageAnalysis.getAnalyzer()
    • ImageAnalysis.removeAnalyzer()
    • Preview.removePreviewOutputListener()
    • Preview.getOnPreviewOutputUpdateListener()
    • Preview.setOnPreviewOutputUpdateListener()
  • Various config settings now accept null parameters and corresponding getters may return null.

  • Fixed issue when testing on emulators that do not support AF/AE/AWB settings.

  • Fixed crash bug on rotation while analyzing image.

  • Fixed bug where preview appears black on start (no camera data), after rotation or switching between front and back cameras.

  • Removed testing for multiple concurrent image analysis use cases. To ensure compatibility, applications should only attach a single image analysis use case.

  • Added initial robolectric tests for fake camera in camera-testing suite (WIP).

  • Camera2Inititalizer test removed, as its coverage was unclear/misleading.

Camera-Camera2 and Camera-Core Version 1.0.0-alpha04

August 7, 2019

androidx.camera:camera-camera2:1.0.0-alpha04 and androidx.camera:camera-core:1.0.0-alpha04 are released. Version 1.0.0-alpha04 contains these commits.

New Features

Changes to Aspect Ratio and Resolution selection

CameraX's goal is to successfully initialize a camera session. This means CameraX compromises on resolution/aspect ratios based on device capability, in order to start a capture session as its first goal, and so exact requests may not be honored. This may be due to:

  • Devices not supporting the requested resolution
  • Compatibility issues such as on LEGACY devices where certain resolutions must be used to operate correctly
  • On some devices, certain formats are only available at certain aspect ratios
  • A preference for a “nearest mod16” for JPEG or video encoding. See CameraCharacteristics#SCALER_STREAM_CONFIGURATION_MAP

Although CameraX creates and manages the session, you should always check the returned image sizes on the use case output in your code and adjust accordingly.

Some changes have been made for setting resolutions and aspect ratios, intended to make the API more clear:

  • Preview use case is now considered to have a default 4:3 aspect ratio when none is set.
  • When CameraX internally considers changes to requested resolutions and aspect ratios based on device capability, it first tries to maintain the same aspect ratio (as determined by any of setTargetAspectRatio or setTargetResolution calls)
  • A “Nearest mod16” version of the resolution is considered as the same aspect ratio.

ImageAnalysis Non-Blocking Mode

  • The behaviour of ImageReaderMode.ACQUIRE_LATEST_IMAGE is now non-blocking. It acquires the latest image in the queue, but discards unused images continuously to allow the camera pipeline to avoid blocking.
  • The analyzer can hold a single image indefinitely without stalling the pipeline.
  • If the application provides an executor which then blocks, the ImageAnalysis use case blocks.
  • The default executor set internally behaves as a non-blocking executor.

Bug Fixes

  • Fixed timeout issues waiting for 3A convergence when capturing images on devices with no auto-focus, auto exposure, and auto-whitebalance
  • Fixed issue when rapidly taking pictures with ImageCapture. Fixes error: java.lang.IllegalStateException: maxImages (2) has already been acquired
  • Fixed issue when setLensFacing was not called for a use case, resulting in java.lang.IllegalArgumentException: Unable to get camera ID for use case.
  • Fixed issue where LEGACY device required specific aspect ratio as maximum JPEG resolution
  • Fixed issue when backgrounding the app while camera is opening
  • Fixed issue on API < 25, removing error checkAndUpdateEglState: invalid current EGLDisplay
  • Fixed issue when unbinding preview after enabling and starting extensions
  • Build artifacts for camera-view and camera-extensions are now published as alpha versions

Camera-Camera2 and Camera-Core Version 1.0.0-alpha03

July 2, 2019

androidx.camera:camera-core:1.0.0-alpha03 and androidx.camera:camera-camera2:1.0.0-alpha03 are released. Version 1.0.0-alpha03 contains these commits.

API Changes

  • Added javadoc clarification for “target” in setTarget configuration calls

Camera-Core

  • Fixed unconfigured Input/Output Surface crash on rapid open/close or bind/unbind
  • Move to new Futures implementations
  • Test fixes for more robust testing
  • Core integration test now shows capture time for photos
  • Developed internal compat class for Executors
  • Timing test app capture images waits for previous to complete & improved stability

Extensions

  • Added versioning checks
  • Additional test coverage - extension event callbacks
  • Improvements for internally corresponding image and meta-data
  • Fixes to mode switching in test app

Camera-Camera2 and Camera-Core Version 1.0.0-alpha02

June 5, 2019

androidx.camera:camera-core:1.0.0-alpha02 and androidx.camera:camera-camera2:1.0.0-alpha02 are released. Version 1.0.0-alpha02 contains these commits.

Bug fixes

  • Fixed div by zero issue when using emulator
  • Fixed NullPointerException/Surface Abandoned error occurring on some devices when quickly taking photos while unbinding and rebinding use cases rapidly.
  • Fixed internal issue to ensure capture request updates affect all surfaces consistently
  • Stability improvements when restarting use cases in new app instances
  • Internal architecture changes to prepare for supporting executors in the API
  • Additional Javadoc clarifications on CameraX class and lifecycle management
  • Added instrumented testing for Antelope performance test app
  • Remove need for '-keepattributes Signature' in app Proguard config

Camera-Camera2 and Camera-Core 1.0.0-alpha01

May 7, 2019

androidx.camera:camera-core:1.0.0-alpha01 and androidx.camera:camera-camera2:1.0.0-alpha01 are released. Version 1.0.0-alpha01 contains these commits.

Camera-Lifecycle Version 1.0.0

Camera-Lifecycle Version 1.0.0-beta01

February 26, 2020

androidx.camera:camera-lifecycle:1.0.0-beta01 is released. Version 1.0.0-beta01 contains these commits.

Bug Fixes

  • Fixed documentation to note that when obtaining a ProcessCameraProvider during initialization, a default configuration is used and that extending Application is optional. (I5e395)

Camera-Lifecycle Version 1.0.0-beta02

April 1, 2020

androidx.camera:camera-lifecycle:1.0.0-beta02 is released. Version 1.0.0-beta02 contains these commits.

Bug Fixes

  • Updated to support the bug fixes in the camera-camera2:1.0.0-beta02 and camera-core:1.0.0-beta02 artifacts.

Camera-Lifecycle Version 1.0.0-alpha10

February 10, 2020

androidx.camera:camera-lifecycle:1.0.0-alpha10 is released. Version 1.0.0-alpha10 contains these commits.

API Changes

  • Added @MainThread annotation to BindToLifecycle, unbind and unbindAll methods. (I990d2)

Camera-Lifecycle Version 1.0.0-alpha03

January 22, 2020

androidx.camera:camera-lifecycle:1.0.0-alpha03 is released. Version 1.0.0-alpha03 contains these commits.

Updates

  • Various fixes and updates to support Camera Core & Camera2 changes.

Camera-Lifecycle Version 1.0.0-alpha02

December 18, 2019

androidx.camera:camera-lifecycle:1.0.0-alpha02 is released. Version 1.0.0-alpha02 contains these commits.

Dependency changes

  • Updated to use androidx.camera:camera-core:1.0.0-alpha08.

Camera-Lifecycle Version 1.0.0-alpha01

December 4, 2019

androidx.camera:camera-lifecycle:1.0.0-alpha01 is released. Version 1.0.0-alpha01 of camera-lifecycle contains these commits

API notes

  • The camera-lifecycle artifact is added, providing LifeCycleCameraProvider interface, and an implementation called ProcessCameraProvider which provides many of the functions of the previous CameraX class in core and is obtained via a getInstance() method.
  • Apps should include the camera-lifecycle library to use CameraX.
  • See notes in the camera-core section for how to perform initialization of CameraX using a ProcessCameraProvider.

Camera-Extensions and Camera-View Version 1.0.0

Camera-Extensions Version 1.0.0-alpha09

April 1, 2020

androidx.camera:camera-extensions:1.0.0-alpha09 is released. Version 1.0.0-alpha09 contains these commits.

Bug Fixes

  • Updated to support the bug fixes in the camera-camera2:1.0.0-beta02, camera-core:1.0.0-beta02, and camera-lifecycle:1.0.0-beta02 artifacts

Camera-View Version 1.0.0-alpha09

April 1, 2020 androidx.camera:camera-view:1.0.0-alpha09 is released. Version 1.0.0-alpha09 contains these commits.

Known Issues

  • Using ImplementationMode.SURFACE_VIEW with PreviewView may not work well on certain devices, this is because the SurfaceView used for preview invalidates its surface when the lifecycle of the window it's in is stopped, when it restarts, the camera is reopened and may attempt to resume preview before the SurfaceView's surface is valid again. For now, you should use ImplementationMode.TEXTURE_VIEW.

API Changes

  • Renamed PreviewView.setImplementationMode() to PreviewView.setPreferredImplementationMode().
  • Renamed PreviewView.getImplementationMode() to PreviewView.getPreferredImplementationMode().
  • Replaced PreviewView.getSurfaceProvider() by PreviewView.createSurfaceProvider(CameraInfo), which takes a nullable CameraInfo instance used to optimize preview by using ImplementationMode.SURFACE_VIEW whenever possible. If a null instance is passed, or if you set the preferred implementation mode to ImplementationMode.TEXTURE_VIEW, ImplementationMode.TEXTURE_VIEW is used internally.
  • The following code sample shows how a preview use case used to previously be used with PreviewView.

    preview.setSurfaceProvider(previewView.previewSurfaceProvider)
    cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector, preview)
    

    Right now, you can write the following:

    val camera = cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector, preview)
    previewView.preferredImplementationMode = ImplementationMode.TEXTURE_VIEW
    preview.setSurfaceProvider(previewView.createSurfaceProvider(camera.cameraInfo))
    
  • The @UiThread annotation has been added to PreviewView.getSurfaceProvider(), meaning it must be called from the main thread. (I192f3)

  • Added PreviewView.setScaleType() which allows to set the scale type of the preview. It accepts one of the values in PreviewView.ScaleType, and defaults to PreviewView.ScaleType.FILL_CENTER.

  • Added PreviewView.getScaleType().

  • Removed support for setting the implementation mode for PreviewView in a XML layout using the implementationMode attribute.

  • Add createMeteringPointFactory() API to PreviewView to support converting (x, y) in PreviewView to MeteringPoint. (Ib36d7)

Bug Fixes

  • Fixed cases where an incorrect preview is displayed after PreviewView's size changes. (I71101)

Camera-Extensions Version 1.0.0-alpha08

February 26, 2020

androidx.camera:camera-extensions:1.0.0-alpha08 is released. Version 1.0.0-alpha08 contains these commits.

Camera-View Version 1.0.0-alpha08

February 26, 2020

androidx.camera:camera-view:1.0.0-alpha08 is released. Version 1.0.0-alpha08 contains these commits.

Bug Fixes

  • Replaced the ListenableFuture on SurfaceRequest.provideSurface() with an Executor and Callback. This simplifies the API by no longer requiring handling of exceptions on provideSurface() and enforces that the provideSurface() callback cannot be cancelled. This is to prevent crashes on older devices caused by prematurely releasing surfaces. The SurfaceRequest.Result object is now used for tracking how a SurfaceRequest uses the provided Surface. (I7854b)
  • Renamed SurfaceRequest.setSurface(Surface) to SurfaceRequest.provideSurface(Surface) and SurfaceRequest.setWillNotComplete() to SurfaceRequest.willNotProvideSurface(). (I224fe)
  • Fixed initialization of app variants with ProGuard enabled by preserving the flag that sets the default CameraXConfig provider. (I2d6c1)

Camera-Extensions Version 1.0.0-alpha07

February 10, 2020

androidx.camera:camera-extensions:1.0.0-alpha07 is released. Version 1.0.0-alpha07 contains these commits.

Bug Fixes

  • The arguments that were previously passed in ImageCapture.OnImageSavedCallback.onError() and ImageCapture.OnImageCapturedCallback.onError() have now been replaced by a single argument ImageCaptureException, which still contains all the information that was previously passed.
  • The file argument previously passed in ImageCapture.OnImageSavedCallback.onImageSaved() has been removed. (I750d2)

Camera-View Version 1.0.0-alpha07

February 10, 2020

androidx.camera:camera-view:1.0.0-alpha07 is released. Version 1.0.0-alpha07 contains these commits.

API Changes

  • PreviewView's TextureView implementation now sets the TextureView's size to the camera sensor output size before scaling it to fill its parent PreviewView. If you want the camera preview to fill an entire part of the UI (the whole screen for instance), you should not set the PreviewView's size to a fixed value, or have it wrap its content (by using the attribute "wrap_content" for example), this may result in the camera preview only filling part of the PreviewView (if the camera sensor output size is smaller). Instead, you should set the PreviewView as big as its parent (by using the attribute "match_parent" for example). (1204869)

Bug Fixes

  • Updated ImageCapture to allow saving images to Uri and OutputStream. Combined overloaded takePicture methods into one. Updated test app to use Uri as the canonical example. (Ia3bec)
  • Preview.PreviewSurfaceProvider has been renamed to Preview.SurfaceProvider. SurfaceProviders no longer require developers to create their own ListenableFuture, and providing a Surface is now done through a new SurfaceRequest object. The Preview.getPreviewSurfaceProvider() method has been removed due to its potential for misuse when Preview is paired with other classes such as PreviewView. (I20105)
  • The arguments that were previously passed in ImageCapture.OnImageSavedCallback.onError() and ImageCapture.OnImageCapturedCallback.onError() have now been replaced by a single argument ImageCaptureException, which still contains all the information that was previously passed.
  • The file argument previously passed in ImageCapture.OnImageSavedCallback.onImageSaved() has been removed. (I750d2)
  • API updated, with getZoomRatio(), getMaxZoomRatio(), getMinZoomRatio(), and getLinearZoom() methods of CameraInfo merging into getZoomState() which returns a ZoomState instance. (Ib19fe)

Camera-Extensions Version 1.0.0-alpha06

January 22, 2020

androidx.camera:camera-extensions:1.0.0-alpha06 is released. Version 1.0.0-alpha06 contains these commits.

Updates

  • Various fixes and updates to support Camera Core & Camera2 changes.

Camera-View Version 1.0.0-alpha06

January 22, 2020

androidx.camera:camera-view:1.0.0-alpha06 is released. Version 1.0.0-alpha06 contains these commits.

Updates

  • Various fixes and updates to support Camera Core & Camera2 changes.

Camera-Extensions Version 1.0.0-alpha05

December 18, 2019

androidx.camera:camera-extensions:1.0.0-alpha05 is released. Version 1.0.0-alpha05 contains these commits.

Bug Fixes

  • Updated to match the internal Camera Core APIs.

Camera-View Version 1.0.0-alpha05

December 18, 2019

androidx.camera:camera-view:1.0.0-alpha05 is released. Version 1.0.0-alpha05 contains these commits.

Known Issues

  • The aspect ratio may be incorrect when using PreviewView (b/146215202).

New Features

  • Implemented a new class called PreviewView.TextureViewImplementation that syncs the SurfaceTexture's lifecycle with the camera's usage of the TextureView's surface.

Camera-Extensions Version 1.0.0-alpha04

December 4, 2019

androidx.camera:camera-extensions:1.0.0-alpha04 is released. Version 1.0.0-alpha04 of camera-extensions contains these commits

API changes

  • Checking for the availability and enabling of an extension now takes in a CameraSelector as an input parameter. This needs to be the same CameraSelector that is used for binding the use case.

    val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
    val builder = ImageCapture.Builder()
    val bokehImageCaptureExtender = BokehImageCaptureExtender.create(builder)
    if (bokehImageCaptureExtender.isExtensionAvailable(cameraSelector)) {
        bokehImageCaptureExtender.enableExtension(cameraSelector)
    }
    val imageCapture = builder.build()
    mCameraProvider?.bindToLifecycle(this, cameraSelector, imageCapture)
    
  • You must initialize extensions before using the extension library.

    val availability = ExtensionsManager.init()
    Futures.addCallback<ExtensionsManager.ExtensionsAvailability>(
       availability,
       object : FutureCallback<ExtensionsManager.ExtensionsAvailability> {
           override fun onSuccess(availability: ExtensionsManager.ExtensionsAvailability?) {
               // Ready to make extensions calls
           }
           override fun onFailure(throwable: Throwable) {
               // Extensions could not be initialized
           }
       },
       Executors.newSingleThreadExecutor()
    )
    

Camera-View Version 1.0.0-alpha04

December 4, 2019

androidx.camera:camera-view:1.0.0-alpha04 is released. Version 1.0.0-alpha04 of camera-view contains these commits

API changes

  • A PreviewView class is provided for easily displaying the output from the Preview use case in an application.
  • PreviewView can be included in the layout:

    <androidx.camera.view.PreviewView
      android:id="@+id/preview_view"
      … />
    
  • PreviewView provides a PreviewSurfaceProvider to easily connect a Preview use case

    preview.setPreviewSurfaceProvider(previewView.previewSurfaceProvider)
    
  • ZoomLevel” is now “ZoomRatio” in API-naming

  • Some method parameters have changed nullability

Camera-Extensions and Camera-View Version 1.0.0-alpha03

October 9, 2019

androidx.camera:camera-extensions:1.0.0-alpha03 and androidx.camera:camera-view:1.0.0-alpha03 are released. These are the commits included in camera-extensions:1.0.0-alpha03 and these are the commits included in camera-view:1.0.0-alpha03.

New Features

  • Added Context initializer for extensions. Extensions version incremented to 1.1.0

Camera-Extensions and Camera-View Version 1.0.0-alpha02

September 5, 2019

androidx.camera:camera-extensions:1.0.0-alpha02 and androidx.camera:camera-view:1.0.0-alpha02 are released. These are the commits included in camera-extensions:1.0.0-alpha02 and these are the commits included camera-view:1.0.0-alpha02.

  • Added tests to verify PreviewImageProcessorImpl has correctly implemented timestamps.
  • Fix ExtensionTest test failure on Nexus 5 (API level 21) and ensure preview is available.

Camera-Extensions and Camera-View Version 1.0.0-alpha01

August 7, 2019

androidx.camera:camera-extensions:1.0.0-alpha01 and androidx.camera:camera-view:1.0.0-alpha01 are released. These are the commits included in camera-extensions:1.0.0-alpha01 and these are the commits included camera-view:1.0.0-alpha01

  • New library for future Camera Extensions for accessing effects on supported devices. This library is a work in progress.
  • New Camera View class. This library is a work in progress.