NoClassDefFoundError: com.parse.ParseRequest. Andr

2019-02-26 00:46发布

问题:

I have create one sample app using parse.com jar. In this project Buid version SDK was 22(it was running fine). But after change it with 23 I am facing some issues in compiling app. I have tried to clean project, Invalidate caches. Rebuild project etc but I faced same issue error is:

FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.parse.ParseRequest
at com.parse.Parse.initialize(Parse.java:184)
I can't get find exact solution. I have checked libs folder have jar. I have also tried with latest gradle code but faced same error. After removing parse jar I can compile my project. My dependencies are

    dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/org.apache.http.legacy.jar')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile project(':MaterialShowcaseView')
    compile files('libs/Parse-1.9.2.jar')
    compile files('libs/bolts-android-1.2.0.jar')
    compile files('libs/universal-image-loader-1.9.4.jar')

}

If I Change this dependencies with

compile 'com.parse.bolts:bolts-android:1.4.0'
compile 'com.parse:parse-android:1.12.0'
then error is different. Error is:
java.lang.NoClassDefFoundError: com.parse.ParsePlugins$1
at com.parse.ParsePlugins.restClient(ParsePlugins.java:92)
at com.parse.Parse.initializeParseHttpClientsWithParseNetworkInterceptors(Parse.java:762)
at com.parse.Parse.initialize(Parse.java:365)
at com.parse.Parse.initialize(Parse.java:344)
Please suggest me, what is wrong with this dependency. Thanks in advance

回答1:

Issue is not because of parse class.In error you get that error because of mulitdex not handled & Initilization of parse is on app start up thats why it will give class not found error.

add below lines to build.gradle to handle multi dex

To resolve issue what i give in my build.gradle

dexOptions {
        incremental true
        // here heap size give 4g i got this thing from https://groups.google.com/forum/#!topic/adt-dev/P_TLBTyFWVY

        javaMaxHeapSize "4g"
    }


dependencies {
     compile 'com.android.support:multidex:1.0.1'
    //    your dependencies which you are using.

}

Entire build.gradle

apply plugin: 'com.android.application'
repositories {
    mavenCentral()

}
configurations {
//    all*.exclude group: 'com.android.support', module: 'recyclerview-v7'
}

android {
    signingConfigs {
        /*
        releasebuild {
            keyAlias 'hellotest'
            keyPassword 'hellotest'
            storeFile file('path to keystore')
            storePassword 'hellotest'
        }
        */
    }
    compileSdkVersion 'Google Inc.:Google APIs:22'
    buildToolsVersion '23.0.0'
    /* if you got error regarding duplicate file of  META-INF/LICENSE.txt from jar file
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
    }
    */
    dexOptions {
        jumboMode = true
        incremental true
        // here heap size give 4g i got this thing from https://groups.google.com/forum/#!topic/adt-dev/P_TLBTyFWVY

        javaMaxHeapSize "4g"
    }
    defaultConfig {
        multiDexEnabled true
        applicationId "com.myapp.packagenme"
        minSdkVersion 17
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.releasebuild
        }
        debug {
            signingConfig signingConfigs.releasebuild
        }
    }
}

dependencies {
     compile 'com.android.support:multidex:1.0.1'
    //    your dependencies which you are using.

}

With the help of android developer multidex guide MultiDexApplication class

To install MultiDex.install i refer android developer link

public class MyAppClass extends MultiDexApplication{
@Override
    protected void attachBaseContext(Context newBase) {
        MultiDex.install(newBase);
        super.attachBaseContext(newBase);
    }
}

Suggestion

Selectively compiling APIs into your executable

Don't use entire google play service use only required library.From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:

compile 'com.google.android.gms:play-services:8.4.0'

with these lines:

compile 'com.google.android.gms:play-services-fitness:8.4.0'
compile 'com.google.android.gms:play-services-wearable:8.4.0'

Let me know if anything.