transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.61k stars 428 forks source link

[ Android ] Could invoke RNBackgroundGeolocation.configure #375

Closed kulyk closed 6 years ago

kulyk commented 6 years ago

Environment

Behavior

I've been using react-native-background-geolocation-android (installed with token) for a couple of months. Worked perfectly on both iOS and Android. But during last few days, I can't even start the Android app (iOS works fine).

Screenshot of the error is attached.

Context

Tried reinstalling whole dependencies, ./gradlew clean. Nothing helps 😢

screen shot 2017-12-21 at 12 31 24 pm
christocracy commented 6 years ago

The first thing you do when your app crashes is capture the exception stacktrace in $ adb logcat.

There you’ll likely find an exception related to ActivityRecognitionClient.

The plugin now requires play-services min version 11.20.

kulyk commented 6 years ago

@christocracy do you mean 11.2.0 is the min version? I've tried using 11.2.0 and 11.6.0

The only thing I get from adb logcat related to ActivityRecognitionClient is:

FATAL EXCEPTION: mqt_native_modules
Process: APPS_BUNDLE_ID, PID: 26344

java.lang.IncompatibleClassChangeError: Superclass com.google.android.gms.internal.zzbej of com.google.android.gms.location.ActivityRecognitionResult is declared final (declaration of 'com.google.android.gms.location.ActivityRecognitionResult' appears in /data/app/APPS_BUNDLE_ID-1/base.apk)
                                                       at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.<init>(RNBackgroundGeolocationModule.java:82)
                                                       at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocation.createNativeModules(RNBackgroundGeolocation.java:21)
                                                       at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:106)
                                                       at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1191)
                                                       at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1161)
                                                       at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1094)
                                                       at com.facebook.react.ReactInstanceManager.access$800(ReactInstanceManager.java:112)
                                                       at com.facebook.react.ReactInstanceManager$4.run(ReactInstanceManager.java:922)
                                                       at java.lang.Thread.run(Thread.java:761)
christocracy commented 6 years ago

No, I I mean Google Play Services version. Paste your app/build.gradle

kulyk commented 6 years ago
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.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.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: []
 * ]
 */

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
def keystorePropertiesFile = rootProject.file("keystores/release.keystore.properties")

def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        applicationId "com.app.app"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        multiDexEnabled true
    }
    signingConfigs {
        release {
            keyAlias keystoreProperties['key.alias']
            keyPassword keystoreProperties['key.alias.password']
            storeFile file(keystoreProperties['key.store'])
            storePassword keystoreProperties['key.store.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
            }
        }
    }
}

repositories {
    flatDir {
        dirs "../../node_modules/react-native-background-geolocation-android/android/libs"
    }
}

dependencies {
    compile(name: 'tslocationmanager', ext: 'aar')
    compile project(':react-native-background-geolocation-android')
    compile ("com.google.android.gms:play-services-location:11.6.0") {
        force = true;
    }
    compile project(':react-native-fcm')
    compile 'com.google.firebase:firebase-core:10.0.1'
    compile project(':react-native-svg')
    compile project(':react-native-linear-gradient')
    compile project(':react-native-keep-awake')
    compile project(':react-native-orientation')
    compile project(':react-native-sound')
    compile project(':react-native-zip-archive')
    compile project(':react-native-fetch-blob')
    compile project(':react-native-device-info')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:26.0.1"
    compile "com.facebook.react:react-native:+"
    compile project(':react-native-navigation')
    compile project(':react-native-image-crop-picker')
    compile project(':react-native-vector-icons')
    compile project(':react-native-video')
}

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

apply plugin: 'com.google.gms.google-services'
christocracy commented 6 years ago

Firebase dependencies must align to the same version as play-services version.

compile project(':react-native-fcm') compile 'com.google.firebase:firebase-core:10.0.1'

kulyk commented 6 years ago

Changed to compile 'com.google.firebase:firebase-core:11.6.0', didn't help :( And it was working with 10.0.1 for two months. The build.gradle file hasn't been changed for a long time

christocracy commented 6 years ago

Version 2.10.1 of this plugin requires min play-services 11.2.0.

You have other dependencies requesting inferior play-services / Firebase dependencies.

Look inside the build.gradle of react-native-fcm. You’ll find the problem is there.

See my sample app for an example of how to override the dependencies of another plugin and enforce your desired version.

https://github.com/transistorsoft/rn-background-geolocation-demo/blob/master/android/app/build.gradle#L166

christocracy commented 6 years ago

And to see your entire dependency tree:

$ cd android 
$ ./gradlew app:dependencies
kulyk commented 6 years ago

So now it's

compile project(':react-native-background-geolocation-android')
compile(name: 'tslocationmanager', ext: 'aar')
compile 'com.google.android.gms:play-services-location:11.2.0'
compile(project(':react-native-fcm')) {
   exclude group: 'com.google.android.gms'
}
compile 'com.google.firebase:firebase-core:11.2.0'

But I still face the issue

christocracy commented 6 years ago

Yes, because you need to address EVERY firebase dependency within react-Native-fcm.

https://github.com/evollu/react-native-fcm/blob/master/android/build.gradle

kulyk commented 6 years ago

@christocracy it helped! Thank you very much! Closing the issue

anarqz commented 6 years ago

@antonkulyk can you please send your updated build.gradle after the solution?

noumantahir commented 6 years ago

having similar error, not sure what I am doing wrong, it was working find few days back....below is my app level build.gradle...

apply plugin: "com.android.application"
apply plugin: "io.fabric"

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 "com.zoobidriver"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 7
        versionName "0.3.3"
        multiDexEnabled true
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    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 {

    implementation 'com.android.support:multidex:1.0.3'
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
        transitive = true
    }

    //react native packages
    implementation "com.facebook.react:react-native:+" 
    implementation project(':react-native-device-info')
    implementation project(':react-native-network-info')
    implementation project(':react-native-firebase')
    implementation project(':react-native-image-picker')
    implementation project(':react-native-background-fetch')
    implementation project(':react-native-background-geolocation')
    implementation project(':react-native-geocoder')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-sound')
    implementation (project(':react-native-maps')){
        exclude group: 'com.google.android.gms', module: 'play-services-base'
        exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }

    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:27.1.1"
    implementation "com.android.support:support-v4:27.1.1"

    //google play services
    implementation 'com.google.android.gms:play-services-base:15.0.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation "com.google.android.gms:play-services-base:15.0.1"

    //firebase related packages
    implementation "com.google.firebase:firebase-core:16.0.3"
    implementation "com.google.firebase:firebase-messaging:17.3.0"
    implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
    implementation "com.google.firebase:firebase-storage:16.0.1"
    implementation "com.google.firebase:firebase-auth:16.0.3"
    implementation "com.google.firebase:firebase-database:16.0.1"

}

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

apply plugin: 'com.google.gms.google-services'

and below is the error report.....


java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/location/ActivityRecognitionResult;
        at java.lang.reflect.Executable.getParameterTypesInternal(Native Method)
        at java.lang.reflect.Method.getParameterTypes(Method.java:179)
        at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingReflectionInSingleClass(SubscriberMethodFinder.java:163)
        at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingInfo(SubscriberMethodFinder.java:88)
        at org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(SubscriberMethodFinder.java:64)
        at org.greenrobot.eventbus.EventBus.register(EventBus.java:136)
        at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation.<init>(Unknown Source:150)
        at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation.a(Unknown Source:13)
        at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation.getInstance(Unknown Source:19)
        at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.getAdapter(RNBackgroundGeolocationModule.java:993)
        at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.initializeLocationManager(RNBackgroundGeolocationModule.java:967)
        at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.onHostResume(RNBackgroundGeolocationModule.java:276)
        at com.facebook.react.bridge.ReactContext.onHostResume(ReactContext.java:186)
        at com.facebook.react.ReactInstanceManager.moveToResumedLifecycleState(ReactInstanceManager.java:687)
        at com.facebook.react.ReactInstanceManager.onHostResume(ReactInstanceManager.java:606)
        at com.facebook.react.ReactActivityDelegate.onResume(ReactActivityDelegate.java:102)
        at com.facebook.react.ReactActivity.onResume(ReactActivity.java:66)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1355)
        at android.app.Activity.performResume(Activity.java:7117)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3556)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3621)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1638)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.ClassNotFoundException: com.google.android.gms.location.ActivityRecognitionResult
        at java.lang.VMClassLoader.findLoadedClass(Native Method)
        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at java.lang.reflect.Executable.getParameterTypesInternal(Native Method) 
        at java.lang.reflect.Method.getParameterTypes(Method.java:179) 
        at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingReflectionInSingleClass(SubscriberMethodFinder.java:163) 
        at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingInfo(SubscriberMethodFinder.java:88) 
        at org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(SubscriberMethodFinder.java:64) 
        at org.greenrobot.eventbus.EventBus.register(EventBus.java:136) 
        at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation.<init>(Unknown Source:150) 
        at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation.a(Unknown Source:13) 
        at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation.getInstance(Unknown Source:19) 
        at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.getAdapter(RNBackgroundGeolocationModule.java:993) 
        at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.initializeLocationManager(RNBackgroundGeolocationModule.java:967) 
        at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.onHostResume(RNBackgroundGeolocationModule.java:276) 
        at com.facebook.react.bridge.ReactContext.onHostResume(ReactContext.java:186) 
        at com.facebook.react.ReactInstanceManager.moveToResumedLifecycleState(ReactInstanceManager.java:687) 
        at com.facebook.react.ReactInstanceManager.onHostResume(ReactInstanceManager.java:606) 
        at com.facebook.react.ReactActivityDelegate.onResume(ReactActivityDelegate.java:102) 
        at com.facebook.react.ReactActivity.onResume(ReactActivity.java:66) 
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1355) 
        at android.app.Activity.performResume(Activity.java:7117) 
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3556) 
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3621) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1638) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/internal/zzbfm;
        at java.lang.reflect.Executable.getParameterTypesInternal(Native Method) 
        at java.lang.reflect.Method.getParameterTypes(Method.java:179) 
        at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingReflectionInSingleClass(SubscriberMethodFinder.java:163) 
        at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingInfo(SubscriberMethodFinder.java:88) 
        at org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(SubscriberMethodFinder.java:64) 
        at org.greenrobot.eventbus.EventBus.register(EventBus.java:136) 
        at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation.<init>(Unknown Source:150) 
        at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation.a(Unknown Source:13) 
        at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation.getInstance(Unknown Source:19) 
        at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.getAdapter(RNBackgroundGeolocationModule.java:993) 
        at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.initializeLocationManager(RNBackgroundGeolocationModule.java:967) 
        at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.onHostResume(RNBackgroundGeolocationModule.java:276) 
        at com.facebook.react.bridge.ReactContext.onHostResume(ReactContext.java:186) 
        at com.facebook.react.ReactInstanceManager.moveToResumedLifecycleState(ReactInstanceManager.java:687) 
        at com.facebook.react.ReactInstanceManager.onHostResume(ReactInstanceManager.java:606) 
        at com.facebook.react.ReactActivityDelegate.onResume(ReactActivityDelegate.java:102) 
        at com.facebook.react.ReactActivity.onResume(ReactActivity.java:66) 
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1355) 
        at android.app.Activity.performResume(Activity.java:7117) 
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3556) 
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3621) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1638) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.internal.zzbfm" on path: DexPathList[[zip file "/data/app/com.zoobidriver-TYzkLmQsXMP95rMkxutXWA==/base.apk"],nativeLibraryDirectories=[/data/app/com.zoobidriver-TYzkLmQsXMP95rMkxutXWA==/lib/x86, /data/app/com.zoobidriver-TYzkLmQsXMP95rMkxutXWA==/base.apk!/lib/x86, /system/lib, /vendor/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
christocracy commented 6 years ago

Your android/app/build.gradle is a mess. Post your android/build.gradle

christocracy commented 6 years ago

@noumantahir and if you're going to do a "me too" post, you should also post your environment stats as in the OP.

Plugin version: ???
Platform: Android
OS version:  ???
Device manufacturer / model: ???
React Native version (react-native -v): ???
noumantahir commented 6 years ago

cleaned things up a little in app level gradle file...below is the project level gradle file

buildscript {
    repositories {
        jcenter()
        google()

        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:3.2.1'
        classpath 'io.fabric.tools:gradle:1.25.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven {
            url 'https://maven.fabric.io/public'
        }
        google()
        maven { url "https://maven.google.com" }
        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 "$rootDir/../node_modules/react-native-background-geolocation/android/libs"
       }
       maven {
           url "$rootDir/../node_modules/react-native-background-fetch/android/libs"
       }

    }
}
christocracy commented 6 years ago

First-of-all, see the Android Setup Docs where it's recommended you implement the Gradle Config Properties:

ext {
    compileSdkVersion   = 27
    targetSdkVersion    = 27
    buildToolsVersion   = "27.0.3"
    supportLibVersion   = "27.1.1"
    googlePlayServicesVersion = "15.0.1"
}

If you generate a new RN app ($ react-native init Foo), you'll notice that RN now automatically adds this block to the android/build.gradle.

Next, you now implement these variables in your android/app/build.gradle, eg:

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

    defaultConfig {
         .
         .
         .
+        minSdkVersion rootProject.ext.minSdkVersion
+        targetSdkVersion rootProject.ext.targetSdkVersion
    }
}

Finally, most popular RN modules are now aware of these Gradle Config Params. You no longer need to mess around with exclude group. react-native-maps is aware of googlePlayServicesVersion.

implementation (project(':react-native-maps')){
        exclude group: 'com.google.android.gms', module: 'play-services-base'
        exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }

You can probably get rid of all this firebase messing around too:

//firebase related packages
    implementation "com.google.firebase:firebase-core:16.0.3"
    implementation "com.google.firebase:firebase-messaging:17.3.0"
    implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
    implementation "com.google.firebase:firebase-storage:16.0.1"
    implementation "com.google.firebase:firebase-auth:16.0.3"
    implementation "com.google.firebase:firebase-database:16.0.1"

Also, use the Gradle Config Param supportLibVersion instead of hard-coding as well:

    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"
noumantahir commented 6 years ago

@christocracy here is more info you requested...

Plugin version: "^2.12.0" Platform: Android OS version: 8.1.0 Device manufacturer / model: Pixel 2 XL React Native version (react-native -v): 0.5.2

p.s. I am willing to provide any other relevant information, still getting familiar with github issues norms

noumantahir commented 6 years ago

Thanks, aligning versions using your global ext method worked well...

michael-aries11 commented 1 year ago

Thanks @christocracy . This thread has been helpful in 2022. I had a mismatch in my googleplayservices version and firebase version.

christocracy commented 1 year ago

The ultimate authority on google apis/versions is https://maven.google.com

mikehardy commented 1 year ago

I actually like this table here - I usually use it as a reference when I'm doing a pass on new version qualification / integration https://developers.google.com/android/guides/setup