簡體   English   中英

任務 ':app:compileDebugJavaWithJavac' 的 Android 執行失敗。 - 反應原生

[英]Android Execution failed for task ':app:compileDebugJavaWithJavac'. - React Native

我正在開發一個反應本機應用程序。 當我嘗試使用react-native run-android構建應用程序時,構建失敗。 這是發生的錯誤的輸出。

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* 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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 8s
253 actionable tasks: 5 executed, 248 up-to-date
error Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: ./gradlew app:installDebug
debug Error: Command failed: ./gradlew app:installDebug
    at checkExecSyncError (child_process.js:607:13)
    at execFileSync (child_process.js:627:13)
    at runOnAllDevices (/Users/FaisalHussain/mobile/node_modules/@react-native-community/cli/build/commands/runAndroid/runOnAllDevices.js:58:39)
    at buildAndRun (/Users/FaisalHussain/mobile/node_modules/@react-native-community/cli/build/commands/runAndroid/runAndroid.js:142:41)
    at then.result (/Users/FaisalHussain/mobile/node_modules/@react-native-community/cli/build/commands/runAndroid/runAndroid.js:104:12)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)

該應用程序位於舊版本的 react native (0.48.x) 上,我已將其更新到 0.59.10。

到目前為止我做了什么:

  1. 使用 jetifier 解決插件問題。
  2. 檢查構建工具版本是否與編譯 sdk 版本匹配
  3. 檢查模擬器是否正在運行。

因此,我已盡我所能解決此問題,但沒有運氣。 請指導我如何解決此問題。 期待您的回答。

確保您已遵循升級助手https://react-native-community.github.io/upgrade-helper/?from=0.48.0&to=0.59.10 的所有必要步驟

我還建議您升級到 v0.60+,因為 v0.59.10 之后有重大變化。

話說回來

在你運行應用程序之前確保你的 gradle 是干凈的運行以下命令來清理你的 gradle cd android && ./gradle clean然后你可以導航回你的應用程序文件夾cd ..並再次嘗試運行react-native run-android

看起來您的軟件包在 Android 端不穩定。 最好更新所有軟件包並將本機版本反應為它們的最后一個穩定版本。

如果您在更新時遇到太多錯誤,您可以創建全新的 React Native 項目(與當前項目具有相同的包名),安裝所有包(及其依賴項)並將當前項目的源代碼復制到新項目中。

經過數小時的搜索和頭撞牆,我發現 React Native 中的 Android 不允許類似的包駐留在項目中。

就我而言,我有react-native-cookies@react-native-cookies/cookies包,它們在構建時向 Kotlin 文件添加了類似的代碼。 這會導致 java JDK 中出現類似導入的問題。

我刪除了一個,它就像一個魅力。

快樂編碼!

在同一問題上解決:

我的解決方案位於 /android/build.gradle 文件中。 不知何故,buildscript 版本是錯誤的。

遵循與 RN 文檔完全相同的步驟,創建一個全新且干凈的項目。 並比較 /android/build.gradle 文件 > buildscript & dependencies 部分。 應該有一些版本差異。 這取決於您自己的本地環境設置。

更改 buildToolsVersion、ndkVersion、classpath 后,它又可以正常工作了!!

另外,正如@Nimantha 所說,刪除重復的庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM