NoClassDefFoundError:com.parse.ParseRequest。 Android Parse异常

时间:2016-01-22 11:27:04

标签: android parse-platform android-gradle

我使用parse.com jar创建了一个示例应用。在这个项目中,Buid版本SDK为22(运行正常)。但在改变它23后,我在编译应用程序时面临一些问题。我试图清理项目,无效缓存。重建项目等但我遇到同样的问题错误是:

FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.parse.ParseRequest
at com.parse.Parse.initialize(Parse.java:184)
我无法找到确切的解决方案。我检查过libs文件夹有jar。我也尝试过使用最新的gradle代码,但遇到了同样的错误。删除解析jar后我可以编译我的项目。我的依赖是

    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')

}

如果我使用

compile 'com.parse.bolts:bolts-android:1.4.0'
compile 'com.parse:parse-android:1.12.0'
更改此依赖关系,则错误会有所不同。错误是:
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)
请建议我,这种依赖有什么问题。提前致谢

1 个答案:

答案 0 :(得分:3)

问题不是因为解析类。错误导致错误,因为mulitdex未处理&启动解析是在应用程序启动,这就是为什么它会给类找不到错误。

将以下行添加到build.gradle以处理多dex

解决我在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.

}

整个 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.

}

android developer multidex guide MultiDexApplication class

的帮助下

要安装MultiDex.install,请参阅android developer link

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

<强> 建议

<强> Selectively compiling APIs into your executable

请勿使用整个Google Play服务仅使用所需的库。从版本6.5开始,您可以选择性地将Google Play服务API编译到您的应用中。例如,要仅包含Google Fit和Android Wear API,请替换build.gradle文件中的以下行:

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

这些行:

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

如果有的话,请告诉我。