Protobuffers错误添加库到android

时间:2016-03-17 15:06:10

标签: android maven google-app-engine android-studio protocol-buffers

我有以下错误:

  

错误:任务执行失败   ':应用程序:transformResourcesWithMergeJavaResForDebug'。   com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException:在APK plugin.xml中复制的重复文件       File1:/home/aaa/.gradle/caches/modules-2/files-2.1/org.eclipse.sisu/org.eclipse.sisu.inject/0.0.0.M5/4f6bda3f528c60a12e70db2e7a3feee539dcc8cd/org.eclipse.sisu.inject- 0.0.0.M5.jar       File2:/home/aaa/.gradle/caches/modules-2/files-2.1/kr.motd.maven/os-maven-plugin/1.2.3.Final/5467b32e1fe84f9ee2ea00a7e64128a269fb44a6/os-maven-plugin-1.2.3。 Final.jar

当我添加这个精简版时,我收到此错误:

compile 'com.google.protobuf:protobuf-gradle-plugin:0.7.6

到build.grandle(app)依赖项:

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.1"

        defaultConfig.with {
            applicationId = "com.google.sample.helloandroid"
            minSdkVersion.apiLevel = 17
            targetSdkVersion.apiLevel = 23
            versionCode = 1
            versionName = "1.0"
        }
    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles.add(file('proguard-android.txt'))
        }
    }
    android.ndk {
        moduleName = "hello-android-jni"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.google.protobuf:protobuf-gradle-plugin:0.7.6'
}

我该如何解决这个问题?我需要添加要在项目中使用的protobuf

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

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle-experimental:0.4.0'
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.6'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

1 个答案:

答案 0 :(得分:1)

Protobuf应该在buildscript级别添加,它应该在build.gradle中,它位于根文件夹中不在/app内,同时请确保你使用gradle 2.12+和Java7:

buildscript {
  repositories {
    jcenter()
    mavenCentral()
  }
  dependencies {
    classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.6'
  }
}
allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

然后在你的app / build.gradle下执行此操作:

android {
     packagingOptions {
          pickFirst 'plugin.xml'
     }
}