简体   繁体   中英

SLF4J is included in my brand new react native project and it is causing an error on app reboot

I have created a brand new react native project (v0.71.1) using npx react-native init BGTest.

The project was created as expected, it compiles just fine and runs on the device in debug mode with no errors. I have then installed the react-native-background-fetch package and configured a job to start the app on reboot of the device on Android.

Again, the project compiles and runs just fine with no errors when running it from Android studio or using the 'yarn android' command.

Now, when I reboot the device, it seems the app tries to restart, it picks up that it needs to execute the job that I configured, but then the app is killed. Just before it is killed, I see logs about SLF4J failing to load and I'm not sure why that is there - I cannot find any dependency on SLF4J anywhere in the application and what confuses me is that on the initial running and loading of the app on the device it does not have this error, only when the device is rebooted.

Here is the log:

SLF4J error log

How can I fix this error? I'm struggling to find similar issues about SLF4J in react native online and the fact that I cannot find any dependencies within the android application is also really confusing. Unless it is part of the JDKs that I'm using (I've tried compiling with JDK11.0.13 and OpenJDK 17) but the error has persisted with both.

Ok I have resolved this myself.

The fix was to add slf4j as a dependency in the app/build.gradle file of the android project - now the error has disappeared.

This is the line I added:

    implementation("org.slf4j:slf4j-log4j12:1.7.29")

Leaving this here in case it helps someone else with the same issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM