NoClassDefFoundError: com.parse.ParseObject$1 - java

I'm Running into a NoClassDefFoundError on Android 4.4, 4.3, and 4.2. I've tried all day to fix it to no avail. I've tried changing the targetSdkVersion, Parse version, importing the Parse library with a jar instead of Gradle, and cleaning and rebuilding the project. Everything works on Android 5.0 and up.
I'm using Parse version 1.12.0
CompileSdkVersion 23
buildToolsVersion 23.0.2
minSdkVersion 17
targetSdkVersion 23
Here is my stack trace. It crashes on the first attempt to register a subclass of ParseObject.
01-13 12:18:26.500 1347-1347/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.parse.ParseObject$1
at com.parse.ParseObject.<clinit>(ParseObject.java:316)
at com.company.myapp.utils.Application.onCreate(PensterApplication.java:36)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4444)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Here is the Application class where it crashes.
I've altered the class names to post online here
public class myApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(this);
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
// Parse classes that need registering
ParseObject.registerSubclass(aaa.class); //error happens here
ParseObject.registerSubclass(bbb.class);
ParseObject.registerSubclass(ccc.class);
ParseObject.registerSubclass(ddd.class);
ParseObject.registerSubclass(eee.class);
ParseObject.registerSubclass(fff.class);
ParseObject.registerSubclass(ggg.class);
ParseObject.registerSubclass(hhh.class);
ParseObject.registerSubclass(iii.class);
ParseObject.registerSubclass(jjj.class);
Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
//set a default acl so that default is not public read.write
if (ParseUser.getCurrentUser() != null) {
ParseACL defaultACL = new ParseACL(ParseUser.getCurrentUser());
defaultACL.setPublicReadAccess(false);
defaultACL.setPublicWriteAccess(false);
ParseACL.setDefaultACL(defaultACL, true);
}
// Save this installation
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseFacebookUtils.initialize(this);
ParseTwitterUtils.initialize(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
}
}
Any idea what's going wrong would be much appreciated.

I got some help from the friendly parse people on their github repo.
My issue:
https://github.com/ParsePlatform/Parse-SDK-Android/issues/342
The issue referenced from my issue:
https://github.com/ParsePlatform/Parse-SDK-Android/issues/213
The Stack Overflow Question referenced from the referenced issue. (this is what helped me solve my problem.)
Crash: java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$layout
Turns out it was a problem with multidex. I needed to extend MultiDexApplication instead of Application. I also added a couple things to my proguard rules.

This might be caused by:
aaa (presumably a subclass of ParseObject) having been built with a version of ParseObject that is different than the deployed library version, OR
myApplication being built with a version of ParseObject that is different than the deployed library version.
More likely the latter.

Related

Unable to start Chrome CustomTabsIntent in my Android app

I am trying to use Chrome Custom Tabs in my Android application. My MainActivity class extends AppCompatActivity. In onCreate, I invoke startCustomTabs. Below is the code for that:
private void startCustomTab(){
CustomTabsIntent intent = new CustomTabsIntent.Builder().setToolbarColor(getResources().getColor(R.color.colorPrimary)).build();
intent.launchUrl(this, Uri.parse("http://github.com/black-dragon/SaavnExtractor"));
}
As soon as the app launches, it crashes with following the error:
11-16 10:55:38.561 30093-30093/com.nick.saavnextractor
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.nick.saavnextractor, PID: 30093
java.lang.NoSuchMethodError: No static method
startActivity(Landroid/app/Activity;Landroid/content/Intent;Landroid/os/Bundle;)V
in class Landroid/support/v4/app/ActivityCompat; or its super classes
(declaration of 'android.support.v4.app.ActivityCompat' appears in
/data/data/com.nick.saavnextractor/files/instant-run/dex/slice-com.android.support-support-compat-25.0.0_15c83dd4ec129d2d74bfda2e34f6aeeb93d83fa1-classes.dex)
at android.support.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:262)
at com.nick.saavnextractor.MainActivity.startCustomTab(MainActivity.java:325)
at com.nick.saavnextractor.MainActivity.onCreate(MainActivity.java:111)
at android.app.Activity.performCreate(Activity.java:6311)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2539)
at android.app.ActivityThread.access$900(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1384)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5507)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Note: If I execute the same code with the same methods in a new app, the Custom Tabs launch fine.
Okay, so here is the resolution. I was using build tools version 25.0.0 but my SDK platform was 24.
Update the build tools, platform tools & SDK to same version and then you won't face this issue.
Along with #Nick's answer, I also had to update the Facebook SDK version and the crash stopped happening.
You need to add Customtabs dependency in your build.gradle file.
implementation 'com.android.support:customtabs:28.0.0'

Android build variant debug gives java.lang.NoClassDefFoundError

I have been working on a project that has been perfectly fine, until i included the android-smack-xmpp library.
After this inclusion, i am not able to run the app on devices (API < 21) on debug mode. However i am able to run it on release build variant.
Process: com.example, PID: 496
java.lang.NoClassDefFoundError: com.example.network.ServerCalls$3
at com.example.network.ServerCalls.initData(ServerCalls.java:167)
at com.example.ui.fragmentsAndActivities.homeFeed.HomePageActivity.onCreate(HomePageActivity.java:212)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
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)
ServerCalls is included in the HomePageActivity, and compilation works just fine. What is that i could be missing here ?
Also HomePageActivity.java:212 is :
ServerCalls.samosaInitData()
Edit : I have been able to get it working my setting minifyEnabled and shrinkResources to true in gradle for the debug build. This is probably pointing at improper linking in the JVM. But this looks like a hack to me. Can somebody point me to a cleaner way of doing the same?
The error was multi-dexing the solution.
The smack-api library introduction led to the 64k dex limit to be exceeded.
Multidexing the solution does the trick.
It looks like you don't export your library in the final .apk file.
You have to choose the Compile option in your Android Studio project settings in the Dependencies section.

NoClassDefFoundError on Android Studio project that builds fine

I am not an Android developer, but I am trying to upgrade the Facebook SDK for an app I have on Android Studio. The previous SDK was 3.5 and I am trying to add 4.4.1
I have written the login class by following the getting started guide but now when I try to launch the app on a device, although it compiles just fine, it crashes on startup.
I get the following error:
08-05 21:05:25.128 25207-25207/? E/dalvikvm﹕ Could not find class
'com.history.HistoryOrder', referenced from method
com.service.Global. 08-05 21:05:25.138 25207-25207/?
E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at com.imperautus.testProject.ActivitySplash.onCreate(ActivitySplash.java:61)
at android.app.Activity.performCreate(Activity.java:5326)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2218)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2309)
at android.app.ActivityThread.access$700(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
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.NoClassDefFoundError: com.history.HistoryOrder
at com.service.Global.(Global.java:113)
            at com.imperautus.testProject.ActivitySplash.onCreate(ActivitySplash.java:61)
            at android.app.Activity.performCreate(Activity.java:5326)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2218)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2309)
            at android.app.ActivityThread.access$700(ActivityThread.java:157)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
            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)
What I see is that it complaints that it cannot find the class com.history.HistoryOrder but this class is in this exact place and it worked before the transition to the new Facebook SDK (I haven't touched the class' code).
The Global.java:113 says:
public static ArrayList<HistoryOrder> historyOrderList = new ArrayList<HistoryOrder>();
public static HistoryOrder historyOrderItem = new HistoryOrder();
I also changed all references in my code from app.Fragment to the support.v4.app.Fragment version because I thought that this caused the problem.
Any clues?
java.lang.NoClassDefFoundError is propably thrown because you have reached the 65k limit http://developer.android.com/tools/building/multidex.html#about
If you need to go beyond 65k limit you must include multidex support
gradle:
defaultConfig {
...
multiDexEnabled true
}
...
dependencies {
compile 'com.android.support:multidex:1.0.1'
...
}
Manifest:
<application
...
android:name="android.support.multidex.MultiDexApplication">
If you have a Custom Application class:
extend MultiDexApplication or add MultiDex.install(getBaseContext()); to your CustomApplication onCreate()
Note that on some low-end devices adding
MultiDex.install(getBaseContext()); to your CustomApplication onCreate()
can still throw java.lang.NoClassDefFoundError:
If so try adding MultiDex.install to attachBaseContext(Context base) instead
public class CustomApplication extends Application {
...
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(base);
}
...
ok, it seems that the error was due to a very different reason:
The app was updated to use Google Services 7.5 which made the methods go to more than 65k which made me to add the mutiDexEnabled to true.
I don't know if the code needs to be changed to support that, but it seems that after making this change, the app was crashing at random points (when I remarked the history call, the reachability class was crashing, when removed the reachability another, etc.
of course all classes were at the right place when the compiler complained about not finding them
This made me wonder if the multidex caused that so I removed some of the libraries like going from 7.5 verson of google play to 6.5
The app compiles and runs just fine now, allowing me to add the FB sdk 4+
I post this here, so it may help other people having problems without being able to understand where they come from.
I think you set the wrong class path so 1st check your class path
It will solve your problem

How work around java.lang.verifyerror in Android

I have an app which works perfect in all 4.x devices, but now I have a report of the app not working on a samsung_gt (advance) android 2.3.6. Here is the trace:
FATAL EXCEPTION: main
java.lang.VerifyError: com.bamobile.fdtks.activities.MainActivity
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1409)
at android.app.Instrumentation.newActivity(Instrumentation.java:1024)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3770)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
at dalvik.system.NativeStart.main(Native Method)
I have the latest support jar (v4) and have already patched the gson library in case the phone is already using it. The problem seems to be the the support lib. Any ideas? Thank you very much!
The most common cause of java.lang.VerifyError is having a class that uses methods that are not available on the version of Android where the app is running.
Based on your stacktrace, it seems that com.bamobile.fdtks.activities.MainActivity is using a method that is not available on Android 2.3.6, hence the "verification error" that you're seeing.
To fix it, change the minSdkVersion and of your app to 9 or 10 (Android 2.3.6) and look for errors/warnings about unsupported methods for that version of Android. You can also change (temporarily) both minSdkVersion and targetSdkVersion to 9 to force the compiler to fail when you use methods that are not found in Gingerbread devices.

App works in debug but is crashing on google play version (classpath issue?)

I just posted a very major update to a program I have on google play. Everything works fine locally. But I have received field reports of about 20 or 30 of the following Crash report:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.twoplay.twoplayer/com.twoplay.twoplayer.TwoPlayer2Activity}: java.lang.ClassNotFoundException: com.twoplay.twoplayer.TwoPlayer2Activity in loader dalvik.system.PathClassLoader[/data/app/com.twoplay.twoplayer-1.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1680)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.twoplay.twoplayer.TwoPlayer2Activity in loader dalvik.system.PathClassLoader[/data/app/com.twoplay.twoplayer-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1672)
... 11 more
com.twoplay.twoplayer/com.twoplay.twoplayer.TwoPlayer2Activity is the correct name of the initial startup activity.
I also have a similar crash-dump where one of the app's services successfully starts, but crashes shortly after starting due to a missing class (not the service class itself).
I am using android.support.v4, along with a variety of other private libraries.
The project files have (for all practical purposes) been rebuilt from scratch since 2.0 upgrade. Although the package file name should be correct.
Curious things that I don't entirely understand in the log file:
/data/app/com.twoplay.twoplayer-1.apk
Why does "-1" get appended? The actual name of the APK seems to vary from crash dump to crash dump from the field. Sometimes the "-1" is there; sometimes not. e.g. (from other logs):
/data/app/com.twoplay.twoplayer-2.apk
I am assuming and hoping that Google Play developer console would not let me update my app if I had signed with an incorrect key. I didn't have any problems uploading.
Obviously, I'm not able to debug this locally, since I can't download my own app from Google Play. (I do hate that).
Any theories, or suggestions on how to approach gratefully appreciated.

Categories

Resources