Android Studio - Unable to resolve class L after upgrade - android

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

Related

com.iceteck.silicompressorr.provider.GenericFileProvider doesn't found and crash app

When I install app on the device with the android 4.4 app crashed and I get this error in the logcat.
But app installs and correctly work on the above android.
How can I fix this error
I also add the below code on the manifiests.xml and didn't get any result
<provider
android:name="com.iceteck.silicompressorr.provider.GenericFileProvider"
android:authorities="${applicationId}.silli.provider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
Error:
java.lang.RuntimeException: Unable to get provider com.iceteck.silicompressorr.provider.GenericFileProvider: java.lang.ClassNotFoundException: Didn't find class "com.iceteck.silicompressorr.provider.GenericFileProvider" on path: DexPathList[[zip file "/data/app/ir.mspars.azmoun-9.apk"],nativeLibraryDirectories=[/data/app-lib/ir.mspars.azmoun-9, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5131)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4722)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4605)
at android.app.ActivityThread.access$1600(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5511)
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 "com.iceteck.silicompressorr.provider.GenericFileProvider" on path: DexPathList[[zip file "/data/app/ir.mspars.azmoun-9.apk"],nativeLibraryDirectories=[/data/app-lib/ir.mspars.azmoun-9, /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:5116)
you may have not selected the lowest Android version when you are creating a new project.
if this is the problem try this
https://www.youtube.com/watch?v=D5lRTCaqhII&ab_channel=CodeDocu_com

Exception "java.lang.ClassNotFoundException: Didn't find class..." on Android 4.4.2

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.

Android NoClassDefFoundError on android 4.4.2

When I try to run my app on Android 4.4.2 it is giving me this error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: my.package, PID: 24775
java.lang.NoClassDefFoundError: my/package/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.package.models.Transaction" on path: DexPathList[[zip file "/data/app/my.package-1.apk"],nativeLibraryDirectories=[/data/app-lib/my.package-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
However, for Android 5.0 and above it is working without any errors.
What is the reason and how can I fix it?
Note: there is a similar question on StackOverflow but it does not have any answers.
You can find the answer for this question here:
NoClassDefFoundError with Android Studio on Android 4
https://developer.android.com/studio/build/multidex
Try this
Just go to disable Instant Run Go to
File -> Settings -> Build,Execution, Deployment -> Instant Run ->
Uncheck the checkbox for instant run
Run your app once.

Firebase library not working in <= Lolypop devices

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.

java.lang.RuntimeException: Unable to instantiate application

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

Categories

Resources