info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 936 file(s) to forward-jetify. Using 12 workers...
info JS server already running.
info Installing the app...
> Task :react-native-gradle-plugin:compileKotlin FAILED
'compileJava' task (current target is 1.8) and 'compileKotlin' task (current target is 11) jvm target compatibility should be set to the same Java version.
1 actionable task: 1 executed
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-gradle-plugin:compileKotlin'.
> Failed to query the value of task ':react-native-gradle-plugin:compileKotlin' property 'compilerRunner$kotlin_gradle_plugin'.
> Kotlin could not find the required JDK tools in the Java installation. Make sure Kotlin compilation is running on a JDK, not JRE.
* 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 4s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-gradle-plugin:compileKotlin'.
> Failed to query the value of task ':react-native-gradle-plugin:compileKotlin' property 'compilerRunner$kotlin_gradle_plugin'.
> Kotlin could not find the required JDK tools in the Java installation. Make sure Kotlin compilation is running on a JDK, not JRE.
* 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 4s
at makeError (C:\Users\dhanp\React native projects\test3\ProjectName\node_modules\execa\index.js:174:9)
at C:\Users\dhanp\React native projects\test3\ProjectName\node_modules\execa\index.js:278:16
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async runOnAllDevices (C:\Users\dhanp\React native projects\test3\ProjectName\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
at async Command.handleAction (C:\Users\dhanp\React native projects\test3\ProjectName\node_modules\@react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details
我见过涉及更改 classpath() 和分发 URL 的解决方案,但我已经完成了。
来自我的 build.gradle 文件:
dependencies {
classpath("com.android.tools.build:gradle:7.2.1")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("de.undercouch:gradle-download-task:4.1.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
来自 gradle 包装器
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
这些都不能修复错误,此外,我注意到运行 gradlew clean 也会引发相同的错误
> Task :react-native-gradle-plugin:compileKotlin FAILED
'compileJava' task (current target is 1.8) and 'compileKotlin' task (current target is 11) jvm target compatibility should be set to the same Java version.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-gradle-plugin:compileKotlin'.
> Failed to query the value of task ':react-native-gradle-plugin:compileKotlin' property 'compilerRunner$kotlin_gradle_plugin'.
> Kotlin could not find the required JDK tools in the Java installation. Make sure Kotlin compilation is running on a JDK, not JRE.
* 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 4s
1 actionable task: 1 executed
我还尝试将以下代码添加到 build.gradle 文件中
android {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
}
请帮我解决这个问题,我以前使用过 EXPO CLI,一切都运行良好,所有这一切都是为了学习 React-native CLI。
我遇到了同样的问题,为了解决这个问题,我在 gradle-wrapper.properties 文件中进行了更改
之前:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
之后:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
我更改了gradle版本并解决了它。 参考
//before
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
//after
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
我面临同样的问题,所有 Java 包都已安装或完美同步,但 kotlin 包未同步,它会引发 kotlin 编译错误。
我按照This在Android Studio上安装kotlin包。
Android Studio → 首选项… → 插件 → 浏览存储库 → 在搜索框中输入“Kotlin” → 安装
之后,您需要从
中删除该项目的缓存文件 -> 使缓存无效 -> 无效并重新启动。
之后,当您的项目重新打开并成功同步时,请从
Build -> Clean Project
中清除您的项目。
之后kotlin的所有包都完美安装了。
我刚刚安装了 jdk11 然后运行 cd ./android/ && ./gradlew clean 这对我有用
我们必须注意 Gradle 与 java 版本的兼容性版本,适用于 React-Native 或 Flutter 框架。您可以在上述网址中查看兼容版本 https://docs.gradle.org/current/userguide/compatibility.html
我在使用expo时遇到了同样的问题
我删除了
eas.json
文件,因为 eas build
创建了一个新的 eas.json
文件
它对我有用。
我遇到了同样的问题,为了解决这个问题我做了:
package.json
中,我在版本前添加了 ^
,然后是 yarn install
。 (更新react native
版本0.68.2
为^0.68.2
)当我遇到同样的问题时,这对我有用:
rm -rf ./node_modules
yarn
npm run android
删除node_modules并重新安装。我认为这个问题也可能是因为我使用 Android Studio 安装 Gradle。 另请检查您是否安装了多个版本的 Java JDK,请检查以确保 React Native 使用的是哪一个版本。
找到了解决方案,但不确定为什么它有效
我使用以下命令来启动构建
npm start
现在打开另一个终端并执行以下命令
npm run android
而不是
npx react-native start
和
npx react-native run-android
官方文档建议后者