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.64k stars 425 forks source link

All of a sudden, app started crashing on startup even though the codes of this plugin were never touched. #1563

Closed RuzenDev closed 2 years ago

RuzenDev commented 2 years ago

All of a sudden, we are having crashes on android when the app starts.

Your Environment

Expected Behavior

It should not crash.

Actual Behavior

App is crashing on startup.

Context

We havent touched any codes related with this plugin. All of a sudden, it started crashing.

Debug logs

Logs ``` The logs below are from firebase crashlytics. Fatal Exception: java.lang.IncompatibleClassChangeError: Found interface com.google.android.gms.location.FusedLocationProviderClient, but class was expected (declaration of 'com.google.android.gms.location.FusedLocationProviderClient' appears in /data/app/~~mDofj7Nsc77fSwgNVRxamA==/com.taknal.app.dev-L5fPGa6FVs_vlYzCh-W5Mg==/base.apk!classes3.dex) at com.transistorsoft.locationmanager.location.SingleLocationRequest.startUpdatingLocation(:123) at com.transistorsoft.locationmanager.service.LocationRequestService.handleStartAction(:74) at com.transistorsoft.locationmanager.service.LocationRequestService.access$200() at com.transistorsoft.locationmanager.service.LocationRequestService$a.run(:62) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637) at java.lang.Thread.run(Thread.java:1012) ```
mikehardy commented 2 years ago

What version of the package is actually installed? When you specify a dependency with ^ you may accidentally update package versions without realizing you are doing so.

This doesn't really have enough information to troubleshoot unfortunately (https://stackoverflow.com/help/how-to-ask / https://stackoverflow.com/help/minimal-reproducible-example)

christocracy commented 2 years ago

Your originally posted issue said

Plugin version: ^4.1.1

You later edited to 4.8.2.

which version of the plugin generated that error??

RuzenDev commented 2 years ago

@mikehardy Thank you for your response. Its 4.8.2 . I did try with other version but having same issue.

christocracy commented 2 years ago

Post your gradle files.

RuzenDev commented 2 years ago

@christocracy Thank you for your response. Am sorry, actually the version is 4.8.2. Then we tried with 4.1.1 with same result.

As requested, these are the gradle files. android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "32.0.3"
        minSdkVersion = 23
        compileSdkVersion = 32
        targetSdkVersion = 32
        ndkVersion = "20.1.5948944"
        googlePlayServicesAuthVersion = "16.0.1"
        googlePlayServicesLocationVersion = "17.0.0"
        supportLibVersion = "28.0.0"
        appCompatVersion = "1.0.2"  // <-- IMPORTANT:  For new AndroidX compatibility.
        androidXCore = "1.0.2"
        appCompatVersion = "1.1.0"
        googlePlayServicesVersion = "+"
        firebaseMessagingVersion = "21.1.0"
    }
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.1.0")
        classpath 'com.google.gms:google-services:4.3.2'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
       maven {
            // Required for react-native-background-geolocation
            url("${project(':react-native-background-geolocation').projectDir}/libs")
        }
        maven {
            // Required for react-native-background-fetch
            url("${project(':react-native-background-fetch').projectDir}/libs")
        }
        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
    }
}

android/app/build.gradle

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. If none specified and
 *   // "index.android.js" exists, it will be used. Otherwise "index.js" is
 *   // default. Can be overridden with ENTRY_FILE environment variable.
 *   entryFile: "index.android.js",
 *
 *   // https://reactnative.dev/docs/performance#enable-the-ram-format
 *   bundleCommand: "ram-bundle",
 *
 *   // 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,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // 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 = [
    enableHermes: false,  // clean and rebuild if changing
]

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

Project background_geolocation = project(':react-native-background-geolocation')
apply from: "${background_geolocation.projectDir}/app.gradle"

def useIntlJsc = false

/**
 * 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

/**
 * The preferred build flavor of JavaScriptCore.
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US.  Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc:+'

/**
 * Whether to enable the Hermes VM.
 *
 * This should be set on project.ext.react and mirrored here.  If it is not set
 * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
 * and the benefits of using Hermes will therefore be sharply reduced.
 */
def enableHermes = project.ext.react.get("enableHermes", false);

android {
    ndkVersion rootProject.ext.ndkVersion

    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "*****"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
        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
            }
        }
    }
    flavorDimensions "env"
    productFlavors {
        dev {
            dimension "env"
            applicationId "com.***.app.dev"
            buildConfigField "String", "ENV", "\"dev\""
        }
        prd {
            dimension "env"
            applicationId "com.****.app.dev"
            buildConfigField "String", "ENV", "\"prd\""
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android..
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            // Add following proguardFiles (leave existing one above untouched)
            // proguardFiles "${background_geolocation.projectDir}/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:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        defaultConfig.versionCode * 1000 + versionCodes.get(abi)
            }

        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

dependencies {
    implementation project(':react-native-android-open-settings')
    implementation project(':react-native-push-notification')
    implementation project(':react-native-device-info')
    implementation project(':react-native-gesture-handler')
    // implementation project(':react-native-firebase')
    // implementation project(':@react-native-community_netinfo')
    implementation fileTree(dir: "libs", include: ["*.jar"])
        //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules

    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
      exclude group:'com.facebook.fbjni'
    }
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }
    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    implementation 'com.facebook.android:facebook-android-sdk:13.0.0'
    implementation 'com.android.support:support-annotations:28.0.0'
    implementation project(':react-native-community-netinfo')
    implementation "com.google.firebase:firebase-messaging:21.1.0"
    implementation'com.facebook.soloader:soloader:0.9.0+'
    implementation project(':react-native-linear-gradient')
    implementation ("androidx.appcompat:appcompat:1.3.1") {
        version {
            strictly '1.3.1'
        }
}

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }

    if (useIntlJsc) {
        implementation 'org.webkit:android-jsc-intl:+'
    } else {
        implementation 'org.webkit:android-jsc:+'
    }
}

// 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 from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
mikehardy commented 2 years ago

That looks like manual linking instead of auto linking in lots of modules I maintain (firebase, device info, fbsdk) with apologies, I can't spend the time digging into that. It's probably something about Gradle and java and kotlin versions not being compatible, with some transitive dependency causing the issue. The far sighted solution is to update to current versions of the software in use and use auto linking. Everything in current versions should be working but with versions as old as you've got, manually linked, entropy will get you like this

christocracy commented 2 years ago

That looks like manual linking

@mikehardy is absolutely correct. You should not see any references to 3rd party dependencies in app/build.gradle

There is no quick fix here for you.

I would re-generate a fresh new RN app if I were you. Add current version of all dependencies. Copy your RN JavaScript/Typescript into the freshly generated app. It’s a good day’s work.

mikehardy commented 2 years ago

This will give you a skeleton with firebase at least, the other modules are easy in my opinion: https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh

christocracy commented 2 years ago

Also, look at your ext vars. You have a duplicate.

appCompatVersion = "1.0.2" // <-- IMPORTANT: For new AndroidX compatibility. androidXCore = "1.0.2" appCompatVersion = "1.1.0"

RuzenDev commented 2 years ago

@mikehardy @christocracy

Thank you very much for your co-operation.

We did a little digging and found out that

googlePlayServicesVersion = "+"

was the problem.

We changed that to googlePlayServicesVersion = "16+" and miraculously it worked!

christocracy commented 2 years ago

You’re dragging around a load of tech debt.

you should still migrate yourself to a fresh new app.