app:transformClassesWithMultidexlistForDebug 失败

4

我已经尝试了以下链接:

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

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

com.android.build.transform.api.TransformException

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

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

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

com.android.build.transform.api.TransformException

我的 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'
}

以下是我的清单。

<?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>

我的活动文件如下所示。

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);
    }
}

尽管我做了这一切,我仍然收到以下错误提示。
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

在消息窗口中向上滚动一点,找到那个错误。可能会有一个更有用的错误信息,说明出了什么问题。 - George Mulligan
嗨,George,以下是我的堆栈跟踪。这里没有任何问题。我是Android Studio的新手。 - novice_dev
你为什么将rt.jar作为依赖项? - George Mulligan
我希望使用 ScriptEngine 来计算数学表达式。rt.jar 包含了 java.script.*,因此 rt.jar 是一个依赖项。 - novice_dev
只是出于好奇,没有它会工作吗? - George Mulligan
显示剩余3条评论
4个回答

5

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

更改minSdkVersion意味着它将不能在低于sdk版本的设备上运行

在您的Android文件夹下查找build.gradle文件。将minSdkVersion替换为21。它的代码应该如下所示:

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

感谢Edward Beazer的贡献。


1
非常感谢。我不知道问题出在哪里,但它已经起作用了 :) - Kishan Bharda
欢迎,但我们需要一些修复,以便在minSdkVersion 16上运行。 - Wasi Sadman

4

答案

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

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

感谢George Mulligan指出这一点。


如何做。请提供更多细节。 - Mohith7548
我通过 Cordova 的清理和构建项目实现了这一点。 - Karnan Muthukumar

0

我不确定在Windows操作系统上是否与纯JAVA相同。我在Mac上使用cordova run android时遇到了同样的问题,它总是失败。因此,我在我的build.gradle文件中添加了以下内容,构建通过了,并且我能够在模拟器上进行测试。在android部分下添加您的编译信息,在default config下添加multidex。

android {
    compileSdkVersion 23
    buildToolsVersion "23"
}

defaultConfig {
    multiDexEnabled true
}

请注意,版本号只是23而不是23.0.1。

0

我知道这个问题已经过去了,但是我也遇到了同样的问题。 错误信息如下:

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]))

我搜索了很多却没有找到解决方法。 最后我通过在gradle中添加以下行来解决它:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接