React Native - Gradle - Andriod -JAVA

So i have been working on a project that is an app to from react native to collect the data from an NPK sensor from bluetooth and store that data in the sqlite in the app i just eject the react native expo out since it cannot use bluetooth and sqlite but it seem likes there is a problem related to the version of java my gradle knows and the version of java i am currently using (not sure about the cause of the problem) but here is the error massages

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\User\Desktop\react_native\FirstWork\android\app\build.gradle' line: 175

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not open cp_dsl generic class cache for script 'C:\Users\User\Desktop\react_native\FirstWork\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' (C:\Users\User\.gradle\caches\8.3\scripts\eoxe7qyipog4lrxqwlgckzp03).
   > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 66

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 12s
info Run CLI with --verbose flag for more details.

i need help , if you know any info related to this problem or how to fix the problem so i can run the app on an android emulator please let me know.

You try to run a Gradle 8.3 build using Java 22, this is not supported.
See here for the compatibility information: Compatibility Matrix

1 Like

i checked in terminal and it said i have been using java 22 and gradle 8.8 so


is there a way to change the version of my gradle or installing a new java is faster?

  • is changing the java version to java 20 is better faster and easier?
  • how to update my gradle caches is it better faster and easier?


I am not sure if this is still the same problem but how do i solve it?

What gradle -v returns is absolutely irrelevant.
Usually you should not even have any Gradle version installed locally at all anyway.
Each project should have the 4 Gradle wrapper files included which defines and manages the Gradle version that is used.
The Gradle version is defined in gradle/wrapper/gradle-wrapper.properties by default

The error from your last message is something different. You try to use targetCompatibility which seems to not exist, probably because you do it on a project that does not apply any javaesque plugin. But it would anyway better to use JVM toolchains instead.

hey bro i have been encountering some new error again the build was succeed once which i dont know why but i tried changing the internet and turn off firewall


and if i do gradle --refresh-dependencies

PS C:\Users\User\Desktop\react_native\FirstWork> gradle --refresh-dependencies
Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details

FAILURE: Build failed with an exception.

* What went wrong:
java.io.UncheckedIOException: Could not move temporary workspace (C:\Users\User\Desktop\react_native\FirstWork\.gradle\8.8\dependencies-accessors\d7f838bb16dc243bdd05bfa8f75ef956f6209f3c-1b1b456e-42ec-47db-861b-526c78d8685d) to immutable location (C:\Users\User\Desktop\react_native\FirstWork\.gradle\8.8\dependencies-accessors\d7f838bb16dc243bdd05bfa8f75ef956f6209f3c)
> Could not move temporary workspace (C:\Users\User\Desktop\react_native\FirstWork\.gradle\8.8\dependencies-accessors\d7f838bb16dc243bdd05bfa8f75ef956f6209f3c-1b1b456e-42ec-47db-861b-526c78d8685d) to immutable location (C:\Users\User\Desktop\react_native\FirstWork\.gradle\8.8\dependencies-accessors\d7f838bb16dc243bdd05bfa8f75ef956f6209f3c)

this appear so what do i do?

The “was not found in any …” means you try to apply the com.android.application plugin without specifying a version and without otherwise bringing the plugin to the classpath.

The “Could not move temporary workspace” is

i dont clearly understand both of the error eventhough u had explain it to me, i mean i tried chaning the

plugins {
    id 'com.android.application' 
    id 'org.jetbrains.kotlin.android' version '1.9.0'
}

to

plugins {
    id 'com.android.application' version '8.5.0' apply false (try 8.0.0 and apply false alread)
    id 'org.jetbrains.kotlin.android' version '1.9.0'
}

to try indicating the version of the com.android.application but it still say that
“was not found in any …”
can you please check my build gradle in android level

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.0.0' // Use the appropriate version for your setup
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10' // Use the appropriate version for your setup
        classpath 'com.facebook.react:react-native-gradle-plugin'
    }
}

plugins {
    id 'com.android.application' version '8.5.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.9.0'
}

android {
    compileSdkVersion 31
    defaultConfig {
        applicationId 'com.anonymous.FirstWork'
        minSdkVersion 21
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"
    }
    // Java Toolchain Configuration
    java {
        toolchain {
            languageVersion = JavaLanguageVersion.of(22)
        }
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}
dependencies {
    implementation("com.facebook.react:react-android")
    // Other dependencies

    def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true";
    def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true";
    def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?: "") == "true";

    if (isGifEnabled) {
        implementation("com.facebook.fresco:animated-gif:${reactAndroidLibs.versions.fresco.get()}")
    }

    if (isWebpEnabled) {
        implementation("com.facebook.fresco:webpsupport:${reactAndroidLibs.versions.fresco.get()}")
        if (isWebpAnimatedEnabled) {
            implementation("com.facebook.fresco:animated-webp:${reactAndroidLibs.versions.fresco.get()}")
        }
    }

    implementation("com.facebook.react:flipper-integration")

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }
}

apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
applyNativeModulesAppBuildGradle(project)

what are the things wrong and why are they wrong?

If you change id 'com.android.application' to id 'com.android.application' version '8.5.0' apply false that is not particularly helpful as you then do no longer apply the plugin but just add it to the classpath.

what are the things wrong and why are they wrong?

Actually many things if you ask that way.
Here some of the points:

  • More a personal recommendation, but switch to Kotlin DSL, by now it is the default DSL, you immediately get type-safe build scripts, actually helpful error messages if you mess up the syntax, and amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio.
  • Having in the root build script both, classpath 'com.android.tools.build:gradle:8.0.0' and id 'com.android.application' version '8.5.0' apply false is bad. Both add the AGP to the classpath so if it were the same version it would be redundant, as they are different versions it even is an error that would fail if the resoultion would have worked
  • I guess applying org.jetbrains.kotlin.android in the build script you showed will fail as you do not apply the Android plugin (apply false)
  • Don’t put the java { ... } block inside the android { ... } block, it is a sibling and having it inside is just visual clutter and confusing
  • allprojects { ... } as well as any other way to do cross-project configuration like subprojects { ... }, project("...") { ... }, and so on are highly discouraged bad practice and work against more sophisticated Gradle features and optimzations, if you want to centralize build logic, better consider using Convention Plugins, for example in buildSrc or an included build, for example implemented as Precompiled script plugins.
  • Do not use legacy script plugins (the things you use using apply from) they have many quirks and problems and should be avoided

Regarding the error, I guess that you did not define google() as plugin repository in your settings script and thus it cannot resolve from the plugin id with version in the plugins { ... } block to the plugin. Either use the proper way, defining google() as plugin repository and using the plugins { ... } block, or if you prefer using the discouraged legacy way, remove the version from inside the plugins { ... } block and keep the classpath stuff.

1 Like

i am not sure that is there a way to change from using groovy to kotlin without a mess or not so i do prefer to stay with the groovy for now to fix the problem i can (if i would stuck to some problem in the future please tell me to change)

so i tried solving the error base on my understanding from your reply as

  • removing all the plugin stuff and remain the classpath stuff
  • using maven to properly define google
  • move the java() out
    *** but i dont understand what to do with allproject() things

buildscript {
repositories {
google() // For Gradle 4.0+
maven { url ‘https://maven.google.com’} // For Gradle < 4.0

but now i receive this error
(the error is too long i will put it in the google doc link)

the top of the error look like this
FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project ‘FirstWork’.

Could not resolve all dependencies for configuration ‘:classpath’.
Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.9.22/kotlin-gradle-plugin-1.9.22.pom
- https://maven.google.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.9.22/kotlin-gradle-plugin-1.9.22.pom
Required by:
project :
Could not find org.jetbrains.kotlin:kotlin-stdlib:1.9.22.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-stdlib/1.9.22/kotlin-stdlib-1.9.22.pom
- https://maven.google.com/org/jetbrains/kotlin/kotlin-stdlib/1.9.22/kotlin-stdlib-1.9.22.pom
Required by:
project : > project :gradle-plugin
Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.9.22/kotlin-gradle-plugin-1.9.22.pom

You now only have google() as repository (and a mirror of it where even your comment says to not use it as you are not on Gradle <4 where simply google() did not exist).
But org.jetbrains.kotlin:kotlin-gradle-plugin is not available in google(), but in mavenCentral().

but i dont understand what to do with allproject() things

Replace them by using convention plugins as documented in the links I provided. :slight_smile:

Adding the centralmaven() does solve the problem thanks a lot , anyway now there have been some problem with com.facebook stuff (i will figure out the allproject convention plugin with groovy later)

error Failed to install the app.
Command failed with exit code 1: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 
FAILURE: Build failed with an exception.
* Where: Build file 'C:\Users\User\Desktop\react_native\FirstWork\android\build.gradle' line: 44
* What went wrong: A problem occurred evaluating root project 'FirstWork'.
> Could not find method implementation() 
for arguments [com.facebook.react:react-android] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

i already add the facebook in the class path already but i dont know whats wrong here

dependencies {
        classpath 'com.android.tools.build:gradle:8.2.1' // Use the appropriate version for your setup
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10' // Use the appropriate version for your setup
        classpath 'com.facebook.react:react-native-gradle-plugin'
    }

Did I mention that you get “actually helpful error messages if you mess up the syntax” if you would use Kotlin DSL? :wink:

You try to add dependencies to the implementation configuration, but you do not apply any plugin that adds this configuration. So either you miss to apply a plugin, or you try to add dependencies in the wrong build script.

Hey, I am just facing this error

error Failed to install the app. Command failed with exit code 1: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 FAILURE: Build failed with an exception.

 * What went wrong: Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
 *  > Could not resolve all dependencies for configuration ':app:debugCompileClasspath'.
 *  > Could not find com.facebook.react:flipper-integration:. Required by: project :app
 
 *  * Try: > Run with --stacktrace option to get the stack trace. 
 * > Run with --info or --debug option to get more log output. 
 * > Run with --scan to get full insights. 
 * > Get more help at https://help.gradle.org. BUILD FAILED in 18s.
info Run CLI with --verbose flag for more details.

Sometime it successfully build ,but sometime this error pops up. i wonder why ?

Internet said to do something with specifying Flutter version but it have no compatibility doc so what version shall i use? or many people said flutter is bad?

And fixing javaWithJavac some people say to add local.properties toandroid and some say that it means the version is incompatible what do i do?

In the end , seems like my gradle is 8.2.1 and using java 22 is not good right?
if i change my gradle to 8.8 by./gradlew wrapper --gradle-version=8.8 would this BuildTools support version resolve? or the better way is to downgrade the Java 22 to 20 or 17 which people say best with andriod?

what is the best way to solve this " Command failed with exit code 1: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 FAILURE: Build failed with an exception. * What went wrong: Could not determine the dependencies of task ‘:react-native-sqlite-storage:bundleLibCompileToJarDebug’. > Could not create task ‘:react-native-sqlite-storage:compileDebugJavaWithJavac’. > In order to compile Java 9+ source, please set compileSdkVersion to 30 or above *"

more info that might useful
Kotlin does not yet support 22 JDK target, falling back to Kotlin JVM_21 JVM target
WARNING: The specified Android SDK Build Tools version (27.0.3) is ignored, as it is below the minimum supported version (34.0.0) for Android Gradle Plugin 8.2.1.
Android SDK Build Tools 34.0.0 will be used.
To suppress this warning, remove “buildToolsVersion ‘27.0.3’” from your build.gradle file, as each version of the Android
Gradle Plugin now has a default version of the build tools

update** i use --gradle-version=8.8 already but the dependencies of task ‘:react-native-sqlite-storage:bundleLibCompileToJarDebug’. error is not solve

In the end , seems like my gradle is 8.2.1 and using java 22 is not good right?

No, don’t confuse the Gradle version with the version of the Android Gradle Plugin.
Google just unluckily named their artifact “gradle” but the AGP version has nothing to do directly with the Gradle version.
Your previous errors and screenshots show, that you were using Gradle 8.8 already,
and that the version of the Android Gradle Plugin is 8.2.1.

if i change my gradle to 8.8 by./gradlew wrapper --gradle-version=8.8 would this BuildTools support version resolve?

No, as you are already using 8.8 unless you changed something.
Besides that it is unclear what error you talk about here.

or the better way is to downgrade the Java 22 to 20 or 17 which people say best with andriod?

I have no idea about Android development. If “people” know what they are saying, maybe you should listen. :man_shrugging:

what is the best way to solve this […} In order to compile Java 9+ source, please set compileSdkVersion to 30 or above

The error message seems to be quite explicit, why don’t you try what it suggests?

Besides that further down you quoted that your deifned 27.0.3 is ignored anyway and it recommends to remove it as anyway 34.0.0 will be used, which then should also solve this of course.