java react-native run-android 构建错误 ':app:generateDebugBuildConfig'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45222227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
react-native run-android Building Error ':app:generateDebugBuildConfig'
提问by Diego Barreto
I am having a problem to build a new project. I am using React-Native and Android Emulator (AVD) but when I use the command react-native run-android
I get the following message:
我在构建新项目时遇到问题。我正在使用 React-Native 和 Android Emulator (AVD),但是当我使用该命令时,react-native run-android
我收到以下消息:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:generateDebugBuildConfig'.
> java.io.IOException: Could not delete path 'C:\Users\diego\Desktop\Diego\albums\android\app\build\generated\source\buildConfig\debug\com'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2 mins 47.189 secs
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/android-setup.html
FAILURE:构建失败,出现异常。
* 什么地方出了错:
任务“:app:generateDebugBuildConfig”执行失败。
> java.io.IOException: 无法删除路径“C:\Users\diego\Desktop\Diego\albums\android\app\build\generated\source\buildConfig\debug\com”。
* 尝试:
使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。
构建失败
总时间:2 分 47.189 秒
无法在设备上安装该应用程序,请阅读上面的错误了解详情。确保您有一个正在运行的 Android 模拟器或已连接的设备并已设置您的 Android 开发环境:https: //facebook.github.io/react-native/docs/android-setup.html
Here's an image of the prompt: Image of the problem
这是提示的图像:问题的图像
How can I fix this?
我怎样才能解决这个问题?
-------------------------------------------------------------UPDATE-------------------------------------------------------
-------------------------------------------------- - - - - - -更新 - - - - - - - - - - - - - - - - - - - -----------------
I added the value C:\....\AppData\Local\Android\sdk\tools
to the variable Path
and I got build sucessful. Problem solved. Yay.
我将值添加C:\....\AppData\Local\Android\sdk\tools
到变量中,Path
并且构建成功。问题解决了。耶。
Thanks.
谢谢。
采纳答案by Bashirpour
@diego-barreto
@迭戈-巴雷托
Added the value C:\....\AppData\Local\Android\sdk\tools
to the variable Path
and I got build sucessful. Problem solved. Yay.
将值添加C:\....\AppData\Local\Android\sdk\tools
到变量中Path
,我构建成功。问题解决了。耶。
回答by KAMAL VERMA
cd android //Navigate into the android folder from the root directory
cd android //从根目录导航到android文件夹
gradlew clean // Run this
gradlew clean // 运行这个
回答by Rajesh Nasit
Create rn.sh
file in your root of React native project with following content
rn.sh
使用以下内容在 React Native 项目的根目录中创建文件
cd android/app/
rm -rf build
cd ..
cd ..
react-native run-android
Then run from terminal or cmd
然后从终端或 cmd 运行
./rn.sh
Recommendation
推荐
VSCode must be run as Admistrator or GitDesktopmust be run as Administrator
VSCode 必须 以管理员身份运行或GitDesktop必须以管理员身份运行
回答by Ashish Singh Rawat
React Native
反应本机
Faced similar issue while building react native app. Running on the different port as the default port (8081) is used by some other app.
在构建 React Native 应用程序时遇到了类似的问题。在不同的端口上运行,因为其他应用程序使用默认端口 (8081)。
Command to build the app.
构建应用程序的命令。
react-native run-android --port=8082
react-native run-android --port=8082
SolutionMy case
解决我的情况下,
(Removed extra attribute android:screenOrientation="portrait"
. If you check the log, it says
(删除了额外的属性android:screenOrientation="portrait"
。如果你检查日志,它说
lineNumber: 26; columnNumber: 56; Attribute "screenOrientation" bound to namespace "http://schemas.android.com/apk/res/android" was already specified for element "activity".
行号:26;列数:56;已为元素“activity”指定了绑定到命名空间“ http://schemas.android.com/apk/res/android”的属性“screenOrientation ”。
hence removed the same attribute. This was being added multiple times
因此删除了相同的属性。这被多次添加
Error log
错误日志
Configure project :react-native-webview
:react-native-webview:reactNativeAndroidRoot /Users/PROJECT_PATH/node_modules/react-native/android
Task :app:generateDebugBuildConfig FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:generateDebugBuildConfig'.
org.xml.sax.SAXParseException; systemId: file:/Users/PROJECT_PATH/android/app/src/main/AndroidManifest.xml; lineNumber: 26; columnNumber: 56; Attribute "screenOrientation" bound to namespace "http://schemas.android.com/apk/res/android" was already specified for element "activity".
* 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 1s
32 actionable tasks: 1 executed, 31 up-to-date
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
Command failed: ./gradlew installDebug
回答by Tahir Khalid
Navigate into the android folder of your react-native project and type the following:
导航到您的 react-native 项目的 android 文件夹并键入以下内容:
gradlew cleanBuildCache
gradlew cleanBuildCache
Then fire up something like Android Studio do a build and you should find the issue is resolved. If you still get errors check the log carefully the information is in there just hard to find.
然后启动 Android Studio 之类的东西进行构建,您应该会发现问题已解决。如果您仍然遇到错误,请仔细检查日志,那里的信息很难找到。