java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder on below Lollipop versions

有些话、适合烂在心里 提交于 2019-12-11 00:36:53

问题


I am using parse.com sdk in my app. It is working absolutely fine with Lollipop. But when I run the app on below lollipop versions I get this error:

java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder
at com.parse.Parse.initialize(Parse.java:297)
at com.xxx.android.MyApp.onCreate(MyApp.java:16)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1014)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4747)
at android.app.ActivityThread.access$1500(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1343)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
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:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)

I'm getting this error when initialising parse by

Parse.initialize(this); 

Application class code:

public class MyApp extends Application {
@Override
public void onCreate() {
    super.onCreate();
    // Enable Local Datastore.
    Parse.enableLocalDatastore(this);
    Parse.initialize(this);
}

}

My manifest code:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.android">


<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<application
    android:name="com.xxx.android.MyApp"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity
        android:name="com.xxx.android.HomeActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data
        android:name="com.parse.APPLICATION_ID"
        android:value="@string/app_id" />
    <meta-data
        android:name="com.parse.CLIENT_KEY"
        android:value="@string/client_key" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/api_key" />
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
</application>

Gradle:

  apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.xxx.android"
    minSdkVersion 9
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true

}
dexOptions {
    incremental = true;
    preDexLibraries = false
    javaMaxHeapSize "4g" 
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:palette-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.parse.bolts:bolts-android:1.4.0'
compile 'com.parse:parse-android:1.12.0'
compile 'com.parse:parseui-widget-android:0.0.1'
compile 'com.google.code.gson:gson:2.5'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.marshalchen.ultimaterecyclerview:library:0.3.18'

}

How can I fix this?


回答1:


Looking at your dependencies and since you have confirmed you have multidex enabled, please consider this (quoting from the official documentation):

Versions of the platform prior to Android 5.0 use the Dalvik runtime for executing app code. By default, Dalvik limits apps to a single classes.dex bytecode file per APK. In order to get around this limitation, you can use the multidex support library.

It means you have to set the multidex support library in order to enable multidex and to be able to run your application on devices running a version of Android prior to 5.0.

The official documentation is quite straightforward and it's really simple to follow.

You basically have to:

  • enable multidex support in your defaultConfig section adding: multiDexEnabled true
  • declare the library as a dependency:

    compile 'com.android.support:multidex:1.0.0'

  • skip the step where you have to set MultiDexApplication in the manifest as the application name (because you have your own Application class).

Since you have a custom Application class, please be careful while you set the multidex support library:

If your app uses extends the Application class, you can override the attachBaseContext() method and call MultiDex.install(this) to enable multidex.

So call this method from your custom Application class.

Please check if there's a new version of the library: Android Studio should give you a warning if that's the case.



来源:https://stackoverflow.com/questions/34876628/java-lang-noclassdeffounderror-com-parse-parseconfigurationbuilder-on-below-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!