Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Camera causing gradle build error

I'm having an issue with react-native-camera on Android. It was working fine for about a week now and suddenly, Gradle won't build giving the following error:

Error:Execution failed for task ':react-native-camera:processReleaseResources'.
> Error: more than one library with package name 'com.google.android.gms.license'

From what I gather this is caused by com.google.android.gms being loaded more than once. I followed the RNCamera docs and ensured my Gradle files match.

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

Here is all the com.google.android.gms entries in external libraries, I don't see any duplicates and tried all answers in here Gradle: Error: more than one library with package name 'com.google.android.gms'

external libs

I've tried removing com.android.support:appcompat-v7 version, creating a new project, uninstalling and reinstalling Android SDK Build Tools (23.0.1, 25.0.2, 26.0.1, 26.0.2, 27.0.3) & Android Support Repository and have run out of ideas. I'm using Android Studio 3.0.1, gradle-2.14.1

Once I remove the camera refs from the Gradle files, the project builds fine and works as expected. So I am really confused now. Any advice would be greatly appreciated.

like image 847
Keith Burke Avatar asked Mar 21 '18 23:03

Keith Burke


Video Answer


1 Answers

This is because the google service version update(12.0.0). You should point it back to 11.8.0 by editing the android/build.gradle file:

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"
        }
      }
    }
  }
}
like image 69
Thanh Lam Avatar answered Oct 11 '22 16:10

Thanh Lam