在OS独立路径'protobuf.meta'中找到了多个文件

AJD*_*AJD 4 android protocol-buffers android-gradle-plugin android-espresso

我看到一些问题之间的兼容性com.google.android.gms:play-services-auth:11.6.0,并com.android.support.test.espresso:espresso-core:3.0.1 作为依赖使用的Android库模块上时

我收到这个错误:

Execution failed for task ':mylibrary:transformResourcesWithMergeJavaResForDebugAndroidTest'.   
More than one file was found with OS independent path 'protobuf.meta'
Run Code Online (Sandbox Code Playgroud)

当我尝试执行时 ./gradlew :myLibrary:connectedAndroidTest

这是一个准确的build.gradle,我已经重现了这个问题:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26



    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.google.android.gms:play-services-auth:11.6.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Run Code Online (Sandbox Code Playgroud)

我不认为我可以排除这些文件中的任何一个,因为内容不同.

小智 15

出现此问题是因为您使用包含相同文件的两个单独导入.您的问题是外部库可能有重复内容或导入两次,以解决此问题您应该将这些代码行放在build.gradle(Module:app)中.

添加以下行:

android {
    // [...]
    packagingOptions {
        pickFirst 'protobuf.meta'
    }
}
Run Code Online (Sandbox Code Playgroud)

有时,也可以完全排除此文件: exclude 'protobuf.meta'

对于多模块项目,由于检测测试中的此错误而无法构建的Android库可能需要在build.gradle中包含此代码段.