【问题标题】:React Native Camera causing gradle build errorReact Native Camera 导致 gradle 构建错误
【发布时间】:2018-08-31 06:33:12
【问题描述】:

我在 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 文件匹配。

android/app/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
}

android/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'

android/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 Support Repository 已经没有想法了。我正在使用 Android Studio 3.0.1,gradle-2.14.1

一旦我从 Gradle 文件中删除了相机引用,项目就可以正常构建并按预期工作。所以我现在真的很困惑。任何建议将不胜感激。

【问题讨论】:

    标签: android android-studio react-native android-gradle-plugin react-native-camera


    【解决方案1】:

    这是因为谷歌服务版本更新(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"
            }
          }
        }
      }
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-20
    • 1970-01-01
    相关资源
    最近更新 更多