React Native无法构建APK文件

时间:2019-07-06 08:42:25

标签: react-native gradle android-emulator command-prompt

根据此http://facebook.github.io/react-native/docs/getting-started文档,我已经成功构建了本地应用文件夹

但是,当我在cmd中运行react-native run-android时,正在向我显示--

info Starting JS server...
info Installing the app...
> Task :app:mergeDebugResources FAILED
9 actionable tasks: 8 executed, 1 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Specified AAPT2 executable does not exist: C:\Users\DE\.gradle\caches\transforms-2\files-2.1\e3571e1615ccf7c32524cbf1a8ed0eb8\aapt2-3.4.1-5326820-windows\aapt2.exe

* 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 55s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Specified AAPT2 executable does not exist: C:\Users\DE\.gradle\caches\transforms-2\files-2.1\e3571e1615ccf7c32524cbf1a8ed0eb8\aapt2-3.4.1-5326820-windows\aapt2.exe

* 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 55s

    at checkExecSyncError (child_process.js:621:11)
    at execFileSync (child_process.js:639:15)
    at runOnAllDevices (C:\Users\DE\AwesomeApp\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:75:39)
    at buildAndRun (C:\Users\DE\AwesomeApp\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\index.js:137:41)
    at C:\Users\DE\AwesomeApp\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\index.js:103:12
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
    at async Command.handleAction (C:\Users\DE\AwesomeApp\node_modules\@react-native-community\cli\build\cliEntry.js:160:7)```

2 个答案:

答案 0 :(得分:0)

我有同样的问题。我尝试使用cmd转到应用程序目录的第二个目录,并运行“ react-native start”。这解决了我的问题。

答案 1 :(得分:0)

我已通过删除.gradle文件夹的缓存解决了此问题。路径为C:\Users\DE\.gradle\caches。之后,应用程序开始构建。