question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[CameraX] App crashes api < 21

See original GitHub issue
  • Android version 4.4.4, API 19
  • dependencies: androidx.camera:camera-core:1.0.0-alpha06 androidx.camera:camera-camera2:1.0.0-alpha06

Problem I’m trying to use this library only for API > 21, but i also can’t run my application for API < 21 . I want to use this library like this:

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            useOldCamera();
        } else {
            useCameraX();
        }

When i run my application, i get crash with this exception: E/UncaughtException: java.lang.NoClassDefFoundError: android.util.Size

I’m trying to use this method, but it’s not help: stackoverflow

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
peterdkcommented, Dec 2, 2019

@owahltinez Here another vote, I want to use CameraX where possible, but write the code for legacy Camera myself, with a conditional SDK_INT check. Now just adding the implementations makes the app crash. I need to support 4.1+, so I really don’t understand why it cannot be used conditionally.

implementation 'androidx.camera:camera-core:1.0.0-alpha06'
implementation 'androidx.camera:camera-camera2:1.0.0-alpha06'
 if (Build.VERSION.SDK_INT >= 21)
        {
            cameraApi = CameraXApi(view.texture_view)
        }else
        {
            cameraApi = Camera1Api(view.texture_view)
        }
E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.VerifyError: androidx/camera/camera2/impl/Camera2CameraFactory
        at androidx.camera.camera2.Camera2AppConfig.create(Camera2AppConfig.java:55)
        at androidx.camera.camera2.impl.Camera2Initializer.onCreate(Camera2Initializer.java:45)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1058)
        at android.app.ActivityThread.installProvider(ActivityThread.java:4560)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:4190)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4132)
        at android.app.ActivityThread.access$1300(ActivityThread.java:130)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
3reactions
roffelcommented, Oct 29, 2019

@owahltinez But before I could write an if statement stating if < api 21 use the deprecated camera so I could still build for Android 4.x. That is not possible anymore.

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - While trying to implement CameraX, the app crashes
When I try to run it, the app crashes And AndroidStudio gives this error in logcat: https://i2.paste.pics/c77714ec26373276884c6d490f3bbe40.
Read more >
Android application with cameraX library crash on start for API ...
I don't used any androidx.camera.core.CameraX function in API <21 ,but application still crash on start. Beasuse CameraX is initialized in app startup through...
Read more >
CameraX API causes emulator to crash : r/androiddev - Reddit
If I set the camera to Emulated the app crashes with the divide by zero error. If I set the camera to VirtualScene...
Read more >
CameraX | Android Developers
CodecException , especially on API 21-22 devices. ... However, this fix only prevents app from crashing, but doesn't resolve the cause of the ......
Read more >
Issues with CameraX video library - Google Groups
I recently tried replacing the old video capture api with the new one and ... and my app just crashes when it manually...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found