我在 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 中尝试了所有答案:错误:多个库的包名称为“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 Support Repository 已经没有想法了。我正在使用 Android Studio 3.0.1,gradle-2.14.1
一旦我从 Gradle 文件中删除了相机参考,该项目就可以正常构建并按预期工作。所以我现在真的很困惑。任何建议将不胜感激。