My application was working fine on Debug mode. Unfortunately after uploading to Google Play Store I found that the app is crashing. I searched several similar questions all of which suggested to disable Proguard or check the Log outputs. However I have come across the following cases when using the release Build Variant:
1- In normal case when minifyEnabled
is true
the app crashes and I am not able to see any Log outputs. There are No Debuggable Processes.
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
2- Making debuggable true
my app works fine. But again I am not able to see any error Logs because the app is working fine.
release {
debuggable true
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
3- Commenting minifyEnabled true
the app works. But I lose minification benefits.
release {
shrinkResources true
//minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
Also tried hardcoding android:debuggable="true"
in AndroidManifest.XML which gives error.
The strange thing is that by setting debuggable to true the app works fine. I am not sure whether I should keep debuggable true
in the release mode or disable minification, Or any other workaround to tackle this issue.
I will be very grateful if anyone could share how to solve this problem.
UPDATE: by running Android Device Monitor I was able to find the problem:
01-28 00:28:13.764: E/AndroidRuntime(4806): FATAL EXCEPTION: main
01-28 00:28:13.764: E/AndroidRuntime(4806): Process: com.example.myapp, PID: 4806
01-28 00:28:13.764: E/AndroidRuntime(4806): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.SearchView.setSearchableInfo(android.app.SearchableInfo)' on a null object reference
01-28 00:28:13.764: E/AndroidRuntime(4806): at com.example.myapp.MainActivity.onCreateOptionsMenu(Unknown Source)
01-28 00:28:13.764: E/AndroidRuntime(4806): at android.app.Activity.onCreatePanelMenu(Activity.java:3142)
01-28 00:28:13.764: E/AndroidRuntime(4806): at android.support.v4.b.n.onCreatePanelMenu(Unknown Source)
01-28 00:28:13.764: E/AndroidRuntime(4806): at android.support.v7.view.i.onCreatePanelMenu(Unknown Source)
01-28 00:28:13.764: E/AndroidRuntime(4806): at android.support.v7.app.h$b.onCreatePanelMenu(Unknown Source)
01-28 00:28:13.764: E/AndroidRuntime(4806): at android.support.v7.view.i.onCreatePanelMenu(Unknown Source)
01-28 00:28:13.764: E/AndroidRuntime(4806): at android.support.v7.app.q.j(Unknown Source)
01-28 00:28:13.764: E/AndroidRuntime(4806): at android.support.v7.app.q$1.run(Unknown Source)
01-28 00:28:13.764: E/AndroidRuntime(4806): at android.os.Handler.handleCallback(Handler.java:739)
01-28 00:28:13.764: E/AndroidRuntime(4806): at android.os.Handler.dispatchMessage(Handler.java:95)
01-28 00:28:13.764: E/AndroidRuntime(4806): at android.os.Looper.loop(Looper.java:148)
01-28 00:28:13.764: E/AndroidRuntime(4806): at android.app.ActivityThread.main(ActivityThread.java:7329)
01-28 00:28:13.764: E/AndroidRuntime(4806): at java.lang.reflect.Method.invoke(Native Method)
01-28 00:28:13.764: E/AndroidRuntime(4806): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
01-28 00:28:13.764: E/AndroidRuntime(4806): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Apps on Android can crash because of low storage space, too many apps running simultaneously, a weak internet connection, or not having the proper app updates installed.
The easiest way to fix an app that keeps crashing on your Android smartphone is to simply force stop it and open it again. To do this, go to Settings -> Apps and select the app that keeps crashing. Tap on the app's name and then tap on 'Force stop'. Now try opening the app again and see if it works well.
minify is an Android tool that will decrease the size of your application when you go to build it. It's extremely useful as it means smaller apk files! It detects any code or libraries that aren't being used and ignores them from your final apk.
Looks like Proguard wasn't able to handle the SearchView widget properly. I added the following line to proguard-rules.pro file located inside app folder and the problem disappeared:
-keep class android.support.v7.widget.SearchView { *; }
Now I don't need to set minifyEnabled to false.
For those who still aren't able to see the error logs in the android studio or reproduce the crashes on release builds, they can use an online crash reporting tool.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With