【问题标题】:NoClassDefFoundError: com.parse.ParseRequest. Android Parse ExceptionNoClassDefFoundError:com.parse.ParseRequest。 Android 解析异常
【发布时间】:2016-04-28 23:47:28
【问题描述】:

我使用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)
请建议我,这种依赖有什么问题。提前致谢

【问题讨论】:

  • 我认为您必须检查是否为您的库检查了导出:右键单击您的项目->“模块设置”-> 依赖项,然后检查是否检查了导出...
  • @ Opiatefuchs 我已经检查了它的依赖关系我可以看到它被链接了screencast.com/t/fUynUfMqZ
  • @Opiatefuchs 我还需要更改其他设置吗?我已经检查了另一个 jar 在这个依赖项下工作正常
  • 先清理你的项目,这往往是个问题...
  • @Opiatefuchs 完成了 20 多次此过程。甚至关闭工作室重建,重新索引所有尝试。

标签: android parse-platform android-gradle-plugin


【解决方案1】:

问题不是因为解析类。在错误中,您会因为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'

如果有什么事请告诉我。

【讨论】:

  • @bhavin 检查更新的答案和建议。通过使用所需的播放服务库可以在不添加 multidex 的情况下解决您的问题。
  • 我没有尝试过你的完整代码,但“建议”对我有用。为我删除了未使用的 play-services 个人工作,不需要 multi-dex 感谢您的大力帮助。
  • @bhavinchauhan 建议有效,但错误只是多 dex,所以我的代码也可以工作.. :)
猜你喜欢
  • 1970-01-01
  • 2015-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-09
  • 1970-01-01
相关资源
最近更新 更多