juliansteenbakker / mobile_scanner

A universal scanner for Flutter based on MLKit. Uses CameraX on Android and AVFoundation on iOS.
BSD 3-Clause "New" or "Revised" License
852 stars 499 forks source link

Fatal exception: CameraX-core_camera_0 on 3.2.0 #614

Closed JakubBizewski closed 9 months ago

JakubBizewski commented 1 year ago

Hello, I encountered an issue with this plugin on Android release version. When the camera starts after granting permission, the application crashes unexpectedly. This issue does not occur on the debug version or any other platform.

Device: AVD with Android 13, Motorola Moto E20, Huawei P30 pro mobile_scanner version: 3.2.0 Flutter version: 3.3.10 Android SDK: 33

Stack trace:

05-08 17:46:54.589 18416 18643 E AndroidRuntime: FATAL EXCEPTION: CameraX-core_camera_0
05-08 17:46:54.589 18416 18643 E AndroidRuntime: Process: com.audioguide.budapest, PID: 18416
05-08 17:46:54.589 18416 18643 E AndroidRuntime: java.lang.ExceptionInInitializerError
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at androidx.camera.camera2.e.v0.<init>(Unknown Source:149)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at androidx.camera.camera2.e.G0.<init>(Unknown Source:145)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at androidx.camera.camera2.e.w0.b(Unknown Source:34)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at androidx.camera.core.impl.U.b(Unknown Source:47)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at androidx.camera.core.H0.f(:1)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at androidx.camera.core.f.run(Unknown Source:10)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.lang.Thread.run(Thread.java:1012)
05-08 17:46:54.589 18416 18643 E AndroidRuntime: Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: androidx.camera.core.impl.B.values []
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.lang.Enum.enumValues(Enum.java:272)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.lang.Enum.-$$Nest$smenumValues(Unknown Source:0)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.lang.Enum$1.create(Enum.java:279)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.lang.Enum$1.create(Enum.java:277)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at libcore.util.BasicLruCache.get(BasicLruCache.java:63)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.lang.Enum.getSharedConstants(Enum.java:291)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.lang.Class.getEnumConstantsShared(Class.java:2461)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.util.EnumSet.getUniverse(EnumSet.java:412)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.util.EnumSet.noneOf(EnumSet.java:114)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.util.EnumSet.of(EnumSet.java:288)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at androidx.camera.camera2.e.W0.<clinit>(Unknown Source:8)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        ... 9 more
05-08 17:46:54.589 18416 18643 E AndroidRuntime: Caused by: java.lang.NoSuchMethodException: androidx.camera.core.impl.B.values []
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.lang.Class.getMethod(Class.java:2103)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.lang.Class.getDeclaredMethod(Class.java:2081)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        at java.lang.Enum.enumValues(Enum.java:269)
05-08 17:46:54.589 18416 18643 E AndroidRuntime:        ... 19 more

pubspec.yaml

version: 5.0.0+50000

environment:
  sdk: ">=2.15.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  flutter_map: ^3.0.0
  location: ^4.3.0
  flutter_html: ^3.0.0-alpha.5
  url_launcher: ^6.0.9
  equatable: ^2.0.3
  http: ^0.13.3
  flutter_bloc: ^8.0.1
  intro_slider: ^3.0.2
  shared_preferences: ^2.0.7
  dio: ^4.0.0
  flutter_archive: ^5.0.0
  path_provider: ^2.0.2
  permission_handler: ^10.0.0
  rxdart: ^0.27.1
  carousel_slider: ^4.0.0
  flutter_i18n: ^0.32.2
  google_mobile_ads: ^2.0.0
  audio_service: ^0.18.3
  just_audio: ^0.9.12
  in_app_purchase: ^3.0.2
  intl: ^0.17.0
  scrollable_positioned_list: ^0.3.2
  package_info_plus: ^1.3.0
  device_info_plus: ^4.0.2
  flutter_dotenv: ^5.0.2
  flutter_math_fork: ^0.6.3+1
  async: ^2.8.2
  android_id: ^0.0.7
  dijkstra: ^0.0.3
  mobile_scanner: ^3.2.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_launcher_icons: ^0.10.0

build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 33

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.audioguide.budapest"
        minSdkVersion 21
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

Please let me know if you need any additional information or if there's a workaround for this issue. Thank you!

jbrechbuehl commented 1 year ago

Experiencing exactly the same issue with Samsung Galaxy S7 FE Android 13. I reverted back to version 3.0.0-beta.3 to make it work.

a-szotyori commented 1 year ago

We also have the same issue after we updated CameraX dependencies to 1.2.2 in our project. We are investigating currently. I'll give you an update here after we find the cause or a workaround in our project.

a-szotyori commented 1 year ago

Unfortunately we weren't able to identify the exact cause. We couldn't reproduce it locally and our client fixed it by updating their proguard rules, but they didn't tell us what they changed. Sorry I couldn't be more helpful.

DFerenczi commented 1 year ago

Hey, ran into this issue while working on my Native Android app where I've implemented camerax etc. Had a hard time figuring out the actual missing method since the stacktrace I (and you from what it seems) had was obfuscated since the crash only appeared when app was built with the release variant.

So I added debuggable true to my release variant in gradle to able to get some better stacktraces. The crash stacktrace now included the name of the missing method which made me try adding this to the proguard-rules.pro file:

-keep public class androidx.camera.core.impl.CameraCaptureMetaData$** { *; }

and bing bang bong it worked for me. Hopefully this works for you as well!

AtamerSahin commented 1 year ago

Hey, ran into this issue while working on my Native Android app where I've implemented camerax etc. Had a hard time figuring out the actual missing method since the stacktrace I (and you from what it seems) had was obfuscated since the crash only appeared when app was built with the release variant.

So I added debuggable true to my release variant in gradle to able to get some better stacktraces. The crash stacktrace now included the name of the missing method which made me try adding this to the proguard-rules.pro file:

-keep public class androidx.camera.core.impl.CameraCaptureMetaData$** { *; }

and bing bang bong it worked for me. Hopefully this works for you as well!

After adding the following line, app didn't crash. However, i have a new problem now. I am trying to scan a barcode but the device does not show the camera visuals though it scans the barcode successfully.

jbrechbuehl commented 1 year ago

Hey, ran into this issue while working on my Native Android app where I've implemented camerax etc. Had a hard time figuring out the actual missing method since the stacktrace I (and you from what it seems) had was obfuscated since the crash only appeared when app was built with the release variant.

So I added debuggable true to my release variant in gradle to able to get some better stacktraces. The crash stacktrace now included the name of the missing method which made me try adding this to the proguard-rules.pro file:

-keep public class androidx.camera.core.impl.CameraCaptureMetaData$** { *; }

and bing bang bong it worked for me. Hopefully this works for you as well!

Thank you so much @DFerenczi. It worked for me too.

puri-new commented 1 year ago

Hey, ran into this issue while working on my Native Android app where I've implemented camerax etc. Had a hard time figuring out the actual missing method since the stacktrace I (and you from what it seems) had was obfuscated since the crash only appeared when app was built with the release variant.

So I added debuggable true to my release variant in gradle to able to get some better stacktraces. The crash stacktrace now included the name of the missing method which made me try adding this to the proguard-rules.pro file:

-keep public class androidx.camera.core.impl.CameraCaptureMetaData$** { *; }

and bing bang bong it worked for me. Hopefully this works for you as well!

I've already attempted this recommendation, but it's still not effective in my case. Does anyone have any other suggestions I could try ?

adidevsoft commented 9 months ago

Not sure how this is working for anybody on android. In release mode, there seem to be at least some functions which, are not added to proguard exceptions and get minified or shaken out, and crash with "NoSuchMethodExcpetion". The last working version was 2.1.0, every version after that seems to be broken.

adidevsoft commented 9 months ago

Seems to be a problem with 2.1.0 as well. At least on compileSdkVersion 34 and android 14 on a pixel 7 pro.