当前位置: 首页 > 知识库问答 >
问题:

错误:程序类型已存在:org.apache.maven.profiles.DefaultProfileManager

杨晟
2023-03-14

这是我的构建。gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

apply plugin: 'org.jetbrains.dokka'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.me.daggersample"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    flavorDimensions "version"
    productFlavors {
        production {
            dimension "version"
            minSdkVersion 17
        }
        uiTest {
            dimension "version"
            minSdkVersion 18
        }
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }

    dokka {
        outputFormat = 'html'
        outputDirectory = "$buildDir/javadoc"
    }
}

// To resolve //Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6
// https://stackoverflow.com/questions/48988778/cannot-inline-bytecode-built-with-jvm-target-1-8-into-bytecode-that-is-being-bui
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
    outputFormat = 'javadoc'
    outputDirectory = "$buildDir/javadoc"
}
configurations {
    androidTestImplementation.exclude module: 'guava'
    androidTestImplementation.exclude module: 'error_prone_annotations'
    androidTestImplementation.exclude module: 'checker-compat-qual'
    all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//    implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha02'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha02'
    implementation 'com.google.android.material:material:1.1.0-alpha04'

    //Navigation
    implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-rc02'
    implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-rc02'

    testImplementation 'org.mockito:mockito-inline:2.7.13'
    testImplementation 'com.nhaarman:mockito-kotlin-kt1.1:1.5.0'
    /*
        testImplementation 'org.robolectric:robolectric:4.0.2'
        testImplementation 'android.arch.core:core-testing:1.1.1'*/
    androidTestImplementation 'org.mockito:mockito-android:2.19.0'
    androidTestImplementation "org.robolectric:robolectric:4.2"
    androidTestImplementation 'androidx.test:core:' + rootProject.coreVersion
    androidTestImplementation 'androidx.test:core-ktx:' + rootProject.coreVersion
    androidTestImplementation 'androidx.test.ext:junit:' + rootProject.extJUnitVersion
    androidTestImplementation 'androidx.test.ext:junit-ktx:' + rootProject.extJUnitVersion
    androidTestImplementation 'androidx.test:runner:' + rootProject.runnerVersion
    androidTestImplementation 'androidx.test.espresso:espresso-core:' + rootProject.espressoVersion
    androidTestImplementation 'androidx.test.espresso:espresso-intents:' + rootProject.espressoVersion
    testImplementation 'junit:junit:4.12'
    // UiAutomator Testing
    androidTestImplementation 'androidx.test.uiautomator:uiautomator:' + rootProject.uiautomatorVersion;
    androidTestImplementation 'org.hamcrest:hamcrest-integration:1.3'


    implementation 'com.google.dagger:dagger-android:2.16'
    implementation 'com.google.dagger:dagger-android-support:2.16'
    kapt 'com.google.dagger:dagger-android-processor:2.16'
    kapt 'com.google.dagger:dagger-compiler:2.16'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation 'io.reactivex.rxjava2:rxjava:2.2.6'
    implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    implementation 'com.github.yongjhih.rx-mqtt:rx-mqtt-android:-SNAPSHOT'
//    implementation 'com.afollestad:aesthetic:1.0.0-beta05'

    implementation 'com.github.SherlockGougou:MagicIndicator:1.6.0'
    implementation 'com.patrickpissurno:ripple-effect:1.3.1'
}

该应用程序的构建和运行都很好,但是:当我试图运行UI自动测试时,我得到了错误:

AGPBI: {"kind":"error","text":"Program type already present: org.apache.maven.profiles.ProfileManager","sources":[{}],"tool":"D8"}
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForProductionDebugAndroidTest'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
Program type already present: org.apache.maven.profiles.ProfileManager
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.

共有1个答案

欧阳飞章
2023-03-14

Robolectric依赖项更改为

//Roboelectric
testImplementation ("org.robolectric:robolectric:$versions.robolectric"){
    exclude group: 'org.apache.maven'
}
 类似资料: