使用操作系统独立路径"protobuf.meta"找到了多个文件 [英] More than one file was found with OS independent path 'protobuf.meta'

查看:115
本文介绍了使用操作系统独立路径"protobuf.meta"找到了多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现com.google.android.gms:play-services-auth:11.6.0com.android.support.test.espresso:espresso-core:3.0.1之间的兼容性存在一些问题 用作android库模块的依赖项时

I'm seeing some issues with compatibility between com.google.android.gms:play-services-auth:11.6.0 and com.android.support.test.espresso:espresso-core:3.0.1 when used as dependencies on an android library module

我收到此错误:

Execution failed for task ':mylibrary:transformResourcesWithMergeJavaResForDebugAndroidTest'.   
More than one file was found with OS independent path 'protobuf.meta'

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

这是一个准系统build.gradle,我在以下位置重现了该问题:

Here's a barebones build.gradle that I've reproduced the problem on:

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

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

I don't think I can exclude either of these files as the contents is different.

推荐答案

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

This issue occurred because you use two separate imports containing the same file. Your issue is with an external library that may have duplicate contents or was imported twice, to solve this You should put these lines of code inside build.gradle (Module: app).

添加以下几行:

android {
    // [...]
    packagingOptions {
        pickFirst 'protobuf.meta'
    }
}

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

Sometimes, it is also possible to completely exclude this file: exclude 'protobuf.meta'

在多模块项目的情况下,由于工具测试中的此错误,Android库无法构建,因此可能需要在 build.gradle 中包含此代码段.

In case of multi-module projects, Android libraries failing to build due to this error on instrumentation tests, might need to include this snippet inside build.gradle.

这篇关于使用操作系统独立路径"protobuf.meta"找到了多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆