Java :app:transformClassesWithMultidexlistForDebug 失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36561103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 18:26:02  来源:igfitidea点击:

:app:transformClassesWithMultidexlistForDebug FAILED

javaandroidbuild.gradleandroid-multidex

提问by novice_dev

I have tried the following links

我试过以下链接

http://developer.android.com/intl/es/tools/building/multidex.html

http://developer.android.com/intl/es/tools/building/multidex.html

UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define

意外的顶级异常:com.android.dex.DexException:多个 dex 文件定义

com.android.build.transform.api.TransformException

com.android.build.transform.api.TransformException

':app:transformClassesWithDexForDebug'. > com.android.build.transform.api.TransformException: when i added Facebook latest SDK in my studio project

':app:transformClassesWithDexForDebug'。> com.android.build.transform.api.TransformException:当我在我的工作室项目中添加 Facebook 最新 SDK 时

Android Studio TransformException : Error:Execution failed for task ':app:transformClassesWithDexForDebug'

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

Java finished with non-zero exit value 2 - Android Gradle

Java 以非零退出值 2 结束 - Android Gradle

com.android.build.transform.api.TransformException

com.android.build.transform.api.TransformException

My gradle build file is as below.

我的gradle构建文件如下。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'

    defaultConfig {
        applicationId "appId"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        incremental true
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile files('libs/rt.jar')
    compile 'com.android.support:multidex:1.0.0'
}

My manifest is as below.

我的清单如下。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="packageName">

    <application
        android:name="android.support.multidex.MultiDexApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

My activity file is as below.

我的活动文件如下。

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

After all this, I still get the following error.

毕竟,我仍然收到以下错误。

Error:Execution failed for task
':app:transformClassesWithMultidexlistForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_72\bin\java.exe'' finished with non-zero exit value 1

采纳答案by novice_dev

Answer

回答

I had to do the following at the app level

我必须在应用程序级别执行以下操作

  • Remove rt.jar as library
  • Remove compile files('libs/rt.jar')from build.gradle
  • Clean and build project.
  • 删除 rt.jar 作为库
  • compile files('libs/rt.jar')从 build.gradle 中删除
  • 清理并构建项目。

Thanks to George Mulligan for pointing it out.

感谢 George Mulligan 指出这一点。

回答by Bamanyi

I'm not sure this is the same for the Windows OS with straight JAVA. I was having the same issue with cordova run androidand it always fail in Mac. So I added the following to my build.gradle file and the build passed, and I was able to test on the emulator. Add your compiled info under android section and multidex under default config

我不确定这对于直接使用 JAVA 的 Windows 操作系统是否相同。我遇到了同样的问题,cordova run android它在 Mac 中总是失败。所以我将以下内容添加到我的 build.gradle 文件中并且构建通过了,并且我能够在模拟器上进行测试。在 android 部分和默认配置下的 multidex 下添加您的编译信息

android {
    compileSdkVersion 23
    buildToolsVersion "23"
}

defaultConfig {
    multiDexEnabled true
}

Notice the build is just 23 and not 23.0.1

注意构建只是 23 而不是 23.0.1

回答by S.Hoseinpoor

I know it is passed. but I had same problem. the message was this:

我知道它通过了。但我有同样的问题。消息是这样的:

Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. java.io.IOException: Can't write [D:...app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:....\support-core-ui-27.1.1.aar\eadf2be3981e05166424b72b4128200e\jars\classes.jar(;;;;;;**.class)] (Duplicate zip entry [classes.jar:android/support/v4/view/ViewPager$1.class]))

错误:任务 ':app:transformClassesWithMultidexlistForDebug' 的执行失败。java.io.IOException: 无法写入 [D:...app\build\intermediates\multi-dex\debug\componentClasses.jar] (无法读取 [C:....\support-core-ui -27.1.1.aar\eadf2be3981e05166424b72b4128200e\jars\classes.jar(;;;;;;;**.class)](重复的 zip 条目 [classes.jar:android/support/v4/view/ViewPager$1.class]) )

I searched a lot but nothing found. I resolved it by adding below line to gradle:

我搜索了很多,但没有找到。我通过在gradle中添加以下行来解决它:

implementation 'com.android.support:support-v4:27.0.2'

回答by Wasi Sadman

I have found a quick fix. But there might be a better solution to this.

我找到了一个快速解决方法。但可能有更好的解决方案。

changing minSdkVersion means it will not gonna work for below the sdk version

更改 minSdkVersion 意味着它不适用于低于 sdk 版本

Under your Android folder look for you build.gradle file. Replace the minSdkVersion to 21. The code for it should look like this

在您的 Android 文件夹下查找您的 build.gradle 文件。将 minSdkVersion 替换为 21。它的代码应该是这样的

ext {
    buildToolsVersion = "28.0.3"
    minSdkVersion = 21
    compileSdkVersion = 28
    targetSdkVersion = 28
}

thanks to Edward Beazer

感谢爱德华·比泽