我在Android上遇到了react-native-camera的问题。它现在工作正常一周左右,突然,Gradle不会构建出现以下错误:
Error:Execution failed for task ':react-native-camera:processReleaseResources'.
> Error: more than one library with package name 'com.google.android.gms.license'
从我收集的内容来看,这是由多次加载com.google.android.gms引起的。我按照RNCamera文档进行操作,确保我的Gradle文件匹配。
机器人/应用/的build.gradle:
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.phase1"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 +
defaultConfig.versionCode
}
}
}
}
dependencies {
compile (project(':react-native-camera')) {
exclude group: "com.google.android.gms"
compile 'com.android.support:exifinterface:27.+'
}
//compile project(':react-native-camera')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
}
机器人/ settings.gradle:
rootProject.name = 'Phase1'
include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
include ':app'
机器人/的build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven { url "https://jitpack.io" }
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
以下是外部图书馆中的所有com.google.android.gms条目,我在这里看不到任何重复项并尝试了所有答案Gradle: Error: more than one library with package name 'com.google.android.gms'
我尝试删除com.android.support:appcompat-v7版本,创建新项目,卸载并重新安装Android SDK Build Tools(23.0.1,25.0.2,26.0.1,26.0.2, 27.0.3)& Android支持存储库,已经没有想法。我使用的是Android Studio 3.0.1,gradle-2.14.1
从Gradle文件中删除相机引用后,项目构建正常并按预期工作。所以我现在很困惑。任何建议将不胜感激。
答案 0 :(得分:5)
这是因为谷歌服务版本更新(12.0.0)。您应该通过编辑android / build.gradle文件将其指回11.8.0:
def googlePlayServicesVersion = '11.8.0'
allprojects {
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (requested.group == 'com.google.android.gms') {
details.useVersion "$googlePlayServicesVersion"
}
if (requested.group == 'com.google.firebase') {
details.useVersion "$googlePlayServicesVersion"
}
}
}
}
}