简体   繁体   中英

NoClassDefFoundError: com.parse.ParseObject$1

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:

  1. aaa (presumably a subclass of ParseObject ) having been built with a version of ParseObject that is different than the deployed library version, OR
  2. myApplication being built with a version of ParseObject that is different than the deployed library version.

More likely the latter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM