dependency-analysis-gradle-plugin: CameraX recommendation will lead to crashes (dependency used via reflection)

Plugin version 0.53.1

Gradle version 6.4

Android Gradle Plugin (AGP) version 4.1.0

Describe the bug Output suggests:

Unused dependencies which should be removed:
...
- implementation("androidx.camera:camera-camera2:1.0.0-beta06")
...

Removing this will lead to a crash when using CameraX:

    java.lang.IllegalStateException: CameraX is not configured properly. The most likely cause is you did not include a default implementation in your build such as 'camera-camera2'.
        at androidx.camera.core.CameraX.getOrCreateInstance(CameraX.java:854)
        at androidx.camera.lifecycle.ProcessCameraProvider.getInstance(ProcessCameraProvider.java:137)

To Reproduce Steps to reproduce the behavior:

  1. Add the following to gradle:
    implementation "androidx.camera:camera-camera2:1.0.0-beta06"
    implementation "androidx.camera:camera-view:1.0.0-alpha13"
    implementation "androidx.camera:camera-lifecycle:1.0.0-beta06"
  1. Init CameraX with ProcessCameraProvider.getInstance(activity.applicationContext)
  2. Run dependency analysis.

Expected behavior No suggestion to remove the plugin

Additional context CameraX uses reflection (androidx.camera.core.CameraX)

if (app instanceof CameraXConfig.Provider) {
            // Application is a CameraXConfig.Provider, use this directly
            configProvider = (CameraXConfig.Provider) app;
        } else {
            // Try to retrieve the CameraXConfig.Provider through the application's resources
            try {
                Resources resources = app.getResources();
                String defaultProviderClassName =
                        resources.getString(
                                R.string.androidx_camera_default_config_provider);
                Class<?> providerClass =
                        Class.forName(defaultProviderClassName);
                configProvider = (CameraXConfig.Provider) providerClass
                        .getDeclaredConstructor()
                        .newInstance();
            } catch (Resources.NotFoundException
                    | ClassNotFoundException
                    | InstantiationException
                    | InvocationTargetException
                    | NoSuchMethodException
                    | IllegalAccessException e) {
                Log.e(TAG, "Failed to retrieve default CameraXConfig.Provider from "
                        + "resources", e);
            }

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

我也有这样的问题【No default CameraXConfig.Provider specified in meta-data. The most likely cause is you did not include a default implementation in your build such as ‘camera-camera2’.】,产生这个问题的原因是我引入了https://github.com/LuckSiege/PictureSelector这个库,这个库有个自定义相机,可能跟它相互冲突了 在我将这个库给注释掉后,camerax能够正常使用

Yes, this call should suffice.