我正在尝试在Android上构建React Native项目,但我遇到了各种各样的Android依赖项问题。目前,我发现了这个错误:
* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzfkt.class
这是我的build.gradle
文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
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'
}
maven {
url "$rootDir/../node_modules/react-native-background-geolocation-android/android/libs"
}
maven {
url "$rootDir/../node_modules/react-native-background-fetch/android/libs"
}
}
}
ext {
compileSdkVersion = 26
targetSdkVersion = 26
buildToolsVersion = "26.0.2"
supportLibVersion = "26.1.0"
playServicesVersion = "11.8.0"
}
我的app/build.gradle
:
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
targetSdkVersion rootProject.targetSdkVersion
applicationId "com.gonote"
minSdkVersion 16
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
multiDexEnabled true
}
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 'com.google.firebase:firebase-core:10.0.1' //this decides your firebase SDK version
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile project(':react-native-svg')
compile project(':react-native-sms')
compile project(':react-native-image-resizer')
compile project(':react-native-image-picker')
compile project(':react-native-fcm')
compile project(':react-native-device-info')
compile project(':react-native-contacts')
compile project(':react-native-background-geolocation-android')
compile project(':react-native-background-fetch')
compile project(':react-native-android-location-services-dialog-box')
compile project(':react-native-device-info')
compile project(':react-native-contacts')
compile project(':react-native-android-location-services-dialog-box')
compile project(':react-native-background-fetch')
compile project(':react-native-background-fetch')
compile project(':react-native-background-geolocation-android')
compile project(':react-native-background-geolocation-android')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.android.support:appcompat-v7:$rootProject.supportLibVersion"
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
此错误消息让我很少继续。从我发现的搜索谷歌是由于某种谷歌播放服务版本不匹配引起的,但我不知道我应该如何在这个混乱中找到它。
答案 0 :(得分:0)
此错误与您在项目中使用的不同库所需的不同版本的gms模块有关。请查看此文章以获取有关如何解决此问题的最佳说明:https://medium.com/@suchydan/how-to-solve-google-play-services-version-collision-in-gradle-dependencies-ef086ae5c75f