Android 金维 java.lang.NoClassDefFoundError

Android Kinvey java.lang.NoClassDefFoundError

我有一个使用 kinvey 的 android 应用程序,它对我来说工作得很好,突然我得到了

java.lang.OutOfMemoryError: GC overhead limit exceeded

所以我把

dexOptions {
    incremental true
    javaMaxHeapSize "4g"
}        

在我的 gradle 文件中,但是当我创建新客户端

时,我在行中得到了 java.lang.NoClassDefFoundError
mKinveyClient = new Client.Builder(AP_ID,App_Secret, this).build();

我尝试清理项目,清理 gradle 文件,将我的 kinvey sdk 从 1.5 更新到 1.6 有什么建议吗?

这是我的 build.gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    dexOptions { //for the error java.lang.OutOfMemoryError: GC overhead limit exceeded
        incremental true
        javaMaxHeapSize "4g"
    }       

    defaultConfig {
        applicationId "com.example.dell.augmentedreality"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),    'proguard-rules.pro'
        }
    }
}

repositories {
    jcenter()

    flatDir {
        dirs 'libs'
    }

    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile files('src/main/java/Vuforia.jar')
    compile(name:'kinvey-android-2.10.6', ext:'aar') {changing= true}
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.gordonwong:material-sheet-fab:1.2.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    ///////////////////////////for animating the text
    ///////////////////////
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.easing:library:1.0.1@aar'
    compile 'com.daimajia.androidanimations:library:1.1.3@aar'
    ///////////////google cloud messaging
    compile 'com.google.android.gms:play-services:8.4.0'
}

编辑:下图中我的 jars 文件

i got java.lang.NoClassDefFoundError

您包含了错误的依赖 jar。使用 maven 或 gradle.

添加适当的依赖版本的 jar

我认为问题在于您将 kinvey JAR 文件和 AAR 文件都复制到了 libs/ 文件夹中。您只需要 AAR。

声称丢失的 class com.google.api.client.json.JsonObjectParser 包含在 google-http-client-1.19-0.jar 中,因此将该 JAR 文件添加到模块中正确的 libs/ 目录并在 build.gradle 中包含这些行应该正确地找到 class 而没有错误。

repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {    
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile(name:'kinvey-android-*', ext:'aar')

    // other stuff
}

关于 OutOfMemory 错误,您很可能超过 Android Dex method limit because of how many dependencies you've included. Most specifically, the last line of your gradle file for the play-services dependency. If you read that documentation,您会看到说明

Note: If the number of method references in your app exceeds the 65K limit, your app may fail to compile. You may be able to mitigate this problem when compiling your app by specifying only the specific Google Play services APIs your app uses, instead of all of them.

由于您似乎只需要云消息,您可以只包含那个,所以替换这一行。

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

有了这个

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

以及您要包含的任何 other Play Services