错误:任务':app:transformClassesWithDexForDebug'的执行失败

Sak*_*ain 71 android android-studio android-gradle-plugin android-multidex

错误

错误:任务':app:transformClassesWithDexForDebug'的执行失败.com.android.build.transform.api.TransformException:com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'command'/ usr/lib/jvm/java-8-oracle/bin/java''以非零退出值1结束

我的app gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        applicationId 'Hidden application ID'
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        disable 'InvalidPackage'
    }
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
    productFlavors {
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:multidex:1.0.1'
    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.jakewharton:butterknife:7.0.1'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'com.facebook.android:facebook-android-sdk:4.7.0'
    compile 'com.googlecode.libphonenumber:libphonenumber:7.2.1'
    compile 'com.getbase:floatingactionbutton:1.10.1'
    compile 'com.android.support:preference-v7:23.1.1'
}
Run Code Online (Sandbox Code Playgroud)

在调试时,如果我将minifyEnabled设置为true,那么它就会编译.但是,我无法调试我的应用程序.

我检查了另一个问题:执行谷歌登录Android时,任务':app:transformClassesWithDexForDebug'的执行失败,但只有一个答案,实施它不幸解决了这个问题.

AFAIK,错误是由于添加了太多的Gradle依赖项引起的,但我可能错了(我真的希望错了,因为所有这些包都非常重要!).

请帮我解决这个错误.非常感谢!

Kru*_*hah 49

只需更正Google Play服务依赖项:

您将在项目中包含所有游戏服务.只添加你想要的.

例如,如果您仅使用地图和g + signin,则更改

 compile 'com.google.android.gms:play-services:8.1.0'
Run Code Online (Sandbox Code Playgroud)

compile 'com.google.android.gms:play-services-maps:8.1.0'
compile 'com.google.android.gms:play-services-plus:8.1.0'
Run Code Online (Sandbox Code Playgroud)

来自doc:

在6.5之前的Google Play服务版本中,您必须将整个API包编译到您的应用中.在某些情况下,这样做会使您的应用程序中的方法数量(包括框架API,库方法和您自己的代码)在65,536限制下更加困难.

从6.5版开始,您可以选择性地将Google Play服务API编译到您的应用中.例如,要仅包含Google Fit和Android Wear API,请在build.gradle文件中替换以下行:使用以下行
编译"com.google.android.gms:play-services:8.3.0"
:

编译'com.google.android.gms:play-services-fitness:8.3.0'compile'c​​om.google.android.gms
:play-services-wearable:8.3.0'

整个列表可以在这里找到.


tin*_*ght 25

尝试

dexOptions {
    javaMaxHeapSize "4g"
    preDexLibraries = false
}
Run Code Online (Sandbox Code Playgroud)

我不知道原因.关于preDexLibraries:https: //sites.google.com/a/android.com/tools/tech-docs/new-build-system/tips

根据@ lgdroid57:

以下资源应该有助于解释此代码的作用:link(http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.DexOptions.html)描述javaMaxHeapSize | 调用dx时设置-JXmx*值.格式应遵循1024M模式.preDexLibraries | 是否预先dex库.这可以改善增量构建,但是干净的构建可能会更慢.


Moh*_*alm 19

尝试添加multiDexEnabled true到您的应用build.gradle文件.

  defaultConfig {
    multiDexEnabled true
}
Run Code Online (Sandbox Code Playgroud)


小智 15

这是关于Multidex的问题.您可以尝试删除一些jar,或者您可以尝试这样:http: //developer.android.com/tools/building/multidex.html#mdex-gradle in app build.gradle:

    defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 21
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
dependencies {
  compile 'com.android.support:multidex:1.0.0'
}
Run Code Online (Sandbox Code Playgroud)

在你的清单中:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>
Run Code Online (Sandbox Code Playgroud)


小智 13

multiDexEnabled truedefault config filebuild.gradle这样

    defaultConfig {
        multiDexEnabled true
       }
Run Code Online (Sandbox Code Playgroud)

  • 这对我有用.有人可以解释为什么这是有效的. (2认同)

小智 5

对我个人有用的解决方案是:

在里面 build.gradle

defaultConfig {
        multiDexEnabled true
    }

 dexOptions {
        javaMaxHeapSize "4g"
    }
Run Code Online (Sandbox Code Playgroud)


Dan*_* S. 5

我的回答有点旧,但对于我来说,唯一的解决方案是在 defaultConfig 中添加 multiDexEnabled 选项,如下所示:

    android{
        ...
        defaultConfig{
            ...
            multiDexEnabled true
        }
    }
Run Code Online (Sandbox Code Playgroud)

如果这对您不起作用,请尝试添加这段代码:

    configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '26.1.0'
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的错误与不同库版本的问题有关,这就是诀窍。

我希望这可以帮助某人:)


归档时间:

查看次数:

160406 次

最近记录:

6 年,2 月 前