【问题标题】:Error:Execution failed for task ':app:dexDebug' at runtime错误:任务“:app:dexDebug”在运行时执行失败
【发布时间】:2015-11-09 08:23:41
【问题描述】:

我正面临这个运行时错误。它说:

错误:任务 ':app:dexDebug' 执行失败。

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' 以非完成-零退出值2

这是我的 build.gradle 脚本:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary  'org.apache.http.legacy'

defaultConfig {
    applicationId "com.stratbeans.barium.mobilebarium"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile files('libs/universal-image-loader-1.9.3.jar')
compile files('libs/listviewanimations_lib-core-slh_3.1.0.jar')
compile project(':ListViewAnimations-core')
compile project(':StickyListHeaders')
compile project(':ListViewAnimations-core-slh')

请帮帮我。谢谢!

【问题讨论】:

  • " 以非零退出值结束 2" 是底线。能不能加个洞编译日志?
  • Android Studio 中最常见的错误
  • 使用 gradle assemble --info.还要检查单个模块是否使用不同版本的支持库(jar 文件)

标签: java android jvm runtime build.gradle


【解决方案1】:

您应该审核您的项目是否存在不需要的依赖项并将其删除为 使用 ProGuard 尽可能多地使用未使用的代码。

  1. 更改 Gradle 构建配置以启用 multidex
  2. 修改清单以引用 MultiDexApplication 类

修改您的应用 Gradle 构建文件配置以包含支持库并启用 multidex 输出。

    android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

    defaultConfig {
       applicationId "com.stratbeans.barium.mobilebarium"
       minSdkVersion 16
       targetSdkVersion 23
       versionCode 1
       versionName "1.0"

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

详情可以访问我的回答DexIndexOverflowException Only When Running Tests

【讨论】:

  • 也试过了,同样的错误不断出现。当我评论这一行“编译项目(':ListViewAnimations-core')”时,它会发生。但如果没有这个,我试图在我的应用中实现的谷歌卡片列表视图将无法正常工作。
  • 好的。注释掉(我的意思是删除此行并查看结果)compile project(':ListViewAnimations-core')
  • 为什么会有任何不同?
【解决方案2】:
defaultConfig {
     multiDexEnabled true 
}

在 build.gradle 的 defaultConfig 中添加 multiDexEnabled true。
希望这对你有用!

【讨论】:

  • 并在依赖项中添加这一行:compile 'com.android.support:multidex:1.0.1' AND 你必须在 android-manifest 中添加这个:android:name="android.support. 中的 multidex.MultiDexApplication"
  • 在添加上述行时出现此错误“错误:任务':app:packageAllDebugClassesForMultiDex'的执行失败。> java.util.zip.ZipException:重复条目:android/support/v4/小部件/SearchViewCompatIcs$MySearchView.class"
  • 这意味着添加的依赖项之一是重复的,搜索它,将其删除干净并重建项目
  • 这个依赖导致了“compile project(':ListViewAnimations-core')”的问题。但我需要将它包含在我的应用中,否则我将无法获得我想要的功能。
  • 编译文件('libs/listviewanimations_lib-core-slh_3.1.0.jar') 编译项目(':ListViewAnimations-core') 编译项目(':StickyListHeaders') 编译项目(':ListViewAnimations- core-slh') 你需要这四个吗?它可能在内部重复..
猜你喜欢
  • 2016-12-13
  • 2015-05-16
  • 2015-05-09
  • 1970-01-01
  • 2016-04-03
  • 2016-06-27
相关资源
最近更新 更多