NoClassDefFoundError attempting to use FatSecret REST API in Android Studio - android

I am using the FatSecretAPI in order to retreive items from their database.
I have used this library - http://ranesr.github.io/fatsecret4j/ and done the following:
Created a new module in Android Studio as a new Java Library
Copied the relevant java files across as per the structure provided in the link
Located File > Project Structure... > Modules > my app > Dependencies and added the fatsecret module as a dependency
Called the FatSecretAPI class and instantiated with both my keys as per:
FatSecretAPI api = new FatSecretAPI("my auth key", "my shared key");
Cleaned and Rebuilt the project.
Upon running the app and opening the activity this call is in, I get the following error:
FATAL EXCEPTION: main
Process: com.example.chris.rapical, PID: 7140
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/fatsecret/platform/FatSecretAPI;
at com.example.chris.rapical.FoodSearchOnlineActivity.onCreate(FoodSearchOnlineActivity.java:51)
at android.app.Activity.performCreate(Activity.java:6500)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
at android.app.ActivityThread.access$1000(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6837)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.fatsecret.platform.FatSecretAPI" on path: DexPathList[[zip file "/data/app/com.example.chris.rapical-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.example.chris.rapical.FoodSearchOnlineActivity.onCreate(FoodSearchOnlineActivity.java:51) 
at android.app.Activity.performCreate(Activity.java:6500) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218) 
at android.app.ActivityThread.access$1000(ActivityThread.java:198) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:145) 
at android.app.ActivityThread.main(ActivityThread.java:6837) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 
Suppressed: java.lang.ClassNotFoundException: com.fatsecret.platform.FatSecretAPI
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 15 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Things I have tried:
Cleaning and rebuilding the app
Deleting the /class folder and re-building
Running 'gradlew clean' on CMD at project location
All 3 have no successs.

Figured it out - When I was going to create the new Module, I selected Java library instead of Android library. Duh.

Related

AWS Amplify Crashes on Android 6

I'm trying to use AWS amplify on android 6, but the app crashes suddenly after 30 seconds after the Configuration and gets this error.
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/LocalDateTime;
at com.amplifyframework.devmenu.PersistentLogger.addToLogs(PersistentLogger.java:116)
at com.amplifyframework.devmenu.PersistentLogger.debug(PersistentLogger.java:88)
at com.amplifyframework.logging.BroadcastLogger.debug(BroadcastLogger.java:101)
at com.amplifyframework.analytics.pinpoint.AutoEventSubmitter.lambda$new$0$AutoEventSubmitter(AutoEventSubmitter.java:44)
at com.amplifyframework.analytics.pinpoint.-$$Lambda$AutoEventSubmitter$kRbNZmP2XU9xJOUcrfJ3PKgcA28.run(lambda)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.LocalDateTime" on path: DexPathList[[zip file "/data/app/com.nowpay.nowpay-1/base.apk"],nativeLibraryDirectories=[/data/app/com.nowpay.nowpay-1/lib/arm, /data/app/com.nowpay.nowpay-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.amplifyframework.devmenu.PersistentLogger.addToLogs(PersistentLogger.java:116) 
at com.amplifyframework.devmenu.PersistentLogger.debug(PersistentLogger.java:88) 
at com.amplifyframework.logging.BroadcastLogger.debug(BroadcastLogger.java:101) 
at com.amplifyframework.analytics.pinpoint.AutoEventSubmitter.lambda$new$0$AutoEventSubmitter(AutoEventSubmitter.java:44) 
at com.amplifyframework.analytics.pinpoint.-$$Lambda$AutoEventSubmitter$kRbNZmP2XU9xJOUcrfJ3PKgcA28.run(lambda) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.os.HandlerThread.run(HandlerThread.java:61) 
Suppressed: java.lang.ClassNotFoundException: java.time.LocalDateTime
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 10 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
The basic problem here is that the app is trying to reference a class which doesn't exist at runtime:
java.lang.ClassNotFoundException: Didn't find class "java.time.LocalDateTime"
Initial runtime support for java.time.* was added to Android in API Level 26. For a period of time, java.time.* only worked on these devices.
As of Android Studio 4, java.time.* APIs can be "de-sugared" at build time. When using this functionality, the resulting code will run on all versions of Android. To benefit from this support, you must have Android Studio 4 or higher, and enable "core library desugaring." See the documentation for more details: https://developer.android.com/studio/write/java8-support#library-desugaring

Profiling failed in Android Studio 3.3

I just updated Android Studio 3.2 to 3.3. It updated the Gradle plugin in my project from 3.2.1 to 3.3. Now enabling advanced profiling in Run/Debug configuration making my app crash. Clean/Rebuild/Invalidate caches don't help.
I found one way to make it work: rolling plugin back to 3.2.1 (in project build.gradle)
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
Is there any other way?
01-15 13:38:31.527 6969-6969/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.appcard.androidterminal, PID: 6969
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/android/tools/profiler/support/ProfilerService;
at com.appcard.androidterminal.AppContext.<init>(AppContext.java:53)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1606)
at android.app.Instrumentation.newApplication(Instrumentation.java:1000)
at android.app.Instrumentation.newApplication(Instrumentation.java:985)
at android.app.LoadedApk.makeApplication(LoadedApk.java:567)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4837)
at android.app.ActivityThread.access$1500(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1531)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5643)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.android.tools.profiler.support.ProfilerService" on path: DexPathList[[zip file "/data/app/com.appcard.androidterminal-1/base.apk"],nativeLibraryDirectories=[/data/app/com.appcard.androidterminal-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.appcard.androidterminal.AppContext.<init>(AppContext.java:53) 
at java.lang.reflect.Constructor.newInstance(Native Method) 
at java.lang.Class.newInstance(Class.java:1606) 
at android.app.Instrumentation.newApplication(Instrumentation.java:1000) 
at android.app.Instrumentation.newApplication(Instrumentation.java:985) 
at android.app.LoadedApk.makeApplication(LoadedApk.java:567) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4837) 
at android.app.ActivityThread.access$1500(ActivityThread.java:178) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1531) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:194) 
at android.app.ActivityThread.main(ActivityThread.java:5643) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
Suppressed: java.lang.ClassNotFoundException: com.android.tools.profiler.support.ProfilerService
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 17 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
I filled a bug, here is Google dev response:
I was able to reproduce the issue with emulator API 25 and lower.
Workaround is to use device/emulator API of 26 or higher.
https://issuetracker.google.com/issues/122944954#comment4
Update:
Yes, this has been fixed. The fix won't be in 3.3.1, but it will be in the following release.

The Firebase implementation within an AAR I'm using causes my App to crash

I had been contacted to put a new library in the form of an AAR into my application. It worked fine before adding this AAR, but after that, every time I start it up, it crashes with the following stacktrace:
09-10 21:10:55.272 10354-10354/? W/System.err: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/tasks/TaskCompletionSource;
at com.google.firebase.remoteconfig.FirebaseRemoteConfig.zza(Unknown Source)
at com.google.firebase.remoteconfig.FirebaseRemoteConfig.fetch(Unknown Source)
at com.picmix.mobile.activity.SplashActivity.onCreate(SplashActivity.java:89)
at android.app.Activity.performCreate(Activity.java:6093)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2458)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2577)
at android.app.ActivityThread.access$1000(ActivityThread.java:164)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1462)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:160)
at android.app.ActivityThread.main(ActivityThread.java:5541)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.tasks.TaskCompletionSource" on path: DexPathList[[zip file "/data/app/com.picmix.mobile-2/base.apk"],nativeLibraryDirectories=[/data/app/com.picmix.mobile-2/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 16 more
Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.tasks.TaskCompletionSource
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 17 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
From my experience, this kind of error is because I hadn't enabled MultiDex support. The strange thing is that I have it enabled, my gradle file contains the following line:
compile 'com.android.support:multidex:1.0.3'
The application I use in the manifest extends MultiDexApplication instead of just Application.
So is it something with that AAR?

Android Application crashed when share debug APK from output folder

I am working on one application that have only one screen barcode scanning and I am achieve this with zxing Library. But my problem is if I am install app with android studio it is working fine but if I share this apk from output folder with Bluetooth, Email, Xender, etc.. Application is install but when I open the app it will crash and Exception is NoClassFoundException.
Here is Logcat:
FATAL EXCEPTION: main
Process: com.jenex.cartracking, PID: 31223
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.jenex.cartracking/com.jenex.cartracking.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.jenex.cartracking.MainActivity" on path: DexPathList[[zip file "/data/app/com.jenex.cartracking-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3029)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3300)
at android.app.ActivityThread.access$1000(ActivityThread.java:211)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1705)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6946)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.jenex.cartracking.MainActivity" on path: DexPathList[[zip file "/data/app/com.jenex.cartracking-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newActivity(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3019)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3300) 
at android.app.ActivityThread.access$1000(ActivityThread.java:211) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1705) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:145) 
at android.app.ActivityThread.main(ActivityThread.java:6946) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 
Suppressed: java.lang.ClassNotFoundException: com.jenex.cartracking.MainActivity
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
You have to clean build before share the app and make a debug build.
Follow this simple steps,
Goto Build -> Clean Project
Goto Build -> Build Apk
This will generate build Apk. Share this Apk.
Hope this helps.
It seems like I have the same problem. Such an exception happens now with any project, even with empty and clean just created. I used to share myproject_debug.apk with testers, but now it crashes on start up. Maybe it started after some update of Android Studio or platform-tools, I'm not sure.
So, I found some work around that work for me
Before copy project-debug.apk from output folder:
go to menu in Android Studio and open menu 'Build'
click 'Build APK'
After successful build I copy myproject-debug.apk from output folder and it works well.

Newrelic Android plugin running on non-newrelic project, causing crash

The Newrelic Android plugin is being run on a project that has no references to Newrelic. I have another project open that does use Newrelic, and I'm using Android Studio 2.2, gradle in-process daemon, and the latest Gradle and build tools:
classpath 'com.android.tools.build:gradle:2.2.0'
and
compileSdkVersion 24
buildToolsVersion '24.0.2'
In my other project which does use Newrelic, I'm using
classpath "com.newrelic.agent.android:agent-gradle-plugin:5.+"
and
apply plugin: 'newrelic'
compile 'com.newrelic.agent.android:android-agent:5.+'
I can see the newrelic class re-write logs in the output, which should not happen
[newrelic.info] [my.class.Name] replacing call to com/google/gson/Gson.fromJson(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object; with com/newrelic/agent/android/instrumentation/GsonInstrumentation.fromJson(Lcom/google/gson/Gson;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object; (with instance check)
This then caused my apk to be built somehow missing several Activity classes, so crashes with:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{my.package/my.package.activity.home.LobbyActivity}: java.lang.ClassNotFoundException: Didn't find class "my.package.activity.home.LobbyActivity" on path: DexPathList[[zip file "/data/app/my.package-2/base.apk"],nativeLibraryDirectories=[/data/app/my.package-2/lib/arm64, /vendor/lib64, /system/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3094)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.ClassNotFoundException: Didn't find class "my.package.activity.home.LobbyActivity" on path: DexPathList[[zip file "/data/app/my.package-2/base.apk"],nativeLibraryDirectories=[/data/app/my.package-2/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newActivity(Instrumentation.java:1095)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3084)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7229) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Suppressed: java.lang.NoClassDefFoundError: my.package.activity.home.LobbyActivity
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:226)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
at dalvik.system.DexPathList.findClass(DexPathList.java:338)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
... 13 more
Suppressed: java.lang.ClassNotFoundException: my.package.activity.home.LobbyActivity
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 12 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
This is the same problem as Application crashes in onCreate due to newrelic exception, but the solutions there don't work for me. Those answers are from 2 years ago and no longer relevant (I am using a much newer Gradle version and Newrelic version, I tried deleting the .gradle and gradle project folders).

Categories

Resources