【问题标题】:Android Kinvey java.lang.NoClassDefFoundErrorAndroid Kinvey java.lang.NoClassDefFoundError
【发布时间】:2016-03-28 17:02:20
【问题描述】:

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

java.lang.OutOfMemoryError: 超出 GC 开销限制

所以我放了

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 文件下方的图片中

【问题讨论】:

  • 假设您使用的是 Android Studio,当您在项目窗格中展开“External Libraries”时,您是否看到了 Kinvey 库?
  • 图片中的jars文件有什么问题吗?
  • 你能显示完整的build.gradle吗?
  • 您的内存不足,因为您已将 所有 Google play 服务包含在 compile 'com.google.android.gms:play-services:8.4.0' 中。您可以根据this documentation 进行拆分。如果您只想要云消息传递,那么您想要com.google.android.gms:play-services-gcm:8.4.0

标签: java android kinvey


【解决方案1】:

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

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

repositories {
    flatDir {
        dirs 'libs'
    }
}

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

    // other stuff
}

关于 OutOfMemory 错误,您很可能超过了 Android Dex method limit,因为您包含了多少依赖项。最具体地说,是 play-services 依赖项的 gradle 文件的最后一行。如果您阅读that documentation,您会看到说明

注意:如果您的应用中的方法引用数量超过 65K 限制,您的应用可能无法编译。在编译您的应用程序时,您可以通过仅指定您的应用程序使用的特定 Google Play 服务 API 而不是所有这些 API 来缓解此问题。

由于您似乎只想要云消息传递,因此您可以只包含该消息,因此请替换此行。

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

有了这个

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

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

【讨论】:

  • 当我改变谷歌播放服务的线路时它工作了非常感谢你
【解决方案2】:

我得到了 java.lang.NoClassDefFoundError

您包含错误的依赖 jar。使用 maven 或 gradle 添加适当的 jar 依赖版本。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2016-05-17
  • 1970-01-01
  • 2012-04-09
  • 1970-01-01
  • 1970-01-01
  • 2015-09-25
  • 2021-12-10
  • 2016-03-13
相关资源
最近更新 更多