gpt4 book ai didi

android - Protobuffers错误将库添加到android

转载 作者:行者123 更新时间:2023-11-30 01:28:38 24 4
gpt4 key购买 nike

我有以下错误:

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in 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

当我添加这个 lite 时出现这个错误:

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
}

最佳答案

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

关于android - Protobuffers错误将库添加到android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36064438/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com