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.54k stars 424 forks source link

App crash with error: org.slf4j.helpers.NOPLogger cannot be cast to ch.qos.logback.classic.Logger #1983

Closed thongquach closed 1 month ago

thongquach commented 1 month ago

I've found a similar issue but the fix didn't work.

Your Environment

Expected Behavior

The app should start normally

Actual Behavior

The app crashed!

Steps to Reproduce

  1. Simply build and open the app

Context

As part of upgrading react-native version, I need to upgrade some libs including react-native-background-geolocation

Debug logs

``` 2024-04-01 17:38:53.797 8327-8427 TSBackgroundFetch com.yojee.driverapp.v3.dev D [RNBackgroundFetch initialize] 2024-04-01 17:38:53.799 8327-8327 TSBackgroundFetch com.yojee.driverapp.v3.dev D ☯️ onCreate 2024-04-01 17:38:53.800 8327-8327 TSBackgroundFetch com.yojee.driverapp.v3.dev D ☯️ onStart 2024-04-01 17:38:53.800 8327-8327 TSBackgroundFetch com.yojee.driverapp.v3.dev D ☯️ onResume 2024-04-01 17:38:53.816 8327-8427 HMSSDK_HMS...ageManager com.yojee.driverapp.v3.dev E resolveInfoList is null or empty 2024-04-01 17:38:53.818 8327-8427 HMSSDK_HMS...ageManager com.yojee.driverapp.v3.dev E PackagePriorityInfo list is null 2024-04-01 17:38:53.819 8327-8427 HMSSDK_HMS...ageManager com.yojee.driverapp.v3.dev E Failed to find HMS apk 2024-04-01 17:38:53.822 8327-8427 HMSSDK_HMS...ageManager com.yojee.driverapp.v3.dev I Enter getHMSPackageNameForMultiService 2024-04-01 17:38:53.829 8327-8427 HMSSDK_HMS...ageManager com.yojee.driverapp.v3.dev E resolveInfoList is null or empty 2024-04-01 17:38:53.829 8327-8429 HMSSDK_HMS...ageManager com.yojee.driverapp.v3.dev I enter asyncOnceCheckMDMState 2024-04-01 17:38:53.832 8327-8427 HMSSDK_HMS...ageManager com.yojee.driverapp.v3.dev E PackagePriorityInfo list is null 2024-04-01 17:38:53.835 8327-8427 HMSSDK_HMS...ageManager com.yojee.driverapp.v3.dev E Failed to find HMS apk 2024-04-01 17:38:53.838 8327-8427 HMSSDK_Hua...rvicesUtil com.yojee.driverapp.v3.dev I hmsPackageName is com.huawei.hwid 2024-04-01 17:38:53.841 8327-8427 HMSSDK_HMS...ageManager com.yojee.driverapp.v3.dev E resolveInfoList is null or empty 2024-04-01 17:38:53.842 8327-8429 HMSSDK_HMS...ageManager com.yojee.driverapp.v3.dev I quit asyncOnceCheckMDMState 2024-04-01 17:38:53.844 8327-8427 HMSSDK_HMS...ageManager com.yojee.driverapp.v3.dev E PackagePriorityInfo list is null 2024-04-01 17:38:53.845 8327-8427 HMSSDK_HMS...ageManager com.yojee.driverapp.v3.dev E Failed to find HMS apk 2024-04-01 17:38:53.847 8327-8427 HMSSDK_Hua...rvicesUtil com.yojee.driverapp.v3.dev I HMS is not installed 2024-04-01 17:38:53.877 8327-8430 AndroidRuntime com.yojee.driverapp.v3.dev E FATAL EXCEPTION: pool-17-thread-1 Process: com.yojee.driverapp.v3.dev, PID: 8327 java.lang.ClassCastException: org.slf4j.helpers.NOPLogger cannot be cast to ch.qos.logback.classic.Logger at com.transistorsoft.locationmanager.logger.TSLog.a(Unknown Source:6) at com.transistorsoft.locationmanager.logger.TSLog.a(Unknown Source:0) at com.transistorsoft.locationmanager.logger.TSLog.$r8$lambda$3YB4RZFGV-hL2r0EClp1u86FGKM(Unknown Source:0) at com.transistorsoft.locationmanager.logger.TSLog$$ExternalSyntheticLambda1.run(Unknown Source:4) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012) 2024-04-01 17:38:53.885 8327-8427 RNFusedLocation com.yojee.driverapp.v3.dev I RNFusedLocation initialized ```

dependencies.txt

thongquach commented 1 month ago

Hi @christocracy, could you take a look when you have time? Thanks in advance.

christocracy commented 1 month ago

Show me your android/build.gradle

thongquach commented 1 month ago

Here, @christocracy

``` buildscript { ext { buildToolsVersion = "34.0.0" // https://github.com/mrousavy/react-native-vision-camera/issues/1708#issuecomment-1706973949 minSdkVersion = 26 compileSdkVersion = 34 targetSdkVersion = 34 kotlinVersion = "1.8.0" ndkVersion = "25.1.8937393" supportLibVersion = "29.0.0" // react-native-background-geolocation appCompatVersion = "1.4.2" // Or higher. Required for new AndroidX compatibility. googlePlayServicesLocationVersion = "21.2.0" // Or higher. // https://github.com/transistorsoft/react-native-background-geolocation/issues/1699#issuecomment-1576877814 slf4jVersion = "1.7.36" logbackVersion = "2.0.1" } repositories { google() mavenCentral() } dependencies { classpath("com.android.tools.build:gradle") classpath("com.facebook.react:react-native-gradle-plugin") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin") classpath 'com.google.gms:google-services:4.3.3' } } apply plugin: "com.facebook.react.rootproject" allprojects { repositories { maven { // Required for react-native-background-geolocation url("${project(':react-native-background-geolocation').projectDir}/libs") } maven { url 'https://developer.huawei.com/repo/' } maven { // Required for react-native-background-fetch url("${project(':react-native-background-fetch').projectDir}/libs") } } } ```
mendrixsebas commented 1 month ago

I'm also having this same issue. I can work around it by disabling flipper. Quickest way to this is by having this in react-native.config.js in the project root:

module.exports = {
    dependencies: {
        'react-native-flipper': {platforms: {android: null, ios: null}},
    },
};
christocracy commented 1 month ago

The solution is not to disable things, but to align their dependencies.

The solution is this:

📂 android/build.gradle:

buildscript {
    ext {
        .
        .
        .        
        slf4jVersion = "2.0.7"
        logbackVersion = "3.0.0"
    }
christocracy commented 1 month ago

Both my plug-in and Flipper use the same logging system. Up until recently, Flipper had been importing an older version of this dependency (logback-android), forcing me to follow suit. Since Flipper hardcodes their dependency versions (not very nice of them), they forced me to use an older version up until now.

So now it’s safe to use the latest versions, as mentioned above.

thongquach commented 1 month ago

Hi @christocracy , the solution worked beautifully. Nonetheless, I do not quite understand how it works since I'm not familiar with native Android. Could you elaborate more on why the versions are 2.0.7 and 3.0.0?

christocracy commented 1 month ago

I explained above why. This plug-in wants to include the latest version of the Logger dependency but historically, Flipper has imported the old version and I was forced to comply since Flipper doesn’t offer gradle ext vars to control the imported version, as I do (since I’m a thoughtful and well-behaved citizen).

now, it seems that Flipper has decided to update their Logger version to the latest version, so now we’re all forced to move to the latest version too.

none of this would be required if Flipper would use the same Gradle ext vars that I use.

I use the latest version of logback-android with all other versions of this plugin (Cordova, Capacitor and Flutter). It’s only here in React Native where Flipper forced me to downgrade to abide by the version they use, because everyone imports Flipper. They suck.