In my current project I'm using FCM for notifications. Its good and its working fine, but whenever I try to open the application in any device less than lolypop i.e. version 21 it crashes at the beginning.
I did check out a lot of SO posts, but never saw anyone has fixed it as an answer.
I'm using the latest version libraries as below
compile 'com.google.android.gms:play-services:9.8.0'
compile 'com.google.android.gms:play-services-auth:9.8.0'
compile 'com.google.firebase:firebase-core:9.8.0'
compile 'com.google.firebase:firebase-messaging:9.8.0'
Please help, I need to provide support atleast upto jellybean devices.
CRASH LOG:
FATAL EXCEPTION: main
Process: com.arpaul.geocare, PID: 3127
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.arpaul.geocare-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.arpaul.geocare-2, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:4793)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4385)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4325)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.arpaul.geocare-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.arpaul.geocare-2, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.ActivityThread.installProvider(ActivityThread.java:4778)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4385)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4325)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop
Your dependency on com.google.android.gms:play-services:9.8.0 is including ALL the Google Play Services APIs, most of which you don't need. This needlessly increases the size of your APK and build time. It is also probably causing the app to have more than 64K method references, which on older devices requires Multidex, as explained here.
Instead, you should remove the dependency for com.google.android.gms:play-services:9.8.0 and replace it with the specific APIs you need. Instructions for that are provided here in the section titled Selectively compiling APIs into your executable.
Related
I have an app using Ionic 3 and Cordova-Android 6.4.0. The app works fine on Android API levels > 19 (Kitkat). But running the app on Android 4.4 causes the app to crash at startup with the following exception:
03-21 14:07:40.513 2408-2408/com.xxx.app.xxx E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxx.app.xxx, PID: 2408
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.xxx.app.xxx/com.xxx.app.xxx.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.xxx.app.xxx.MainActivity" on path: DexPathList[[zip file "/data/app/com.xxx.app.xxx-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.xxx.app.xxx-2, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.xxx.app.xxx.MainActivity" on path: DexPathList[[zip file "/data/app/com.xxx.app.xxx-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.xxx.app.xxx-2, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
I've read about the multidex fix, but I can't apply it to my Ionic app because I can't change the generated Java code to add MultiDex.install(this);.
Does anyone have a solution for this?
The problem and solution are described here.
The java.lang.ClassNotFoundException comes from the fact that the app and its libraries exceed 65,536 methods, and as a result the Java classes are spread across more than one DEX file (Dalvik EXecutable) within the app's APK, i.e. classes.dex, classes2.dex etc. Java classes required to start the app may end up in classes2.dex within the app's APK (as opposed to classes.dex), which can then not be loaded by the Dalvik runtime in Android versions less than 5. From the Android web site:
When building each DEX file for a multidex app, the build tools perform complex decision-making to determine which classes are needed in the primary DEX file so that your app can start successfully. If any class that's required during startup is not provided in the primary DEX file, then your app crashes with the error java.lang.NoClassDefFoundError.
The solution is to identify every class that is referenced at app startup in a text file, as described in the link at the start of my post.
However, the list of required classes is long and hard to establish. I got as far as the classes below, but there are still more startup classes to discover. My solution is to say "Sorry, this app is only available for Android 5 and later".
com/mycompany/app/myapp/MainActivity.class
org/apache/cordova/CallbackMap.class
org/apache/cordova/ConfigXmlParser.class
org/apache/cordova/CordovaActivity$1.class
org/apache/cordova/CordovaActivity.class
org/apache/cordova/CordovaInterface.class
org/apache/cordova/CordovaInterfaceImpl.class
org/apache/cordova/CordovaPreferences.class
org/apache/cordova/CordovaWebViewEngine.class
org/apache/cordova/engine/SystemWebViewEngine.class
org/apache/cordova/LOG.class
org/apache/cordova/PluginEntry.class
org/json/JSONException.class
org/json/JSONObject.class
When I try to run my existing application (using Android Studio 3.1.3) on Android 4.4.2 it is not running and showing this error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: my.project, PID: 9428
java.lang.NoClassDefFoundError: uz/uno/models/Transaction
at java.lang.Class.getDeclaredFields(Native Method)
at java.lang.Class.getDeclaredFields(Class.java:610)
at com.activeandroid.util.ReflectionUtils.getDeclaredColumnFields(ReflectionUtils.java:73)
at com.activeandroid.TableInfo.<init>(TableInfo.java:66)
at com.activeandroid.ModelInfo.loadModelFromMetaData(ModelInfo.java:101)
at com.activeandroid.ModelInfo.<init>(ModelInfo.java:61)
at com.activeandroid.Cache.initialize(Cache.java:66)
at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:44)
at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:34)
at com.activeandroid.content.ContentProvider.onCreate(ContentProvider.java:39)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1591)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1562)
at android.app.ActivityThread.installProvider(ActivityThread.java:5233)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4827)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4710)
at android.app.ActivityThread.access$1600(ActivityThread.java:174)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1367)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "my.project.models.Transaction" on path: DexPathList[[zip file "/data/app/my.project-5.apk"],nativeLibraryDirectories=[/data/app-lib/my.project-5, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
Pay attention to the exception:
Caused by: java.lang.ClassNotFoundException: Didn't find class "my.project.models.Transaction" on path: DexPathList[[zip file "/data/app/my.project-5.apk"],nativeLibraryDirectories=[/data/app-lib/my.project-5, /vendor/lib, /system/lib]]
I found out that everytime when I try to run and it crashes the number in the exception increases my.project-5. (First time it was my.project-1, then my.project-2, and so on).
What is the problem and how can I fix this error?
Note: This error is also occuring on android 4.3. However, for android 5.0 and above it is working well.
Edit: Answer
After doing some research, I found the answer here:
NoClassDefFoundError with Android Studio on Android 4
https://developer.android.com/studio/build/multidex
I think you have a conflict with some code that requires at least android 5.0 but you are running in 4.4.2.
See the documentation here: https://developer.android.com/training/basics/supporting-devices/platforms and here: https://developer.android.com/guide/practices/compatibility
Post the code so we can help you better.
In Google Play Developer Console I see this crash:
java.lang.RuntimeException: Unable to instantiate application com.example.MyApp: java.lang.ClassNotFoundException: Didn't find class "com.example.MyApp" on path: DexPathList[[zip file "/mnt/asec/com.example.testapp-1/pkg.apk"],nativeLibraryDirectories=[/mnt/asec/com.example.testapp-1/lib, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4545)
at android.app.ActivityThread.access$1500(ActivityThread.java:160)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1390)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5330)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.MyApp" on path: DexPathList[[zip file "/mnt/asec/com.example.testapp-1/pkg.apk"],nativeLibraryDirectories=[/mnt/asec/com.example.testapp-1/lib, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:975)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
... 11 more
Suppressed: java.io.IOException: unable to open DEX file
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:296)
at dalvik.system.DexFile.<init>(DexFile.java:80)
at dalvik.system.DexFile.<init>(DexFile.java:59)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:263)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:230)
at dalvik.system.DexPathList.<init>(DexPathList.java:112)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:65)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:57)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:326)
at android.app.LoadedApk.makeApplication(LoadedApk.java:508)
... 11 more
This crash occurs mostly on Android versions 4.4 and 4.2.
This answer suggests that this crash occurs when the apk is updated by dalvik. It seems to be a low-priority Android bug.
Are there any workarounds for this?
Does it help to set
<application
android:allowBackup="false"
in Manifest.xml?
(Maybe the backup of application is stored on SD-card, which is causing the problem on apk update).
This error usually occurs when you declare a class extending Application (android.app.Application) and then user android:name="thatClassName"
But if your App can't access it class fully. This error can occur
Try Making the class public only
It will make the application user that class globally
I've recently upgraded my tools and build.gradle to version 21 in Android Studio.
My apk now crashes on load and I get the following error:
Unable to resolve superclass of Lcom/mypackage/MyClass;
Link of class 'Lcom/mypackage/MyClass
Is anyone experiencing similar issues?
I've tried the following but no success:
Cleaning the project
Restarting android studio
Re-importing the project
More log details:
java.lang.RuntimeException: Unable to instantiate application com.mypackage.MyClass:
java.lang.ClassNotFoundException: Didn't find class "com.mypackage.MyClass" on path:
DexPathList[[zip file "/data/app/com.mypackage-1.apk"],nativeLibraryDirectories=[/data/app-
lib/com.mypackage-1, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:507)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4301)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mypackage.MyClass" on path:
DexPathList[[zip file "/data/app/com.mypackage-1.apk"],nativeLibraryDirectories=[/data/app-
lib/com.mypackage-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:975)
at android.app.LoadedApk.makeApplication(LoadedApk.java:502)
I later found out that this was an issue relating to multi dexing.
I needed to run a script to generate the names of the files for my main-dex-list
The blog post below has a detailed outline of this: http://blog.osom.info/2014/10/generating-main-dex-list-file.html
My Xamarin Android app is already in production, people are downloading it from Google play and everything seems to be fine, except from time to time I get following errors in Google Play Developer Console :
java.lang.RuntimeException: Unable to instantiate application mono.android.app.Application: java.lang.ClassNotFoundException: Didn't find class "mono.android.app.Application" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib, /vendor/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:559)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5119)
at android.app.ActivityThread.access$1500(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1418)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "mono.android.app.Application" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:982)
at android.app.LoadedApk.makeApplication(LoadedApk.java:550)
... 11 more
or similar but slightly different version:
java.lang.RuntimeException: Unable to instantiate application mono.android.app.Application: java.lang.ClassNotFoundException: Didn't find class "mono.android.app.Application" on path: /mnt/asec/myapp-1/pkg.apk
at android.app.LoadedApk.makeApplication(LoadedApk.java:504)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4563)
at android.app.ActivityThread.access$1400(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "mono.android.app.Application" on path: /mnt/asec/myapp-1/pkg.apk
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newApplication(Instrumentation.java:985)
at android.app.LoadedApk.makeApplication(LoadedApk.java:499)
... 11 more
I've got zero google results for ClassNotFoundException + mono.android.app.Application. According to Developer console it comes from android 4.2 and 4.4., different devices (HTC, Samsung..), even from devices which i tested and everything works (HTC One).
Any ideas? Is this bug in mono? or Xamarin? Or am I doing something wrong?
Whenever xamarin app install in the device it is find to mono runtime support lib, if it is not installed in the device then it will stop to run so, if u have run without mono installation you can change some settings on:
Property => Android Option
Go to Packaging and select only one Bundle assemblies into native code, and also go to linker and select linking is None then run it.
I hope it might work.