Search code examples
javaandroidkinvey

Android Kinvey java.lang.NoClassDefFoundError


I have an android application that used kinvey and it worked just fine with me suddenly i got

java.lang.OutOfMemoryError: GC overhead limit exceeded

so i put

dexOptions {
    incremental true
    javaMaxHeapSize "4g"
}        

in my gradle file but then i got java.lang.NoClassDefFoundError in the line when i create new client

mKinveyClient = new Client.Builder(AP_ID,App_Secret, this).build();

i tried to clean project ,clean gradle file , updated my kinvey sdk from 1.5 to 1.6 Any suggestions?

here is my build.gradle file

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

Edit:in the image below my jars files

enter image description here


Solution

  • I think the problem is that you copied both the kinvey JAR file and the AAR file into the libs/ folder. You only need the AAR.

    The class that is claimed to be missing, com.google.api.client.json.JsonObjectParser, is contained within google-http-client-1.19-0.jar, so adding that JAR file to the correct libs/ directory in the module and including these lines in you build.gradle should properly find that class without error.

    repositories {
        flatDir {
            dirs 'libs'
        }
    }
    
    dependencies {    
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile(name:'kinvey-android-*', ext:'aar')
    
        // other stuff
    }
    

    With regards to the OutOfMemory error, you most likely exceeded the 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, you'll see the note that says

    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.

    Since you seem to only want cloud messaging, you can just include that one, so replace this line.

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

    With this one

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

    And any other Play Services you want to include.