尝试构建Android项目时出现编译器错误

时间:2019-01-05 11:49:13

标签: java android android-studio compiler-errors

我正在尝试编译一个刚刚恢复工作的旧android项目,由于出现以下错误,因此无法编译。

错误(当我用完房间时不完整):

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\0.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\1.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\81.jar
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.arch.lifecycle.ViewModelStore
at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:55)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:104)
at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:230)
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:73)
at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:124)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:113)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95)
... 33 more
Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\0.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\1.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\2.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\3.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\4.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\5.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\6.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\7.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\8.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\9.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\10.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\11.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\12.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\13.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\14.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\15.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\16.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\17.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\18.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\19.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\20.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\21.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\22.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\23.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\24.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\25.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\26.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\27.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\28.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\29.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\30.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\31.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\32.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\33.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\34.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\35.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\36.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\37.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\38.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\39.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\40.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\41.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\42.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\43.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\44.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\45.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\46.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\47.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\48.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\49.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\50.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\51.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\52.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\53.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\54.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\55.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\56.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\57.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\58.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\59.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\60.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\61.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\62.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\63.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\64.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\65.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\66.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\67.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\68.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\69.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\70.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\71.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\72.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\73.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\74.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\75.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\76.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\77.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\78.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\79.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\80.jar, D:\AndroidStudioProjects\QuaddieKing\app\build\intermediates\transforms\dexBuilder\debug\81.jar
Learn how to resolve the issue at 
https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.arch.lifecycle.ViewModelStore
at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:132)
at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:117)
at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:101)
at com.android.build.gradle.internal.transforms.ExternalLibsMergerTransform.transform(ExternalLibsMergerTransform.kt:122)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:239)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:235)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
... 49 more
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:65)
at com.android.tools.r8.utils.ExceptionUtils.withD8CompilationHandler(ExceptionUtils.java:43)
at com.android.tools.r8.D8.run(D8.java:90)
at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:115)
... 54 more
Caused by: com.android.tools.r8.utils.AbortException: Error: Program type already present: android.arch.lifecycle.ViewModelStore
at com.android.tools.r8.utils.Reporter.failIfPendingErrors(Reporter.java:116)
at com.android.tools.r8.utils.Reporter.fatalError(Reporter.java:74)
at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:59)
... 57 more

以下是我的: -模块gradle文件
-项目gradle文件 -安卓清单文件

模块Gradle文件

//noinspection GradleCompatible
    apply plugin: 'com.android.application'
    apply plugin: 'com.google.gms.google-services'
    android {
        compileSdkVersion 28
        buildToolsVersion '28.0.3'
        defaultConfig {
            applicationId "com.secret.secret"
            minSdkVersion 21
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            multiDexEnabled true
            testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
            vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }

    aaptOptions {
        additionalParameters "--no-version-vectors"
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    // Required -- JUnit 4 framework
    implementation 'com.android.support:appcompat-v7:28.0.0'
    //implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.6'
    implementation 'com.google.firebase:firebase-auth:16.1.0'
    implementation 'com.google.firebase:firebase-database:16.0.5'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.firebaseui:firebase-ui-database:3.1.0'

    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-vector-drawable:28.0.0'
    implementation 'com.firebaseui:firebase-ui-database:3.1.0'
    implementation 'com.google.gms:google-services:4.2.0'
    implementation files('libs/jsoup-1.11.2.jar')
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'

    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testImplementation 'junit:junit:4.12'
}

项目Gradle文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
    jcenter()
    google()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
    classpath 'com.google.gms:google-services:4.2.0'

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

allprojects {
repositories {
    jcenter()
    //google()  // also a google repository
    maven {url "https://maven.google.com" } // Google's Maven repository
    maven { url "https://jitpack.io" } // MPAndroidChart repository but use gradle instead as it is faster (according to them)
}
}

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

Android清单文件

<?xml version="1.0" encoding="utf-8"?>

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application>
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <!-- [START fcm_default_icon] -->
    <!--
         Set custom default icon. This is used when no icon is set for incoming notification messages.

    -->
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/ic_person_white" />
    <!--
         Set color used with incoming notification messages. This is used when no color is set for the incoming

    -->
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/colorAccent" />
    <!-- [END fcm_default_icon] -->

    <activity
        android:name=".LoginActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".GroupListActivity"
        android:label="@string/title_item_list"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name=".GroupDetailActivity"
        android:label="@string/title_item_detail"
        android:parentActivityName=".GroupListActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.secret.secret.GroupListActivity" />
    </activity>

    <!-- [START firebase_service] -->
    <service android:name=".MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    <!-- [END firebase_service] -->
    <!-- [START firebase_iid_service] -->
    <service android:name=".MyFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
    <!-- [END firebase_iid_service] -->
    <activity
        android:name=".ChatActivity"
        android:label="@string/title_activity_main"
        android:parentActivityName=".GroupDetailActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="ACTIVITY_CHAT" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.secret.secret.GroupDetailActivity" />
    </activity>
    <activity
        android:name=".Activity"
        android:label="Select Horses"
        android:parentActivityName=".GroupDetailActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.secret.secret.GroupDetailActivity" />
    </activity>
    <activity
        android:name=".ExceptionActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/title_activity_exception"
        android:theme="@style/FullscreenTheme" />
    <activity
        android:name=".Activity"
        android:label="@string/title_activity"></activity>
</application>

0 个答案:

没有答案