Skip to content
Advertisement

java.lang.ExceptionInInitializerError when running flutter release mode

My flutter app works fine in debug mode. But, when I run it with flutter run --release I am getting the following error.

E/AndroidRuntime(18551):    java.lang.ExceptionInInitializerError
E/AndroidRuntime(18551):    at e.c.M1.o.forTarget(Unknown Source:0)
E/AndroidRuntime(18551):    at e.c.M1.p.a(:1)
E/AndroidRuntime(18551):    at e.c.J0.b(:2)
E/AndroidRuntime(18551):    at com.google.firebase.firestore.p0.V.e(:2)
E/AndroidRuntime(18551):    at com.google.firebase.firestore.p0.r.call(Unknown Source:2)
E/AndroidRuntime(18551):    at c.d.a.b.l.O.run(Unknown Source:4)
E/AndroidRuntime(18551):    at com.google.firebase.firestore.q0.G.a(:1)
E/AndroidRuntime(18551):    at com.google.firebase.firestore.q0.l.run(Unknown Source:4)
E/AndroidRuntime(18551):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(18551):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime(18551):    at java.lang.Thread.run(Thread.java:923)
E/AndroidRuntime(18551): Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: e.c.J1.values []
E/AndroidRuntime(18551):    at java.lang.Enum.enumValues(Enum.java:270)
E/AndroidRuntime(18551):    at java.lang.Enum.access$000(Enum.java:61)
E/AndroidRuntime(18551):    at java.lang.Enum$1.create(Enum.java:277)
E/AndroidRuntime(18551):    at java.lang.Enum$1.create(Enum.java:275)
E/AndroidRuntime(18551):    at libcore.util.BasicLruCache.get(BasicLruCache.java:63)
E/AndroidRuntime(18551):    at java.lang.Enum.getSharedConstants(Enum.java:289)
E/AndroidRuntime(18551):    at java.lang.Class.getEnumConstantsShared(Class.java:2428)
E/AndroidRuntime(18551):    at java.util.EnumSet.getUniverse(EnumSet.java:407)
E/AndroidRuntime(18551):    at java.util.EnumSet.noneOf(EnumSet.java:109)
E/AndroidRuntime(18551):    at java.util.EnumSet.of(EnumSet.java:235)
E/AndroidRuntime(18551):    at e.c.M1.o.<clinit>(Unknown Source:100)
E/AndroidRuntime(18551):    ... 11 more
E/AndroidRuntime(18551): Caused by: java.lang.NoSuchMethodException: e.c.J1.values []
E/AndroidRuntime(18551):    at java.lang.Class.getMethod(Class.java:2072)
E/AndroidRuntime(18551):    at java.lang.Class.getDeclaredMethod(Class.java:2050)
E/AndroidRuntime(18551):    at java.lang.Enum.enumValues(Enum.java:267)
E/AndroidRuntime(18551):    ... 21 more

I’ve tried some ways like upgrading gradle, upgrading some dependencies to latest versions. But still it’s not solved. Can you give any ideas on how to solve this?

Advertisement

Answer

I am using flutter and , I have found solution.

There are some steps , you must do, please follow correctly:

STEP 1:

In /Android/app folder:

find below files: proguard-android.txt proguard-rules.pro

if they are not exists create them, with same name.

STEP 2:

Paste this code into both files (proguard-android.txt and proguard-rules.pro):

   -keep class io.grpc.** {*;}
   -keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

STEP 3:

in /Android/app/build.gradle make sure that, theese lines have added:

 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 //If in debug, change release to debug

        minifyEnabled true
        useProguard true
        shrinkResources true

        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' *//I add this line...*
    } }

STEP 4:

in terminal of Android Studio

flutter clean

then

flutter pub get

after theese steps it must work.

Advertisement