‘Execution failed for task ‘:tasks’. Could not create task ‘:react-native-bg-thread:compileDebugJavaWithJavac’.
In React Native, when setting up the simulator and its environment after installing a or every necessary dependency, the simulator might boot but would not run your application.
It then returns an en error:
'Execution failed for task ':tasks'.
> Could not create task ':react-native-bg-thread:compileDebugJavaWithJavac'.
> In order to compile Java 9+ source, please set compileSdkVersion to 30 or above'
to fix this, go to your project folder:
cd [projectname]
then
cd android
then find and open build.gradle.
Inside that file, add:
subprojects { subproject ->
afterEvaluate{
if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
}
in your buildscript, just below the ext code block.
then rerun:
react-native run-android
or whatever code that starts your simulator.
I hope this helps. Good luck ☘️.