Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pencilcheck opened this issue Mar 22, 2018 · 17 comments

Comments

@pencilcheck
Copy link

Looks like the new gms breaks a lot of lib since "+" is now on the later version however it breaks the project.

Please if possible to support the ability to change the dependencies version for GCM: `facebook/react-native#18479

If possible if someone can create a PR similar to what @christocracy to the react-native-maps that would be awesome.
Example: react-native-maps/react-native-maps#2047

Thanks!

@ivan133
Copy link

ivan133 commented Mar 22, 2018

https://github.com/BlackTies/react-native-onesignal/commit/7ecedccf20a26fc9ce8a5d9ff44c7fb57bfd2e17

@christocracy
Copy link

Looks good @ivan133

@ivan133
Copy link

ivan133 commented Mar 22, 2018

It's not mine ;)
I just found someone already did it I've switched to this fork and it works.

@sators
Copy link

sators commented Mar 22, 2018

+1

@Nightsd01
Copy link
Contributor

Nightsd01 commented Mar 22, 2018

To fix this issue for now, I would recommend adding this grade plugin to the very top of your app/build.gradle file:

plugins {
    id 'com.onesignal.androidsdk.onesignal-gradle-plugin' version '0.8.1'
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

In the longer term, we will be fixing this issue in a cleaner way with an update to how the SDK handles dependencies. We will probably be releasing it in the next day or two.

@s123121
Copy link

s123121 commented Mar 26, 2018

@Nightsd01 I did add those options in my app/build.gradle but the problem still persist.

@pencilcheck
Copy link
Author

pencilcheck commented Mar 27, 2018

Cool, I hope the changes can be merged asap. Really appreciate for the short turnaround. Thanks.

@jxnata
Copy link

jxnata commented May 30, 2018

@Nightsd01 yesterday my app was running normally, today is giving this error :(
even adding the plugin the error continues

@christocracy
Copy link

@jxnata post your:

  • build.gradle
  • app/build.gradle

@jxnata
Copy link

jxnata commented May 30, 2018

@christocracy

build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

app/build.gradle:

plugins {
    id 'com.onesignal.androidsdk.onesignal-gradle-plugin' version '0.8.1'
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"

    defaultConfig {
        applicationId "**************"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        manifestPlaceholders = [onesignal_app_id: "***********", onesignal_google_project_number: "******"]
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

dependencies {
    compile project(':react-native-onesignal')
    compile project(':react-native-vector-icons')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:27.1.0"
    compile "com.facebook.react:react-native:+"   
}

task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

@christocracy
Copy link

You’re not implementing the gradle config params in your gradle files, producing erratic behaviour with multiple versions of google dependencies colliding.

@ayush221b
Copy link

@christocracy I am having the same issue as @jxnata . Here are my files:

build.gradle

`

def googlePlayServicesVersion = '15.0.1'

buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.0.0'
}
}

allprojects {
repositories {
mavenLocal()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
configurations.all {
resolutionStrategy {
force 'com.facebook.android:facebook-android-sdk:4.22.1'

            // react-native-admob
            force "com.google.android.gms:play-services-ads:$googlePlayServicesVersion"

            // force "com.google.android.gms:play-services-base:$googlePlayServicesVersion"
            // force "com.google.android.gms:play-services-maps:$googlePlayServicesVersion"


            // react-native-onesignal
            force "com.google.android.gms:play-services-gcm:$googlePlayServicesVersion"
            force "com.google.android.gms:play-services-analytics:$googlePlayServicesVersion"
            force "com.google.android.gms:play-services-location:$googlePlayServicesVersion"

            // react-native-google-sign-in
            force "com.google.android.gms:play-services-auth:$googlePlayServicesVersion"
        }
    }

}

`

app/build.gradle

`plugins {
id 'com.onesignal.androidsdk.onesignal-gradle-plugin' version '0.8.1'
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: "com.android.application"

import com.android.build.OutputFile

/**

  • The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
  • and bundleReleaseJsAndAssets).
  • These basically call react-native bundle with the correct arguments during the Android build
  • cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
  • bundle directly from the development server. Below you can see all the possible configurations
  • and their defaults. If you decide to add a configuration block, make sure to add it before the
  • apply from: "../../node_modules/react-native/react.gradle" line.
  • project.ext.react = [
  • // the name of the generated asset file containing your JS bundle
  • bundleAssetName: "index.bundle",
  • // the entry file for bundle generation
  • entryFile: "index.js",
  • // whether to bundle JS and assets in debug mode
  • bundleInDebug: false,
  • // whether to bundle JS and assets in release mode
  • bundleInRelease: true,
  • // whether to bundle JS and assets in another build variant (if configured).
  • // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
  • // The configuration property can be in the following formats
  • // 'bundleIn${productFlavor}${buildType}'
  • // 'bundleIn${buildType}'
  • // bundleInFreeDebug: true,
  • // bundleInPaidRelease: true,
  • // bundleInBeta: true,
  • // the root of your project, i.e. where "package.json" lives
  • root: "../../",
  • // where to put the JS bundle asset in debug mode
  • jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
  • // where to put the JS bundle asset in release mode
  • jsBundleDirRelease: "$buildDir/intermediates/assets/release",
  • // where to put drawable resources / React Native assets, e.g. the ones you use via
  • // require('./image.png')), in debug mode
  • resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
  • // where to put drawable resources / React Native assets, e.g. the ones you use via
  • // require('./image.png')), in release mode
  • resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
  • // by default the gradle tasks are skipped if none of the JS files or assets change; this means
  • // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
  • // date; if you have any other folders that you want to ignore for performance reasons (gradle
  • // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
  • // for example, you might want to remove it from here.
  • inputExcludes: ["android/", "ios/"],
  • // override which node gets called and with what additional arguments
  • nodeExecutableAndArgs: ["node"],
  • // supply additional arguments to the packager
  • extraPackagerArgs: []
  • ]
    */

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 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.beonews"
    minSdkVersion 16
    targetSdkVersion 26
    versionCode 22
    versionName "2.8.4"
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
    // Enabling multidex support.
    multiDexEnabled true

    manifestPlaceholders = [onesignal_app_id: "****************************",
                                    onesignal_google_project_number: "REMOTE"]
}
signingConfigs {
    release {
        if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
            storeFile file(MYAPP_RELEASE_STORE_FILE)
            storePassword MYAPP_RELEASE_STORE_PASSWORD
            keyAlias MYAPP_RELEASE_KEY_ALIAS
            keyPassword MYAPP_RELEASE_KEY_PASSWORD
        }
    }
}
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"
        signingConfig signingConfigs.release
    }
}
// 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-fast-image')
compile project(':react-native-admob')
compile project(':react-native-onesignal')
compile project(':react-native-fbsdk')
compile project(':react-native-blur')
compile project(':react-native-linear-gradient')
compile project(':react-native-vector-icons')
compile 'com.facebook.android:facebook-android-sdk:[4.22.1)'
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.1.1"
compile 'com.google.android.gms:play-services-ads:11.8.0'
compile "com.facebook.react:react-native:+" // From node_modules
}
//apply plugin: 'com.google.gms.google-services'

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

@jxnata
Copy link

jxnata commented May 30, 2018

@christocracy Sorry, but how do I do this? It's my first android app rsrs... Thanks!

@christocracy
Copy link

christocracy commented May 30, 2018

To your build.gradle, add the following block at the bottom:

ext {
    compileSdkVersion   = 26
    targetSdkVersion    = 26
    buildToolsVersion   = "26.0.2"
    supportLibVersion   = "26.1.0"
    googlePlayServicesVersion = "11.8.0" 
}

Many 3rd party modules are aware of these variables and will align their dependencies to them. It's up to you to decide what specific versions to apply.

In your android/build.gradle now, use these variables:

android {
+    compileSdkVersion rootProject.compileSdkVersion
+    buildToolsVersion rootProject.buildToolsVersion

    defaultConfig {
+        targetSdkVersion rootProject.targetSdkVersion
         .
         .
         .
    }
}

dependencies {
    .
    .    
+   compile "com.android.support:appcompat-v7:$rootProject.supportLibVersion"  // <-- note double-quotes for variable interpolation

     ////
     // If you're importing play-services dependencies in your project, use the 
     // googlePlayServicesVersion
    //
+   compile "com.google.android.gms:play-services-ads:$rootProject.googlePlayServicesVersion"
}

@jxnata
Copy link

jxnata commented May 30, 2018

@christocracy
Thank u for the explanation! Unfortunately it still gives the same error...
I will search more about

@jxnata
Copy link

jxnata commented May 30, 2018

@ayush221b @christocracy I was finally able to solve it! The error was in the gradle wrapper version. I was using version 2.14, updated and worked perfectly:

/android/gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

@christocracy
Copy link

You'll want to get in the habit of using these Gradle Configuration Properties. You can visit the android/build.gradle of any module to see if they're supported.

eg: here's onesignal's build.gradle: note how it fetches values from rootProject.

Many other modules are aware of these variables. Eg: here's react-native-maps and react-native-device-info

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants