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-wrapper
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。
uj5u.com熱心網友回復:
我面臨同樣的問題,即所有 Java 包都已安裝或完美同步,但 kotlin 包未同步,它會引發 kotlin 編譯錯誤。
我按照This在 Android Studio 上安裝 kotlin 包。
Android Studio → Preferences... →Plugins → Browse Repository → 在搜索框中輸入“Kotlin” → 安裝
之后,您需要從中洗掉該專案的快取
檔案 -> 使快取無效 -> 無效并重新啟動。
之后,當您的專案重新打開并成功同步時,請從Build -> Clean Project.
之后,kotlin 的所有包都安裝完美。
uj5u.com熱心網友回復:
找到了解決方案,但不知道為什么會起作用
我使用以下命令開始構建
npm start
和
npm run android
代替
npx react-native start
和
npx react-native run-android
后者由官方檔案建議
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/509881.html
上一篇:java.lang.NoClassDefFoundError:com/fasterxml/jackson/databind/ser/FilterProvider
下一篇:如何在2022年使用WSL的Windows上的intellij中使用gradle和Kotlin設定docker-composespringbootwebserver/mysql專案并進行熱多載?
