Android Studio构建失败-任务:应用:dexBuilderDebug失败

xwbd5t1u  于 2023-01-09  发布在  Android
关注(0)|答案(3)|浏览(327)

我收到错误消息生成了“build”文件夹下的文件,不应编辑。这是详细的构建输出(我只发布了开头和结尾,因为它太长了)

AGPBI: {"kind":"error","text":"Type com.example.currencyconversion.BuildConfig is defined multiple times: /Users/eimanalwahhabi/Desktop/CurrencyConversion/app/build/intermediates/javac/debug/classes/com/example/currencyconversion/BuildConfig.class, /Users/eimanalwahhabi/Desktop/CurrencyConversion/app/build/intermediates/javac/debug/classes/com/example/currencyconversion/BuildConfig 2.class","sources":[{"file":"/Users/eimanalwahhabi/Desktop/CurrencyConversion/app/build/intermediates/javac/debug/classes/com/example/currencyconversion/BuildConfig.class"}],"tool":"D8"}
org.gradle.workers.WorkerExecutionException: There was a failure while executing work items
    at org.gradle.workers.internal.DefaultWorkerExecutor.workerExecutionException(DefaultWorkerExecutor.java:264)
    at org.gradle.workers.internal.DefaultWorkerExecutor.await(DefaultWorkerExecutor.java:246)
    at com.android.build.gradle.internal.tasks.DexArchiveBuilderTaskDelegate.doProcess(DexArchiveBuilderTaskDelegate.kt:280)
    at com.android.build.gradle.internal.tasks.DexArchiveBuilderTask.doTaskAction(DexArchiveBuilderTask.kt:282)
    at com.android.build.gradle.internal.tasks.NewIncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(AndroidVariantTask.kt:73)
    at com.android.build.gradle.internal.tasks.NewIncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(AndroidVariantTask.kt:34)
    at com.android.build.gradle.internal.tasks.Blocks.recordSpan(Blocks.java:91)
    at com.android.build.gradle.internal.tasks.NewIncrementalTask.taskAction(NewIncrementalTask.kt:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)
    at org.gradle.api.internal.project.taskfactory.IncrementalInputsTaskAction.doExecute(IncrementalInputsTaskAction.java:32)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:42)
    at org.gradle.api.internal.project.taskfactory.AbstractIncrementalTaskAction.execute(AbstractIncrementalTaskAction.java:25)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:28)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.run(ExecuteActionsTaskExecuter.java:569)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:395)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:387)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:157)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:242)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:150)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:84)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:554)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:537)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$300(ExecuteActionsTaskExecuter.java:108)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.executeWithPreviousOutputFiles(ExecuteActionsTaskExecuter.java:278)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:267)
    at org.gradle.internal.execution.steps.ExecuteStep.lambda$execute$0(ExecuteStep.java:32)
.
.
.
.
Caused by: org.gradle.tooling.BuildException: Failed to process: /Users/eimanalwahhabi/Desktop/CurrencyConversion/app/build/intermediates/javac/debug/classes

Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process: /Users/eimanalwahhabi/Desktop/CurrencyConversion/app/build/intermediates/javac/debug/classes

Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.

Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: /Users/eimanalwahhabi/Desktop/CurrencyConversion/app/build/intermediates/javac/debug/classes/com/example/currencyconversion/BuildConfig.class

Caused by: com.android.tools.r8.utils.b: Type com.example.currencyconversion.BuildConfig is defined multiple times: /Users/eimanalwahhabi/Desktop/CurrencyConversion/app/build/intermediates/javac/debug/classes/com/example/currencyconversion/BuildConfig.class, /Users/eimanalwahhabi/Desktop/CurrencyConversion/app/build/intermediates/javac/debug/classes/com/example/currencyconversion/BuildConfig 2.class

Execution failed for task ':app:dexBuilderDebug'.
> There was a failure while executing work items
   > A failure occurred while executing com.android.build.gradle.internal.dexing.DexWorkAction
      > Failed to process: /Users/eimanalwahhabi/Desktop/CurrencyConversion/app/build/intermediates/javac/debug/classes

这是我尝试运行应用程序时的构建输出摘要:

Type com.example.currencyconversion.BuildConfig is defined multiple times: /Users/eimanalwahhabi/Desktop/CurrencyConversion/app/build/intermediates/javac/debug/classes/com/example/currencyconversion/BuildConfig.class, /Users/eimanalwahhabi/Desktop/CurrencyConversion/app/build/intermediates/javac/debug/classes/com/example/currencyconversion/BuildConfig 2.class

这是生成输出错误的图片:Build Output errors
这是我的buildConfig.class

package com.example.currencyconversion;

public final class BuildConfig {
    public static final boolean DEBUG = Boolean.parseBoolean("true");
    public static final String APPLICATION_ID = "com.example.currencyconversion";
    public static final String BUILD_TYPE = "debug";
    public static final int VERSION_CODE = 1;
    public static final String VERSION_NAME = "1.0";

    public BuildConfig() {
    }
}

这是Module build.gradle。您可以在这里看到,我尝试通过添加Multidex依赖项来解决问题,但仍然不起作用。

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 29

    defaultConfig {
        applicationId "com.example.currencyconversion"
        minSdkVersion 29
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    implementation 'com.squareup.retrofit2:retrofit:2.7.1'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    implementation 'com.google.code.gson:gson:2.6.2'

    implementation 'com.android.support:multidex:1.0.3'

这是项目build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
tcomlyy6

tcomlyy61#

我运行了一个干净的版本来修复它

c9qzyr3d

c9qzyr3d2#

经过一番调查之后,最简单的修复方法是导航到BuildConfig.java文件并将其删除/丢弃,然后重新构建您的项目,它将重新生成。

uqzxnwby

uqzxnwby3#

清洁项目,然后让项目为我工作。

相关问题