Android app crash on setting minifyEnabled true - android

Application getting crashed on enabling minifyEnabled true. When I make it false application starts working fine. Do I need to add something to my pro-guard file? I am not able to figure out what is causing an application to crash.
Here is the Gradle code:
debug {
manifestPlaceholders = [crashlyticsApiKey: '', mapApiKey: '']
// Enables code shrinking, obfuscation, and optimization for only
debuggable true
// your project's release build type.
minifyEnabled true
// Enables resource shrinking, which is performed by the
// Android Gradle plugin.
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
buildConfigField "String", "BASE_URL", '"http://"'
signingConfig signingConfigs.debug
}
Logcat Output:
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ExceptionInInitializerError
at l.b.g.f$a.<init>(:372)
at l.b.g.f.<init>(:19)
at l.b.h.m.a(:32)
at l.b.h.m.b(:42)
at l.b.h.b.b(:56)
at l.b.h.g.a(:32)
at l.b.f.a.a(:135)
at l.b.f.b$d.f(:747)
at l.b.f.b.b(:250)
at d.k.a.i.g.a(:36)
at d.k.a.i.g.doInBackground(:17)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
at java.lang.Thread.run(Thread.java:818) 
Caused by: java.lang.IllegalStateException: Could not read resource entities-xhtml.properties. Make sure you copy resources for l.b.g.i
at l.b.g.i.b(:301)
at l.b.g.i.a(:25)
at l.b.g.i$b.<init>(:53)
at l.b.g.i$b.<clinit>(:34)
at l.b.g.f$a.<init>(:372) 
at l.b.g.f.<init>(:19) 
at l.b.h.m.a(:32) 
at l.b.h.m.b(:42) 
at l.b.h.b.b(:56) 
at l.b.h.g.a(:32) 
at l.b.f.a.a(:135) 
at l.b.f.b$d.f(:747) 
at l.b.f.b.b(:250) 
at d.k.a.i.g.a(:36) 
at d.k.a.i.g.doInBackground(:17) 
at android.os.AsyncTask$2.call(AsyncTask.java:295) 
at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
at java.lang.Thread.run(Thread.java:818) 
02-10 15:19:58.687 17254-20516/? E/cjle: *~*~*~ Channel {0} was not shutdown properly!!! ~*~*~*
Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true.
02-10 15:20:25.416 17254-28037/? E/WakeLock: GCM_HB_ALARM release without a matched acquire!
Please let know what is wrong in my code.
Thanks

The error stack indicates this:
Caused by: java.lang.IllegalStateException: Could not read resource entities-xhtml.properties. Make sure you copy resources for l.b.g.i
I think this is because the resource/class l.b.g.i is excluded by ProGuard. You may want to use mappings.txt file (that contains mapping between actual class/method name and its random one generated by proGuard) to decode actual resource name and then force Proguard to keep it, something like this example https://stackoverflow.com/a/5866755/1992013 Hope this helps !

Related

App crashes in release apk which run correctly in debug mode

I have tested my app in debug mode. I have made debuggable as true in release build type in build.gradle file. When I run and test it it gives me following error
2022-10-20 13:17:16.300 26285-26285/com.metamagics.patientsapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.metamagics.patientsapp, PID: 26285
java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.metamagics.pulsepatientsapp.d.h.a()' on a null object reference
at com.metamagics.pulsepatientsapp.fragments.a.V1(:487)
at com.metamagics.pulsepatientsapp.fragments.a$f.c(:1657)
at com.metamagics.pulsepatientsapp.utilities.b.b(:129)
at com.metamagics.pulsepatientsapp.utilities.b.onPostExecute(:10)
at android.os.AsyncTask.finish(AsyncTask.java:771)
at android.os.AsyncTask.access$900(AsyncTask.java:199)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:788)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8057)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
I am not able to understand the issue, if anyone knows a better way to identify the error, I will be thankful.
If you debug a release build, it will still be minified according to your build.gradle file. Try to first set minifyEnabled = false for your release configuration. Probably the Stacktrace gives you the reason of your error. If not you might need to configure your proguard rules if minify is needed.

Flutter Firestore doesn't retrieve any data in released android apk

I have tried to develop a flutter application that uses firestore and firebase auth for authentication.
In debug mode, when I test the application it retrieves data from firestore and show it. and firebase auth also work properly.
But in release mode, Firestore doesn't retrieve any data and shows an error given below.
but Firebase auth perfectly works in release mode application.
I catch the error in release mode by using android studio build variant feature.
Thank you for reading.
E/io.grpc.internal.S1: [Channel<1>: (firestore.googleapis.com)] Uncaught exception in the SynchronizationContext. Panic!
java.lang.ExceptionInInitializerError
at m1.j.Q(Unknown Source:22)
at io.grpc.internal.D.Q(Unknown Source:4)
at io.grpc.internal.k1.A(:3)
at io.grpc.internal.a1.run(:2)
at k1.t1.a(Unknown Source:24)
at k1.t1.execute(:2)
at io.grpc.internal.K1.b(Unknown Source:9)
at io.grpc.internal.u0.a(:10)
at io.grpc.internal.u0.run(Unknown Source:38)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: o1.a.values []
at java.lang.Enum.enumValues(Enum.java:270)
at java.lang.Enum.access$000(Enum.java:61)
at java.lang.Enum$1.create(Enum.java:277)
at java.lang.Enum$1.create(Enum.java:275)
at libcore.util.BasicLruCache.get(BasicLruCache.java:63)
at java.lang.Enum.getSharedConstants(Enum.java:289)
at java.lang.Class.getEnumConstantsShared(Class.java:2428)
at java.util.EnumMap.getKeyUniverse(EnumMap.java:755)
at java.util.EnumMap.<init>(EnumMap.java:138)
at m1.v.<clinit>(:1)
at m1.j.Q(Unknown Source:22) 
at io.grpc.internal.D.Q(Unknown Source:4) 
at io.grpc.internal.k1.A(:3) 
at io.grpc.internal.a1.run(:2) 
at k1.t1.a(Unknown Source:24) 
at k1.t1.execute(:2) 
at io.grpc.internal.K1.b(Unknown Source:9) 
at io.grpc.internal.u0.a(:10) 
at io.grpc.internal.u0.run(Unknown Source:38) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
at java.lang.Thread.run(Thread.java:919) 
Caused by: java.lang.NoSuchMethodException: o1.a.values []
at java.lang.Class.getMethod(Class.java:2072)
at java.lang.Class.getDeclaredMethod(Class.java:2050)
at java.lang.Enum.enumValues(Enum.java:267)
W/Firestore: (23.0.1) [Z]: (3a36b20) Stream closed with status: o1{code=INTERNAL, description=Panic! This is a bug!, cause=java.lang.ExceptionInInitializerError
at m1.j.Q(Unknown Source:22)
at io.grpc.internal.D.Q(Unknown Source:4)
at io.grpc.internal.k1.A(:3)
at io.grpc.internal.a1.run(:2)
at k1.t1.a(Unknown Source:24)
at k1.t1.execute(:2)
at io.grpc.internal.K1.b(Unknown Source:9)
at io.grpc.internal.u0.a(:10)
at io.grpc.internal.u0.run(Unknown Source:38)
This is a common error with Firestore. The problem is with the minifyEnabled and shrinkResources fields in android/app/build.gradle.
You should be able to solve this by changing your release build type in android/app/build.gradle as follows:
buildTypes {
...
release {
...
signingConfig signingConfigs.release
minifyEnabled false
shrinkResources false
}
}
Of course this is not an ideal "solution" as the app-size becomes larger. But the Firebase team says they can't help because we use flutter which isn't officially supported...
Here are related issues:
https://github.com/FirebaseExtended/flutterfire/discussions/5708#discussioncomment-925997
https://github.com/FirebaseExtended/flutterfire/issues/1412

Android App works in debug but not in release

I'm developing an Android app and I have a problem when I run the app in release mode. If I start the app in debug mode I get this type of message in the Logcat (the app doesn't start):
E/AndroidRuntime: FATAL EXCEPTION: GoogleApiHandler
Process: it.planner, PID: 27326
java.lang.SecurityException: In order to use mock mode functionality app it.planner must be selected as the mock location
application in developer settings.
at android.os.Parcel.readException(Parcel.java:2008)
at android.os.Parcel.readException(Parcel.java:1954)
at com.google.android.gms.internal.zzeu.zzb(Unknown Source:10)
at com.google.android.gms.internal.zzcfa.zzbj(Unknown Source:9)
at com.google.android.gms.internal.zzcfd.zzbj(Unknown Source:13)
at com.google.android.gms.internal.zzcfk.zzbj(Unknown Source:2)
at com.google.android.gms.internal.zzcee.zza(Unknown Source:4)
at com.google.android.gms.common.api.internal.zzm.zzb(Unknown Source:8)
at com.google.android.gms.common.api.internal.zzc.zza(Unknown Source:6)
at com.google.android.gms.common.api.internal.zzbo.zzb(Unknown Source:9)
at com.google.android.gms.common.api.internal.zzbo.zzaiw(Unknown
Source:82)
at com.google.android.gms.common.api.internal.zzbo.onConnected(Unknown
Source:16)
at com.google.android.gms.common.internal.zzac.onConnected(Unknown
Source:2)
at com.google.android.gms.common.internal.zzn.zzakr(Unknown Source:130)
at com.google.android.gms.common.internal.zze.zzw(Unknown Source:64)
at com.google.android.gms.common.internal.zzi.zzaks(Unknown Source:51)
at com.google.android.gms.common.internal.zzh.handleMessage(Unknown
Source:270)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loop(Looper.java:166)
at android.os.HandlerThread.run(HandlerThread.java:65) E/iMonitor: FaultDetect: DUMPTOOL_PRINTF return.
Obviously, if I select the mock location in Developer Options, the app starts and works fine.
If I install the release apk and I try to start the app, the app doesn't start and I get this kind of messagge in Logcat:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: it.planner, PID: 29448
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:2054)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:2077)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:678)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:632)
at it.planner.Home.mainMenu(Home.java:374)
at it.planner.Home.computeGeolocation(Home.java:487)
at it..planner.Home.access$100(Home.java:80)
at it.planner.Home$3$1.onLocationResult(Home.java:344)
at com.google.android.gms.internal.zzcff.zzu(Unknown Source:4)
at com.google.android.gms.common.api.internal.zzci.zzb(Unknown Source:8)
at com.google.android.gms.common.api.internal.zzcj.handleMessage(Unknown
Source:16)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7377)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
There is no possibility to select the mock location once the app is in release mode, so it doesn't want to start. I've been dealing with this problem for many days. I also tried with minifyEnabled false in the Gradle file but it doesn't work.
The gradle file is the following:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
debuggable true
}
}
sourceSets {
main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] }
debug {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
This issue is probably because of the Fragment transaction was not committed using the proper API. try to find
transaction.commit();
and replace it with
transaction.commitAllowingStateLoss();
Some more discussion is here: https://github.com/OneBusAway/onebusaway-android/issues/529#issuecomment-224974339

Testing the generated signed Apk - react native

I am trying to generate a signed apk of my first react native app I followed the steps in the official site of react native
I tried this command cd android && gradlew assembleRelease and the apk is generated successfully.
but when I am trying to test this apk on my real device using cd android && gradlew installRelease , the app crashes although it works as expected on genymotion emulator.
Am I missing something ?
Any help is appreciated.
Thanks in advance
Update :
I can't debug on my device because I am always getting the red screen says Unable to download JS bundle although I had done all what is mentioned on the official website about running on the device
logcat:
03-15 16:23:13.504 24331-24331/com.kora E/ViewRootImpl: sendUserActionEvent() mView == null
03-15 16:23:13.939 24331-24359/com.kora E/unknown:React: Unable to download JS bundle
java.net.ConnectException: failed to connect to /192.168.1.6 (port 8081) after 5000ms: isConnected failed: ECONNREFUSED (Connection refused)
at libcore.io.IoBridge.isConnected(IoBridge.java:223)
at libcore.io.IoBridge.connectErrno(IoBridge.java:161)
at libcore.io.IoBridge.connect(IoBridge.java:112)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
at java.net.Socket.connect(Socket.java:843)
at com.squareup.okhttp.internal.Platform$Android.connectSocket(Platform.java:190)
at com.squareup.okhttp.Connection.connectSocket(Connection.java:196)
at com.squareup.okhttp.Connection.connect(Connection.java:172)
at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:367)
at com.squareup.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128)
at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:328)
at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:245)
at com.squareup.okhttp.Call.getResponse(Call.java:267)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
at com.squareup.okhttp.Call.access$100(Call.java:34)
at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:162)
at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: libcore.io.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
at libcore.io.IoBridge.isConnected(IoBridge.java:208)
at libcore.io.IoBridge.connectErrno(IoBridge.java:161) 
at libcore.io.IoBridge.connect(IoBridge.java:112) 
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192) 
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459) 
at java.net.Socket.connect(Socket.java:843) 
at com.squareup.okhttp.internal.Platform$Android.connectSocket(Platform.java:190) 
at com.squareup.okhttp.Connection.connectSocket(Connection.java:196) 
at com.squareup.okhttp.Connection.connect(Connection.java:172) 
at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:367) 
at com.squareup.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128) 
at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:328) 
at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:245) 
at com.squareup.okhttp.Call.getResponse(Call.java:267) 
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224) 
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195) 
at com.squareup.okhttp.Call.access$100(Call.java:34) 
at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:162) 
at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
at java.lang.Thread.run(Thread.java:841) 
03-15 16:23:13.944 24331-24331/com.kora E/ViewRootImpl: sendUserActionEvent() mView == null
Thanks to #G. Hamaide for his answer , It worked for me but with a single addition in buildTypes in app/build.gradle, which is adding this line signingConfig signingConfigs.release as mentioned in the official documentation.
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
That's plus what #G. Hamaide mentioned in his answer which is mentioned above.
Change this :
def enableProguardInReleaseBuilds = true
to this :
def enableProguardInReleaseBuilds = false
Then run the steps again to create you APK.

Android app crash by "FileNotFoundException for drawable in drawable-xhdpi-v4"

guys.I got a crash becasue of "java.io.FileNotFoundException: res/drawable-xhdpi-v4/component_tip_loading1.png".
But I unziped my apk and found the resource is existed.
And my build.gradle set minifyEnabled is true, but not set the shrinkResources.
Thanks for any advice.
Caused by: java.io.FileNotFoundException: res/drawable-xhdpi-v4/component_tip_loading1.png
at android.content.res.AssetManager.openNonAssetNative(Native Method)
at android.content.res.AssetManager.openNonAsset(AssetManager.java:405)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2443)

Categories

Resources