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

ClassCastException: org.slf4j.helpers.SubstituteLogger cannot be cast to ch.qos.logback.classic.Logger #1466

Open
Ronnnn opened this issue Nov 26, 2024 · 16 comments
Labels

Comments

@Ronnnn
Copy link

Ronnnn commented Nov 26, 2024

Your Environment

  • Plugin version: 4.17.4
  • Platform: Android
  • OS version: tested on android 10 & 14
  • Device manufacturer / model: Huawei mate 20 pro + Google pixel 6 pro
  • Cordova version: 12.0.0 ([email protected])
  • Cordova platform version: Installed platforms: android 13.0.0
  • Java JDK: installed 17.0.13
  • Android SDK: installed true
  • Android target: installed android-34
  • Gradle: installed /opt/android-sdk/gradle-8.7/bin/gradle

Expected Behavior

Not crashing during startup.

Actual Behavior

I'm having an hardtime figuring out this error:

  11-23 20:32:07.361  9700 10034 E AndroidRuntime: Process: com.myapp.app, PID: 9700
  11-23 20:32:07.361  9700 10034 E AndroidRuntime: java.lang.ClassCastException: org.slf4j.helpers.SubstituteLogger cannot be cast to ch.qos.logback.classic.Logger
  11-23 20:32:07.361  9700 10034 E AndroidRuntime:        at com.transistorsoft.locationmanager.logger.TSLog.a(Unknown Source:6)
  11-23 20:32:07.361  9700 10034 E AndroidRuntime:        at com.transistorsoft.locationmanager.logger.TSLog.getDatabaseAppender(Unknown Source:0)
  11-23 20:32:07.361  9700 10034 E AndroidRuntime:        at com.transistorsoft.locationmanager.logger.TSLog.d(Unknown Source:0)
  11-23 20:32:07.361  9700 10034 E AndroidRuntime:        at com.transistorsoft.locationmanager.logger.TSLog.$r8$lambda$uok2llHWDuVRXD-tozdjiMXQDaM(Unknown Source:0)
  11-23 20:32:07.361  9700 10034 E AndroidRuntime:        at com.transistorsoft.locationmanager.logger.TSLog$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)
  11-23 20:32:07.361  9700 10034 E AndroidRuntime:        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  11-23 20:32:07.361  9700 10034 E AndroidRuntime:        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
  11-23 20:32:07.361  9700 10034 E AndroidRuntime:        at java.lang.Thread.run(Thread.java:1012)

Steps to Reproduce

  1. Open the app
  2. Start background geolocation
  3. Track a dozen locations
  4. stop background geolocation
  5. Force-stop the app
  6. Try to start the app now

Context

The error isn't always thrown. The first time the app is installed everything works perfectly. I can even start background geolocation tracking. But if I force-close the app while background geolocation is off, and then try to restart the app, it crashes. I've tested this on Android 14 (pixel 6 pro) and Android 10 (mate 20 pro).

But the weird thing is the dependencies seem okay, please see attached gradle deps. I've even used jadx-gui to demux the resulting apk and check for the ch.qos.logback.classic.Logger package. And it is indeed present. Also the build.gradle (attached) looks good and does not contain any other slf4j or logback dependencies.

One of the things I noticed was that in platforms\android\app\libs\com\transistorsoft there are 3 folders:

  • tsbackgroundfetch (version 1.0.2)
  • tslocationmanager-v21 (version 3.6.3)
  • tslocationmanager (version 3.6.3)

I was expecting to only see 2 (tsbackgroundfetch+ tslocationmanager-v21) but this might be normal?

I make my android builds inside a docker image. I can completely rebuild this image including all npm/bower/gradle/cordova dependencies/caches and still then the apk has this error in it. I've got no clue anymore what to do. But I must be overlooking something stupid here. So I was hoping you could shed some light on this. Any idea is welcome. I really appreciate it if you could help me on this.

Debug logs

deps.txt
slf4j
logback

Possible duplicate of (which I read but couldn't help me fix my problem)
#1401

@christocracy
Copy link
Member

I was expecting to only see 2 (tsbackgroundfetch+ tslocationmanager-v21) but this might be normal?

yes, it’s normal.

execute the following. Save the output to a file and post here:

$ cd platforms/android
$ ./gradlew app:dependencies 

@Ronnnn
Copy link
Author

Ronnnn commented Nov 26, 2024

Thank you for the fast response. I included the dependencies in the bugreport (above the images):

deps.txt

And my gradle dependencies are:



dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')
    implementation "androidx.appcompat:appcompat:${cordovaConfig.ANDROIDX_APP_COMPAT_VERSION}"
    implementation "androidx.core:core-splashscreen:${cordovaConfig.ANDROIDX_CORE_SPLASHSCREEN_VERSION}"

    if (cordovaConfig.IS_GRADLE_PLUGIN_KOTLIN_ENABLED) {
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${cordovaConfig.KOTLIN_VERSION}"
    }

    // SUB-PROJECT DEPENDENCIES START
    implementation(project(path: ":CordovaLib"))
    implementation "androidx.exifinterface:exifinterface:1.3.4"
    implementation "androidx.lifecycle:lifecycle-runtime:2.4.+"
    implementation "androidx.lifecycle:lifecycle-extensions:2.2.+"
    implementation "androidx.webkit:webkit:1.4.0"
    implementation "com.google.android.gms:play-services-location:16.+"
    implementation "androidx.legacy:legacy-support-v4:1.0.0"
    implementation "androidx.appcompat:appcompat:1.3.1"
    implementation "com.squareup.okhttp3:okhttp:3.12.+"
    implementation "org.greenrobot:eventbus:3.3.1"
    implementation "io.github.nishkarsh:android-permissions:2.1.6"
    implementation "org.slf4j:slf4j-api:2.0.7"
    implementation "com.github.tony19:logback-android:3.0.0"
    // SUB-PROJECT DEPENDENCIES END
}

@christocracy
Copy link
Member

there's nothing obviously incorrect about your dependencies. I have no idea what causes this.

Can you create for me a simple Hello World app which reproduces this?

@Ronnnn
Copy link
Author

Ronnnn commented Nov 27, 2024

Building a Hello World app will take me a lot of time. Maybe another approach first? Because today I found out that when I replace the dependencies with older versions, then the app works again!

implementation "org.slf4j:slf4j-api:2.0.7"
implementation "com.github.tony19:logback-android:3.0.0"

with:

implementation "org.slf4j:slf4j-api:1.7.25"
implementation "com.github.tony19:logback-android:2.0.0"

So the library is there but the versions are wrong. My app is expecting the older version. Does this mean the wrong / older version of tslocationmanager.aar was loaded? It's hard to explain bacause I have a docker image which starts empty each time. My package.json (and -lock) both point to the 4.17.4 version. Is there a way I can test versions when the app is running?

In my project directory /src/platforms/android/app/libs/com/transistorsoft/tslocationmanager/ only 3.6.3 exists, and the tslocationmanager hashes are and match version 3.6.3 which is provided by 4.17.4:
tslocationmanager-3.6.3.aar.sha1 5941e344c5f1805782c9ab2b3d8d73a4ab248e4
tslocationmanager-v21-3.6.3.aar.sha1 b1ff74273787634c743e423601d64f165fcf70ec

@christocracy
Copy link
Member

christocracy commented Nov 27, 2024

Does this mean the wrong / older version of tslocationmanager.aar was loaded?

The reason that there are two versions of tslocationmanager is that play-services v21 introduced a breaking change.

  • tslocationmanager-3.6.3 is compiled against play-services v20.
  • tslocationmanager-v21 is compiled against play-services > v21+

Both versions of the library are compiled with the latest version of logback-android / slf4j-api.

These two different versions have nothing to do with the logger (logback-android / slf4j).

@christocracy
Copy link
Member

I test the Cordova demo app daily. I have never experienced this problem.

@christocracy
Copy link
Member

$ cordova platform
Installed platforms:
  android 13.0.0
  ios 7.1.1

$ cordova -v
12.0.0 ([email protected])

@Ronnnn
Copy link
Author

Ronnnn commented Nov 27, 2024

$ cordova platform
Installed platforms:
  android 13.0.0
Available platforms:
  browser
  electron

$ cordova -v
12.0.0 ([email protected])

@Ronnnn
Copy link
Author

Ronnnn commented Nov 27, 2024

Does this mean the wrong / older version of tslocationmanager.aar was loaded?

The reason that there are two versions of tslocationmanager is that play-services v21 introduced a breaking change.

  • tslocationmanager-3.6.3 is compiled against play-services v20.
  • tslocationmanager-v21 is compiled against play-services > v21+

Both versions of the library are compiled with the latest version of logback-android / slf4j-api.

These two different versions have nothing to do with the logger (logback-android / slf4j).

So the problem must be then that my app is loading an older version of the tslocationmanager which was compiled against the older versions of slf4j/logback. I can disssamble the resulting .apk and check which version of tslocationmanager had been packed inside the apk?

@GrassiAlessandro95
Copy link

I'm facing the same issue, serching on internet and asking to AI it seems that there is an incompatibility between slf4j and logback-android.

Slf4j 2.x seems to be not compatible to logback 3.x that instead supports Slf4j 1.x.

I'm currently trying this workaround then post here if this is the breakchange or not.

@Ronnnn
Copy link
Author

Ronnnn commented Dec 6, 2024

I'm facing the same issue, serching on internet and asking to AI it seems that there is an incompatibility between slf4j and logback-android.

Slf4j 2.x seems to be not compatible to logback 3.x that instead supports Slf4j 1.x.

I'm currently trying this workaround then post here if this is the breakchange or not.

Chances are you are facing a different (but comparable) issue, and that is this one:
#1401

You should read and check everything that is asked there. Also checking your gadle dependencies first. There exists a good blog post about this problem to understand what is happening:
https://signoz.io/guides/classcastexception-org-slf4j-impl-log4jloggeradapter-cannot-be-cast-to-ch-qos-logback-classic-logger/

I fixed my problem by automatically downgrading the slf4j versions in my pipeline.

@GrassiAlessandro95
Copy link

Yes sorry, next time i will pay more attention to the older threads.
Thanks for the reply and to agree that there is a problem with the library!

@Ronnnn
Copy link
Author

Ronnnn commented Dec 6, 2024

Yes sorry, next time i will pay more attention to the older threads. Thanks for the reply and to agree that there is a problem with the library!

I don't think there is a problem with the library. It's almost certainly a problem with your and mine build environment.

@GrassiAlessandro95
Copy link

This is really strange, cause i'm working on a production app base (branched that new in a test environment that is the same of production in term of setting, also the computer where i make the build is the same).

we've just upgraded the TargetSDK to 34 and consequently the cordova-background-geolocation-lt, then this error started to show up.

@christocracy
Copy link
Member

It’s always Cordova that has this problem. React Native, Flutter and Capacitor do not have this issue.

Copy link

github-actions bot commented Jan 6, 2025

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants