【问题标题】:issue Execution failed for task ':app:dexDebug'. finished with non-zero exit value 2任务':app:dexDebug'的问题执行失败。以非零退出值 2 结束
【发布时间】:2015-10-17 04:29:32
【问题描述】:

我做了一个类似下面结构的项目

我的 build.gradel 文件如下

apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "pkg.com.appname"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies {
/*compile fileTree(dir: 'libs', include: ['*.jar'])*/
compile 'com.android.support:appcompat-v7:22.2.1'
compile files('libs/commons-io-2.4.jar')
compile files('libs/achartengine-1.1.0.jar')
compile files('libs/apache-mime4j-0.6.jar')
compile files('libs/itextpdf-5.1.0.jar')
compile files('libs/android-support-v4.jar')
compile files('libs/gson-2.1.jar')
compile files('libs/json_simple-1.1.jar')
compile files('libs/httpmime-4.0.1.jar')
compile files('libs/droidText.0.2.jar')
compile files('libs/ormlite-android-4.48.jar')
compile files('libs/opencsv-2.4.jar')
compile files('libs/ormlite-core-4.48.jar')
compile 'com.google.android.gms:play-services:7.5.0'
 }

我根据当前接受的答案尝试了所有可能性,如下所示

1.注释依赖lib行form build.gradle

dependencies {
/*compile fileTree(dir: 'libs', include: ['*.jar'])*/
compile 'com.android.support:appcompat-v7:22.2.1'
compile files('libs/commons-io-2.4.jar')
compile files('libs/achartengine-1.1.0.jar')
compile files('libs/apache-mime4j-0.6.jar')
compile files('libs/itextpdf-5.1.0.jar')
compile files('libs/android-support-v4.jar')
compile files('libs/gson-2.1.jar')
compile files('libs/json_simple-1.1.jar')
compile files('libs/httpmime-4.0.1.jar')
compile files('libs/droidText.0.2.jar')
compile files('libs/ormlite-android-4.48.jar')
compile files('libs/opencsv-2.4.jar')
compile files('libs/ormlite-core-4.48.jar')
compile 'com.google.android.gms:play-services:7.5.0'
 }

但是如果我删除它而不是在我的类文件中出现错误,比如你的库在这个类中丢失

2。通过将更改行作为编译提供

当我进行上述更改时,我的应用程序没有运行,并且由于库没有进入相应的类而给出类似空指针的消息。

所以我很困惑我遵循哪种方式知道如何解决这个问题?你的所有建议都是可观的。

【问题讨论】:

标签: android android-gradle-plugin build.gradle executable-jar


【解决方案1】:

在默认配置中添加:

multiDexEnabled = true

并在同一个 build.gradle 中添加:

dexOptions {
    javaMaxHeapSize "4g"
}

并在依赖项中添加:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:multidex:1.0.0'}

【讨论】:

  • Android Weblineindia:您好,谢谢....添加 multiDexEnabled = true 后解决 multiDex 异常,但在加载时许多类文件未生成,因此抛出错误 classDefNotFound。我该如何解决这个问题?
  • 当我添加这个依赖时,它在运行时抛出异常 classDefNotfoun compile 'com.google.api-client:google-api-client:1.20.0' compile 'com.google.api-client:google-api-client-android:1.20.0' compile 'com.google.api-client:google-api-client-gson:1.20.0' compile 'com.google.apis:google-api-services-calendar:v3-rev125-1.20.0' compile 'com.google.android.gms:play-services:7.5.0'
猜你喜欢
  • 2015-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-12
  • 2016-02-23
  • 1970-01-01
  • 2017-05-31
  • 1970-01-01
相关资源
最近更新 更多