Flutter ClassNotFoundException (java.lang.RuntimeException) crash error

3,010
ndk {
    abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
}

fixed it. Add the line to app/build.gradle

Share:
3,010
t0m3r
Author by

t0m3r

Updated on December 21, 2022

Comments

  • t0m3r
    t0m3r over 1 year

    Recently, I uploaded my Flutter app to Play Store. My app crashed after installing and opening the app. I've got several Crash Reports. I did researched everywhere about this error and found nothing, I even contacted Google Play's Support.

    I am using Firebase Auth, cloud_firestore, google_sign_in... (check pubspec.yamll)

    Help will be appreciated

    Flutter Doctor:

    Active code page: 1252
    Doctor summary (to see all details, run flutter doctor -v):
    [√] Flutter (Channel stable, v1.17.3, on Active code page: 1252
    
    Microsoft Windows [Version 10.0.18363.836], locale he-IL)
    
    [√] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
    [√] Android Studio (version 3.6)
    [!] IntelliJ IDEA Community Edition (version 2019.3)
        X Flutter plugin not installed; this adds Flutter specific functionality.
        X Dart plugin not installed; this adds Dart specific functionality.
    [√] VS Code (version 1.45.1)
    [√] Connected device (1 available)
    
    ! Doctor found issues in 1 category.
    

    pubspec.yaml:

    name: iusefully
    description: Be more productive
    
    # The following defines the version and build number for your application.
    # A version number is three numbers separated by dots, like 1.2.43
    # followed by an optional build number separated by a +.
    # Both the version and the builder number may be overridden in flutter
    # build by specifying --build-name and --build-number, respectively.
    # In Android, build-name is used as versionName while build-number used as versionCode.
    # Read more about Android versioning at https://developer.android.com/studio/publish/versioning
    # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
    # Read more about iOS versioning at
    # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
    version: 2.0+1
    
    module:
      androidX: true
    
    environment:
      sdk: ">=2.5.2 <3.0.0"
    
    dependencies:
      flutter:
        sdk: flutter
    
      google_sign_in: 4.5.1 
      firebase_auth: 0.16.1
      firebase_core: ^0.4.5
      firebase_analytics: ^5.0.14
      # cloud_firestore: ^0.13.0+1
      cloud_firestore: 0.13.6
    
      rxdart: 0.20.0
      cupertino_icons: ^0.1.2
      provider: ^4.0.4
      flutter_phoenix: "^0.1.0"
      animations: ^1.0.0+5
      curved_navigation_bar: ^0.3.2
      flutter_spinkit: "^4.1.2"
    
    
    
      # The following adds the Cupertino Icons font to your application.
      # Use with the CupertinoIcons class for iOS style icons.
    
    dev_dependencies:
      flutter_test:
        sdk: flutter
    
    
    # For information on the generic Dart part of this file, see the
    # following page: https://dart.dev/tools/pub/pubspec
    
    # The following section is specific to Flutter.
    flutter:
    
      # The following line ensures that the Material Icons font is
      # included with your application, so that you can use the icons in
      # the material Icons class.
      uses-material-design: true
    
      # To add assets to your application, add an assets section, like this:
      # assets:
      #  - images/a_dot_burr.jpeg
      #  - images/a_dot_ham.jpeg
      assets:
        - images/google.png
        - images/login.png
        - images/human1.png
        - images/onboarding0.png
        - images/onboarding1.png
        - images/onboarding2.png
    
      # An image asset can refer to one or more resolution-specific "variants", see
      # https://flutter.dev/assets-and-images/#resolution-aware.
    
      # For details regarding adding assets from package dependencies, see
      # https://flutter.dev/assets-and-images/#from-packages
    
      # To add custom fonts to your application, add a fonts section here,
      # in this "flutter" section. Each entry in this list should have a
      # "family" key with the font family name, and a "fonts" key with a
      # list giving the asset and other descriptors for the font. For
      # example:
      # fonts:
      #   - family: Schyler
      #     fonts:
      #       - asset: fonts/Schyler-Regular.ttf
      #       - asset: fonts/Schyler-Italic.ttf
      #         style: italic
      #   - family: Trajan Pro
      #     fonts:
      #       - asset: fonts/TrajanPro.ttf
      #       - asset: fonts/TrajanPro_Bold.ttf
      #         weight: 700
      #
      fonts:
        - family: RobotoMono
          fonts:
            - asset: fonts/RobotoMono-Bold.ttf
        - family: NotoSans
          fonts:
            - asset: fonts/NotoSans-Regular.ttf
    
      # For details regarding fonts from package dependencies,
      # see https://flutter.dev/custom-fonts/#from-packages
    

    app/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 = '2.0+1'
    }
    
    def flutterVersionName = localProperties.getProperty('flutter.versionName')
    if (flutterVersionName == null) {
        flutterVersionName = '2.0'
    }
    
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
    
    // def keystorePropertiesFile = rootProject.file("key.properties")
    // def keystoreProperties = new Properties()
    def keystoreProperties = new Properties()
    def keystorePropertiesFile = rootProject.file('key.properties')
    if (keystorePropertiesFile.exists()) {
        keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
    }
    
    android {
        compileSdkVersion 28
    
        sourceSets {
            main.java.srcDirs += 'src/main/kotlin'
        }
    
        lintOptions {
            disable 'InvalidPackage'
        }
    
        defaultConfig {
            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
            applicationId "CLASSIFIED"
            minSdkVersion 23
            targetSdkVersion 28
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
            multiDexEnabled true
            ndk {
                abiFilters 'x86', 'armeabi-v7a'
            }
        }
    
        signingConfigs {
           release {
               keyAlias keystoreProperties['keyAlias']
               keyPassword keystoreProperties['keyPassword']
               storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
               storePassword keystoreProperties['storePassword']
           }
        }
    
        buildTypes {
            release {
                // TODO: Add your own signing config for the release build.
                // Signing with the debug keys for now, so `flutter run --release` works.
                signingConfig signingConfigs.release
                minifyEnabled true
            }
        }
    }
    
    flutter {
        source '../..'
    }
    
    dependencies {
        implementation 'com.android.support:multidex:1.0.3'
        implementation 'android.arch.lifecycle:common-java8:1.1.0'
    
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    }
    
    apply plugin: 'com.google.gms.google-services'
    

    build.gradle (root)

    buildscript {
        ext.kotlin_version = '1.3.50'
        repositories {
            google()
            jcenter()
        }
    
        dependencies {
            //classpath 'com.android.tools.build:gradle:3.2.1' // 3.5.0
            classpath 'com.android.tools.build:gradle:3.4.2'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'com.google.gms:google-services:4.0.1'
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
        }
    }
    
    rootProject.buildDir = '../build'
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
        project.evaluationDependsOn(':app')
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    
    • I have keystore (.jks) as well. But I think the problem isn't there.
    • I am using app bundles

    Thanks in advance :)

    Crash Log (using master channel):

    Launching lib\main.dart on Android SDK built for x86 in debug mode...                                                                                                                                                                                                D
    Active code page: 1252
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    Active code page: 1252
    Active code page: 1252
    Note: D:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.13.6\android\src\main\java\io\flutter\plugins\firebase\cloudfirestore\CloudFirestorePlugin.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    Running Gradle task 'assembleDebug'...                                  
    Running Gradle task 'assembleDebug'... Done                        41.9s
    √ Built build\app\outputs\flutter-apk\app-debug.apk.
    Installing build\app\outputs\flutter-apk\app.apk...                 2.6s
    E/FlutterLoader( 6685): Flutter initialization failed.
    E/FlutterLoader( 6685): java.util.concurrent.ExecutionException: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.tomeruby.iusefully-0JfExLxHhUqLUimkj6h-1Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.tomeruby.iusefully-0JfExLxHhUqLUimkj6h-1Q==/lib/x86, /system/lib, /vendor/lib]]] couldn't find "libflutter.so"
    E/FlutterLoader( 6685):         at java.util.concurrent.FutureTask.report(FutureTask.java:123)
    E/FlutterLoader( 6685):         at java.util.concurrent.FutureTask.get(FutureTask.java:193)
    E/FlutterLoader( 6685):         at io.flutter.embedding.engine.loader.FlutterLoader.ensureInitializationComplete(FlutterLoader.java:193)
    E/FlutterLoader( 6685):         at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:207)
    E/FlutterLoader( 6685):         at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:188)
    E/FlutterLoader( 6685):         at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:154)
    E/FlutterLoader( 6685):         at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.setupFlutterEngine(FlutterActivityAndFragmentDelegate.java:229)
    E/FlutterLoader( 6685):         at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onAttach(FlutterActivityAndFragmentDelegate.java:151)
    E/FlutterLoader( 6685):         at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:409)
    E/FlutterLoader( 6685):         at android.app.Activity.performCreate(Activity.java:7009)
    E/FlutterLoader( 6685):         at android.app.Activity.performCreate(Activity.java:7000)
    E/FlutterLoader( 6685):         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
    E/FlutterLoader( 6685):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
    E/FlutterLoader( 6685):         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
    E/FlutterLoader( 6685):         at android.app.ActivityThread.-wrap11(Unknown Source:0)
    E/FlutterLoader( 6685):         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
    E/FlutterLoader( 6685):         at android.os.Handler.dispatchMessage(Handler.java:106)
    E/FlutterLoader( 6685):         at android.os.Looper.loop(Looper.java:164)
    E/FlutterLoader( 6685):         at android.app.ActivityThread.main(ActivityThread.java:6494)
    E/FlutterLoader( 6685):         at java.lang.reflect.Method.invoke(Native Method)
    E/FlutterLoader( 6685):         at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    E/FlutterLoader( 6685):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
    E/FlutterLoader( 6685): Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.tomeruby.iusefully-0JfExLxHhUqLUimkj6h-1Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.tomeruby.iusefully-0JfExLxHhUqLUimkj6h-1Q==/lib/x86, /system/lib, /vendor/lib]]] couldn't find "libflutter.so"
    E/FlutterLoader( 6685):         at java.lang.Runtime.loadLibrary0(Runtime.java:1011)
    E/FlutterLoader( 6685):         at java.lang.System.loadLibrary(System.java:1657)
    E/FlutterLoader( 6685):         at io.flutter.embedding.engine.loader.FlutterLoader$1.call(FlutterLoader.java:145)
    E/FlutterLoader( 6685):         at io.flutter.embedding.engine.loader.FlutterLoader$1.call(FlutterLoader.java:140)
    E/FlutterLoader( 6685):         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    E/FlutterLoader( 6685):         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    E/FlutterLoader( 6685):         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    E/FlutterLoader( 6685):         at java.lang.Thread.run(Thread.java:764)
    
    • Chinky Sight
      Chinky Sight almost 4 years
      Can you please past the whole crash logs? Flutter ClassNotFoundException (java.lang.RuntimeException) crash error It's just saying that you are having a runtime exception nothing more. Plus whenever you are publishing your app to Playstore, it's always a good practice to push your app to alpha or beta track to test your app before pushing it to production. I usually create .apk file release before publishing it to play store so that I can test it on real device as well :D
    • t0m3r
      t0m3r almost 4 years
      sure, check update.
    • Chinky Sight
      Chinky Sight almost 4 years
      Did you build a release .apk file and tested on real devices ?
    • t0m3r
      t0m3r almost 4 years
      yes, published to play store and it just crashed immediately on startup. Never happened before
    • t0m3r
      t0m3r almost 4 years
      I should mention that it is a differnet problem on Android 9 and Android 10, The error log is from Android 9 emulator.
    • Chinky Sight
      Chinky Sight almost 4 years
      I see I guess the problem is with the master channel. Why don't you try to run the app on stable ?
    • t0m3r
      t0m3r almost 4 years
      I ran it on stable before, but when I ran it on master... It showed the error logs.
    • t0m3r
      t0m3r almost 4 years
      I changed to master just today.
    • Chinky Sight
      Chinky Sight almost 4 years
      Are you testing something on master ?
    • t0m3r
      t0m3r almost 4 years
      What do you mean?
    • Chinky Sight
      Chinky Sight almost 4 years
      I mean that flutter suggest to build apps on the stable channel, so I thought you were testing your app on master channel
    • t0m3r
      t0m3r almost 4 years
      oh, I built the app on stable the whole time. I moved to master because I thought that the happened occurred after flutter upgrade so I tried flutter downgrade and it said to move to master channel
    • Chinky Sight
      Chinky Sight almost 4 years
      hehe stable channel is named stable because it is stable. If you are building a production-ready app then you should always go with stable. If you want to test some new features on Flutter then use the beta, dev, and master channels. For example, if you want to try flutter web then you should change your channel to beta because its still undergoing some changes and updates and not ready production.
    • t0m3r
      t0m3r almost 4 years
  • Jignesh Patel
    Jignesh Patel over 3 years
    I generated an app.aab file using - flutter build appbundle. so then after I need to add ndk { abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a' } it will work for .aab or I need to create APK with this command - flutter build apk
  • FurkanKURT
    FurkanKURT over 3 years
    I think its working both aab and apk builds. github.com/flutter/flutter/issues/37566#issuecomment-6478005‌​55