Android Studio:在APK project.properties中复制的重复文件

时间:2017-05-24 08:29:01

标签: android gradle google-api android-gradle google-translate

将Google翻译API compile 'com.google.cloud:google-cloud-translate:0.18.0-beta'添加到我的项目后,我收到了一个奇怪的错误

  

错误:任务执行失败':ParseStarterProject:transformResourcesWithMergeJavaResForDebug'。   com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException:在APK project.properties中复制的重复文件       File1:.gradle / caches / modules-2 / files-2.1 / com.google.cloud / google-cloud-translate / 0.18.0-beta / 9cac04f2bb48f76f352bf65d782506e4aa18406c / google-cloud-translate-0.18.0-beta.jar       File2:/.gradle/caches/modules-2/files-2.1/com.google.cloud/google-cloud-core/1.0.2/ff451b4b785369093bd91d277c22576fc9c1da3a/google-cloud-core-1.0.2.jar

还有其他SO帖子提到“在APK META_INF中复制的重复文件”,或“在APK LICENSE.txt中复制的重复文件”等等

但是,我还没有看到其他人遇到错误“在APK project.properties中复制的重复文件”

将这些添加到我的gradle无效

packagingOptions {
  exclude 'META-INF/LICENSE'
  exclude 'META-INF/io.netty.versions.properties'
  exclude 'META-INF/INDEX.LIST'
  exclude 'META-INF/DEPENDENCIES'
  exclude 'META-INF/NOTICE'
  exclude 'META-INF/LICENSE.txt'
  exclude 'META-INF/NOTICE.txt'
}

还有什么我可以添加到我的gradle来修复此错误吗?或者是否有其他方法通过删除错误日志中显示的“FILE2”来修复此错误?

摇篮

apply plugin: 'com.android.application'

android {
 useLibrary 'org.apache.http.legacy'
 packagingOptions {
   // exclude 'META-INF/LICENSE'
   //exclude 'META-INF/io.netty.versions.properties'
   //exclude 'META-INF/INDEX.LIST'
 }

compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
    multiDexEnabled true
    applicationId "com.package.name"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 41
    versionName "2.1"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
lintOptions {
    disable 'MissingTranslation'
    disable 'ExtraTranslation'
}
dexOptions {
    javaMaxHeapSize "4g"
}

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.google.firebase:firebase-core:10.2.0'
    compile 'com.google.firebase:firebase-messaging:10.2.0'
    //noinspection GradleCompatible
    compile 'com.google.cloud:google-cloud-translate:0.18.0-beta'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.parse.bolts:bolts-tasks:1.3.0'
    compile 'com.parse:parse-android:1.13.0'
    compile 'com.android.support:multidex:1.0.1'
    //noinspection GradleDynamicVersion
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    //noinspection GradleCompatible
    compile 'com.google.android.gms:play-services-ads:10.2.0'
    // compile 'com.onesignal:OneSignal:3.4.3@aar'

  }


 }
apply plugin: 'com.google.gms.google-services'
 dependencies {
 compile 'com.android.support.constraint:constraint-layout:1.0.1'
  }

2 个答案:

答案 0 :(得分:10)

在我的情况下,

packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/io.netty.versions.properties'
    exclude 'META-INF/INDEX.LIST'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'project.properties' <------------------------here
}

答案 1 :(得分:3)

删除google云核心依赖

添加翻译依赖时执行此操作

compile ('com.google.cloud:google-cloud-translate:0.5.0') {
    exclude group: 'io.grpc', module: 'grpc-all'
    exclude group: 'com.google.protobuf', module: 'protobuf-java'
    exclude group: 'com.google.api-client', module: 'google-api-client-
    appengine'
}