I have an Android app that is crashing with the following error.
Caused by: java.lang.NoSuchFieldError: com.google.gson.FieldNamingPolicy.IDENTITY
at ir.<init>(App:72)
ja.a(App:653)
at ja.doInBackground(App:1)
at android.os.AsyncTask$2.call(AsyncTask.java)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
... 4 more
App crashed! Process: com.company.app
This doesn't crash on my Nexus S running Android 4.0 ICS, however it is crashing on another beta test device that I don't have access to. I am using the Google GSON 2.1 library.
I am also using ProGuard however if that was causing the issue I would think that would also cause the issue on my Nexus S.
Any idea why this would not occur on my test device and how I can resolve the issue?
This issue was caused by a custom Android ROM, I assume that inconsistent class files within the ROM were causing the issue as suggested in the question comments.
I fixed it by skipping GSON from obfuscation.
-keep class com.google.gson.Gson {*;}
Related
I've just built and deployed an app to Google Play. It worked well when I was running it through Android Studio but now it crashes when I download it from Google Play. Because this is my first time, I don't even know how to view the crash report/stacktrace of the app that was downloaded from Google Play. I appreciate any and all help.
UPDATE
So I got the stacktrace for the APK. It tells me that my TopImageFragment.java class cannot create my MemeViewModel.java class. I have no clue why its giving this error. Everything works fine as it is. It seems that proguard is indeed phasing out an important class:
2019-04-18 00:46:32.062 8099-8099/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ozbek.onur.memegenerator, PID: 8099
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ozbek.onur.memegenerator/com.ozbek.onur.memegenerator.MainActivity}: java.lang.RuntimeException: Cannot create an instance of class com.ozbek.onur.memegenerator.MemeViewModel
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2853)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2928)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1609)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6703)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:769)
Caused by: java.lang.RuntimeException: Cannot create an instance of class com.ozbek.onur.memegenerator.MemeViewModel
at android.arch.lifecycle.ViewModelProvider$NewInstanceFactory.create(ViewModelProvider.java:155)
at android.arch.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:210)
at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:134)
at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:102)
at com.ozbek.onur.memegenerator.TopImageFragment.onActivityCreated(TopImageFragment.java:89)
This kind of problem usually happens because your app deployed to Google Play was a release build and proguard minified your app and removed a class it shouldn't have. When you build in Android Studio it is a debug build that does not get minified. That's why you see the crash only from Google Play.
Before uploading to Google Play, test out your release APK file on a device and watch logcat for the error. That should tell you what class got removed by mistake and you can correct that by specifying custom proguard rules and trying again until the app stops crashing. Then when you upload to Google Play, you should be good.
You can also enable proguard in a debug build as well by changing your build.gradle file. Then when you run through Android Studio, you should see the same error as you see through Google Play.
One other alternative, you can disable proguard/minification in your release build. However this is not recommended because your app will be larger than it needs to be.
Check if you have any java files that don't have an access modifier. In my experience, just declaring a class without a public or private modifier, causes this problem.
My app suffered the same problem and it was a ProGuard kill.
Because ProGuard renames all classes unless otherwise instructed.
So, in your case, you have to add
#Keep
annotation before your class name MemeViewModel.
example,
#Keep
class MemeViewModel{
//
//
}
In my suggestion, keep your phone connected to your your PC/Laptop while you download and attempt to open it. Use Logcat on android studio, it mostly has all answers or at least errors that lead to the answers. try putting error logs here so we can have a proper look at it.
1) Try the same version of your application that you deployed on Google play store by pushing it through the android studio and see if the problem continues!
2) If same thing happens then put breakpoint on the entry point (onCreate method in most cases in MainActivity class) of your application and Go to Run->Debug "YourProject" option and do step by step debug for each command being executed and see which one is causing problem.
My project specifies support-v4-26.1.0 as one of its dependencies, which in turn uses
android.library.reference.1=../support-compat-26.1.0
android.library.reference.2=../support-media-compat-26.1.0
android.library.reference.3=../support-core-ui-26.1.0
android.library.reference.4=../support-core-utils-26.1.0
android.library.reference.5=../support-fragment-26.1.0
On Android sdk 10, this crash occurs:
Could not find class 'android.support.v4.app.FragmentManagerImpl', referenced from method android.support.v4.app.FragmentHostCallback.<init>
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: android.support.v4.app.FragmentManagerImpl
at android.support.v4.app.FragmentHostCallback.<init>(FragmentHostCallback.java:46)
at android.support.v4.app.FragmentHostCallback.<init>(FragmentHostCallback.java:63)
at android.support.v4.app.FragmentActivity$HostCallbacks.<init>(FragmentActivity.java:871)
at android.support.v4.app.FragmentActivity.<init>(FragmentActivity.java:100)
How can this be fixed?
Edit: I decompiled my apk and see that FragmentManagerImpl exists in android.support.v4.app package, so it's not a ProGuard issue.
FragmentManagerImpl implements Factory2, which requires API 11. This should be the reason for the NoClassDefFoundError exception: at moment I don't know how to fix this. I tried extending that class but it isn't public.
Anyway I'll continue looking for a solution even if API 10 isn't supported at the moment because I want to keep my app's compatibility high.
English mistakes? I'm an Italian teenager, sorry :-)
A sample app for library has ~67k methods. It has multidex enabled to overcome the 65k method limit. Unfortunately with multidex enabled the app crashes on VerifyError when trying to inject EndpointAdapter in main activity.
This issue doesn't occur when the app is proguarded and the multidex is disabled, so it must be caused by multidex and Dagger 1 problems.
I'm sure EndpointAdapter is in the main dex file, but some classes generated by Dagger are located in the second dex file generated by multidex. This issue occurs on devices with API < 21 (eg. on genymotion with KitKat 4.4.4).
Any idea why it crashes with VerifyError?
FATAL EXCEPTION: main
Process: pl.toro.libsample.debug, PID: 11775
java.lang.VerifyError: pl/toro/lib/network/EndpointAdapter
at java.lang.Class.getDeclaredConstructors(Native Method)
at java.lang.Class.getDeclaredConstructors(Class.java:574)
at dagger.internal.loaders.ReflectiveAtInjectBinding.getConstructorsForType(ReflectiveAtInjectBinding.java:232)
at dagger.internal.loaders.ReflectiveAtInjectBinding.create(ReflectiveAtInjectBinding.java:168)
at dagger.internal.FailoverLoader.getAtInjectBinding(FailoverLoader.java:74)
at dagger.internal.Linker.createBinding(Linker.java:224)
at dagger.internal.Linker.linkRequested(Linker.java:141)
at dagger.ObjectGraph$DaggerObjectGraph.getInjectableTypeBinding(ObjectGraph.java:309)
at dagger.ObjectGraph$DaggerObjectGraph.inject(ObjectGraph.java:279)
at pl.toro.lib.app.BaseApplication.inject(BaseApplication.java:135)
...
Here's output of the MultiDex tag
VM with version 1.6.0 does not have multidex support
install
MultiDexExtractor.load(/data/app/pl.toro.libsample.debug-1.apk, false)
Detected that extraction must be performed.
Extraction is needed for file /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes2.zip
Extracting /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes-1477675005.zip
Renaming to /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes2.zip
Extraction success - length /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes2.zip: 187777
load found 1 secondary dex files
install done
EDIT
I've switched to Dagger 2 and this issue is resolved as of now. Dagger 2 no longer uses reflection which is the major factor of this issue.
As pointed out in this blog post[1], are you creating the dagger graph after installing the multi-dex. So in MultiDexApplication#attachBaseContext after the call to super (or calling MultiDex.install() yourself).
[1] https://developers.soundcloud.com/blog/congratulations-you-have-a-lot-of-code-remedying-androids-method-limit-part-2
Crashlytics compile('com.crashlytics.sdk.android:crashlytics:2.4.0#aar') is integrated with the app and is being tested on nexus 7 4.4.4,
The crash is seen from application onCreate method and following stacktrace is obtained. No other similar error/explaination could be found on stackoverflow.
Any suggestions are welcome.
Caused by: java.lang.TypeNotPresentException: Type com/crashlytics/android/core/internal/CrashEventDataProvider not present
at java.lang.Class.getDeclaredAnnotation(Native Method)
at java.lang.Class.getAnnotation(Class.java:290)
at io.fabric.sdk.android.Kit.containsAnnotatedDependency(Kit.java:158)
at io.fabric.sdk.android.Kit.compareTo(Kit.java:140)
at io.fabric.sdk.android.Kit.compareTo(Kit.java:33)
at java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:291)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:153)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:142)
at java.util.Arrays.sort(Arrays.java:1970)
at java.util.Collections.sort(Collections.java:1864)
at io.fabric.sdk.android.Fabric.initializeKits(Fabric.java:401)
at io.fabric.sdk.android.Fabric.init(Fabric.java:375)
at io.fabric.sdk.android.Fabric.setFabric(Fabric.java:332)
at io.fabric.sdk.android.Fabric.with(Fabric.java:303)
at com.xxxx.MainApplication.onCreate(MainApplication.java:19)
Apparently android limiatation of 65K methods is the problem on pre-lollipop devices, the problem is not due to crashalytics library per-se but in general one might run into this problem due to limitation of 65K methods at dalvik level.
Thanks to http://frogermcs.github.io/MultiDex-solution-for-64k-limit-in-Dalvik/ I was able to get the no. of methods in my .apk file.
Im using the most recent Android Studio updated today.....and also using proguard 4.9
My app runs perfectly from the studio to emulator.... but when i use proguard the app doesn't even start. I export the apk and separately install on phone or emulator, it still fails to start. I managed to get logging from the "proguarded" apk.
I use 2 external jars..... admob 6.4.1 and Google analytics V2, both are saved within the libs folder and referenced in the project set up. and run perfectly without proguard.
I appended this to my proguard.properties.txt
-libraryjars C:\Users\Paul\workspace\Xtreme Converter\libs\libGoogleAnalyticsV2.jar
-libraryjars C:\Users\Paul\workspace\Xtreme Converter\libs\GoogleAdMobAdsSdk-6.4.1.jar
but i get this logging
06-27 17:05:58.163 2194-2194/com.paul.xcon W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xb4ca6908)
06-27 17:05:58.163 2194-2194/com.paul.xcon E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.analytics.tracking.android.EasyTracker
at com.paul.xcon.ConvSel.onStart(Unknown Source)
ive tried very many variations of libjars even without the C:\ references still nothing,
Ok When i encountered the problem at first i thought adding
-libraryjars C:\Users\Paul\workspace\Xtreme Converter\libs\libGoogleAnalyticsV2.jar
-libraryjars C:\Users\Paul\workspace\Xtreme Converter\libs\GoogleAdMobAdsSdk-6.4.1.jar
would solve it..... it didn't but i left it there,
I then updated my studio and also downloaded ad loaded the latest proguard into my SDK...
It would have worked but these things i added above prevented it i think.
Its now working fine after removing them.
Try add this:
-keep class com.google.analytics.tracking.android.EasyTracker
to your proguard config file.
But in real I didn't find a way to make it work with Android Dev Studio.