简体   繁体   English

任务 ':app:compileDebugJavaWithJavac' 的 Android 执行失败。 - 反应原生

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

I am working on a react native application.我正在开发一个反应本机应用程序。 when I try to build the applications using react-native run-android the build fails.当我尝试使用react-native run-android构建应用程序时,构建失败。 Here is the output of the error that occurs.这是发生的错误的输出。

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)

The application was on a old version of react native (0.48.x) I have updated it to 0.59.10.该应用程序位于旧版本的 react native (0.48.x) 上,我已将其更新到 0.59.10。

What I have done so far:到目前为止我做了什么:

  1. used jetifier to resolve issues with the plugins.使用 jetifier 解决插件问题。
  2. checked that the build tools version matches the compile sdk version检查构建工具版本是否与编译 sdk 版本匹配
  3. checked if the emulator is running.检查模拟器是否正在运行。

Hence I have tried everything I could to resolve this but had no luck.因此,我已尽我所能解决此问题,但没有运气。 Please do guide me on how to resolve this issue.请指导我如何解决此问题。 Looking forward to your answers.期待您的回答。

make sure you have followed all the necessary steps from the upgrade helper https://react-native-community.github.io/upgrade-helper/?from=0.48.0&to=0.59.10确保您已遵循升级助手https://react-native-community.github.io/upgrade-helper/?from=0.48.0&to=0.59.10 的所有必要步骤

also i would suggest you to upgrade to v0.60+ because there are breaking changes after v0.59.10.我还建议您升级到 v0.60+,因为 v0.59.10 之后有重大变化。

having said that话说回来

before you run the app make sure your gradle is clean run the following command to clean your gradle cd android && ./gradle clean then later you can navigate back to your app folder cd .. and try and run again react-native run-android在你运行应用程序之前确保你的 gradle 是干净的运行以下命令来清理你的 gradle cd android && ./gradle clean然后你可以导航回你的应用程序文件夹cd ..并再次尝试运行react-native run-android

Looks like your packages not working stable with Android side.看起来您的软件包在 Android 端不稳定。 It's better be update all packages and react native version to their last stable versions.最好更新所有软件包并将本机版本反应为它们的最后一个稳定版本。

If you face with too much error while update, you can create fresh new react native project (with same package name with your current project), install all packages (and their dependencies) and copy your current project's source code to your new project.如果您在更新时遇到太多错误,您可以创建全新的 React Native 项目(与当前项目具有相同的包名),安装所有包(及其依赖项)并将当前项目的源代码复制到新项目中。

After hours of searching and bursting my head against wall I figured out that Android in React Native does not allow similar packages to reside in the project.经过数小时的搜索和头撞墙,我发现 React Native 中的 Android 不允许类似的包驻留在项目中。

In my case I had react-native-cookies and @react-native-cookies/cookies packages that add similar code to the Kotlin file upon build.就我而言,我有react-native-cookies@react-native-cookies/cookies包,它们在构建时向 Kotlin 文件添加了类似的代码。 This causes issue of similar imports in java JDK.这会导致 java JDK 中出现类似导入的问题。

I removed one and it worked like a charm.我删除了一个,它就像一个魅力。

Happy coding!快乐编码!

SOLVED at the same issue:在同一问题上解决:

My solution was at /android/build.gradle file.我的解决方案位于 /android/build.gradle 文件中。 Somehow, the buildscript versions were wrong.不知何故,buildscript 版本是错误的。

Follow the exact same step of RN documentation and make a totally new & clean project.遵循与 RN 文档完全相同的步骤,创建一个全新且干净的项目。 And compate the /android/build.gradle file > buildscript & dependencies part.并比较 /android/build.gradle 文件 > buildscript & dependencies 部分。 There should be some version differences.应该有一些版本差异。 It matters by your own local env settings.这取决于您自己的本地环境设置。

After changing buildToolsVersion, ndkVersion, classpath, it worked fine again!!更改 buildToolsVersion、ndkVersion、classpath 后,它又可以正常工作了!!

also, remove duplicated libraries, as @Nimantha said.另外,正如@Nimantha 所说,删除重复的库。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 任务&#39;:app:compileDebugJavaWithJavac&#39;的执行失败。 适用于Android的React Native应用程序 - Execution failed for task ':app:compileDebugJavaWithJavac'. React Native application for Android 任务&#39;:app:compileDebugJavaWithJavac&#39;的执行失败反应本机 - Execution failed for task ':app:compileDebugJavaWithJavac' react native React Native-任务&#39;:app:compileDebugJavaWithJavac&#39;的执行失败 - React Native - Execution failed for task ':app:compileDebugJavaWithJavac' 任务“:app:compileDebugJavaWithJavac”执行失败。 在运行 React Native 项目时 - Execution failed for task ':app:compileDebugJavaWithJavac'. while running React Native Project React-native 问题 - 任务 ':app:compileDebugJavaWithJavac' 执行失败 - React-native problem - Execution failed for task ':app:compileDebugJavaWithJavac' React Native Android 开发 - Windows Webstorm 上的任务 &#39;:app:compileDebugJavaWithJavac&#39; 执行失败 - React Native Android Development - Execution failed for task ':app:compileDebugJavaWithJavac' on Windows Webstorm Android Studio-任务&#39;:app:compileDebugJavaWithJavac&#39;的执行失败 - Android Studio - Execution failed for task ':app:compileDebugJavaWithJavac' 任务执行失败:app:compileDebugJavaWithJavac in Android Studio 2 - Execution Failed for task :app:compileDebugJavaWithJavac in Android Studio 2 Android Studio 中任务 :app:compileDebugJavaWithJavac 的执行失败 - Execution Failed for task :app:compileDebugJavaWithJavac in Android Studio android - 任务 &#39;:app:compileDebugJavaWithJavac&#39; 执行失败 - android - Execution failed for task ':app:compileDebugJavaWithJavac'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM