Java 命令失败:gradlew.bat installDebug
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54776936/
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
Command failed: gradlew.bat installDebug
提问by Samuel Egwurube
While developing an app I came into following error. I tried downgrading the java version from 11 to 8, but that wasn't helpful.
在开发应用程序时,我遇到了以下错误。我尝试将 java 版本从 11 降级到 8,但这没有帮助。
FAILURE: Build failed with an exception.
* What went wrong:
Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
> Could not create service of type PluginResolutionStrategyInternal using BuildScopeServices.createPluginResolutionStrategy().
* 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 15s
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.bat installDebug
Error: Command failed: gradlew.bat installDebug
at checkExecSyncError (child_process.js:616:11)
at Object.execFileSync (child_process.js:634:13)
at runOnAllDevices (C:\Users\samie\Documents\React Native\auth\node_modules\react-native\local-cli\runAndroid\runAndroid.js:299:19)
at buildAndRun (C:\Users\samie\Documents\React Native\auth\node_modules\react-native\local-cli\runAndroid\runAndroid.js:135:12)
at isPackagerRunning.then.result (C:\Users\samie\Documents\React Native\auth\node_modules\react-native\local-cli\runAndroid\runAndroid.js:65:12)
at process._tickCallback (internal/process/next_tick.js:68:7)
回答by Natalie Friede
I had this issue myself, it eventually went away after I uninstalled and re-installed android studio and gradle, but a few other things you could try first
我自己也遇到过这个问题,在我卸载并重新安装 android studio 和 gradle 后它最终消失了,但是您可以先尝试其他一些事情
1: Setting GRADLE_USER_HOME in environment variables (if on windows)
1:在环境变量中设置 GRADLE_USER_HOME(如果在 Windows 上)
2: Downgrade to react-native 0.57.0
2:降级到 react-native 0.57.0
3: Make sure you have the correct permissions to run the command and access files
3:确保你有正确的权限来运行命令和访问文件
4: Make sure your gradle files are synced correctly, and that location of gradle and the android skd are correct within project structure offline mode
4:确保你的gradle文件同步正确,并且在项目结构离线模式下gradle和android skd的位置是正确的
5: Check gradle for updates
5:检查gradle是否有更新
(Assuming you are using android studio)
(假设您使用的是 android studio)
Good luck
祝你好运
回答by Akshay Mulgavkar
Try running this command inside your project file
尝试在您的项目文件中运行此命令
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
after that
在那之后
cd (path to project/android folder) && gradlew clean && cd .. && react-native run-android
always gradlew clean before run react-native-run-android the above command basically cleans up the gradle and previous builds.
在运行 react-native-run-android 之前总是 gradlew clean 上面的命令基本上清理了 gradle 和以前的构建。
for ENOENT ErrorCheck if $ yarn start
works. The metro bundler wasn't able to run on port 8081 for me and I needed to run $ killall node
对于 ENOENT 错误检查是否$ yarn start
有效。Metro bundler 无法在端口 8081 上运行,我需要运行$ killall node
EDIT:
编辑:
Also update the gradle-wrapper.properties
add
也更新gradle-wrapper.properties
添加
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
remove following code from build.gradle
:
从以下代码中删除build.gradle
:
task wrapper(type: Wrapper) {
gradleVersion = '5.2.1'
distributionUrl = distributionUrl.replace("bin", "all")
}
after that
在那之后
cd (path to project/android folder) && gradlew clean && cd .. && react-native run-android
always gradlew clean before run react-native-run-android the above command basically cleans up the gradle and previous builds.
在运行 react-native-run-android 之前总是 gradlew clean 上面的命令基本上清理了 gradle 和以前的构建。
You're good to go!
你可以走了!
回答by Nicholas Sharpe
I had this issue too and I was able to fix it by creating a new project in react-native 0.57.3 using the command:
react-native init --version="0.57.3" MyNewApp
我也有这个问题,我能够通过使用以下命令在 react-native 0.57.3 中创建一个新项目来解决它:
react-native init --version="0.57.3" MyNewApp
回答by aroldo andrade
open your 'settings.grandler' file in the android folder
在 android 文件夹中打开您的“settings.grandler”文件
change the '\' to '/'
将“\”更改为“/”
save the file
保存文件
run the command 'react-native run-android
运行命令'react-native run-android
回答by FoX
You have to update the gradle-wrapper.propertiesfile to use the newest version of gradle:
您必须更新gradle-wrapper.properties文件才能使用最新版本的 gradle:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
And remove this block from build.gradlefile:
并从build.gradle文件中删除此块:
task wrapper(type: Wrapper) {
gradleVersion = '5.2.1'
distributionUrl = distributionUrl.replace("bin", "all")
}
Then run a gradlew cleanon the android folder and everything should work.
然后在 android 文件夹上运行gradlew clean,一切正常。
回答by codebased
How I solved this problem:
我是如何解决这个问题的:
First, make sure that I have %java_home% variable set and also %path% has the java sdk included. How to setup Java environment variables
首先,确保我设置了 %java_home% 变量并且 %path% 包含了 java sdk。 如何设置Java环境变量
Second, Go to your android folder and run this command:
其次,转到您的 android 文件夹并运行以下命令:
C:\Projects\myproject\android>gradlew.bat app:installDebug.
Unzipping C:\Users\codeb.gradle\wrapper\dists\gradle-4.10.2-all\9fahxiiecdb76a5g3aw9oi8rv\gradle-4.10.2-all.zip to C:\Users\codeb.gradle\wrapper\dists\gradle-4.10.2-all\9fahxiiecdb76a5g3aw9oi8rv Exception in thread "main" java.util.zip.ZipException: error in opening zip file at java.util.zip.ZipFile.open(Native Method) at java.util.zip.ZipFile.(ZipFile.java:225) at java.util.zip.ZipFile.(ZipFile.java:155) at java.util.zip.ZipFile.(ZipFile.java:169) at org.gradle.wrapper.Install.unzip(Install.java:215) at org.gradle.wrapper.Install.access$600(Install.java:27) at org.gradle.wrapper.Install$1.call(Install.java:75) at org.gradle.wrapper.Install$1.call(Install.java:48) at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69) at org.gradle.wrapper.Install.createDist(Install.java:48) at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107) at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
解压 C:\Users\codeb.gradle\wrapper\dists\gradle-4.10.2-all\9fahxiiecdb76a5g3aw9oi8rv\gradle-4.10.2-all.zip 到 C:\Users\codeb.gradle\wrapper\dists\gradle-4.10 .2-all\9fahxiiecdb76a5g3aw9oi8rv 线程“main”中的异常 java.util.zip.ZipException: 在 java.util.zip.ZipFile.open(Native Method) at java.util.zip.ZipFile.(ZipFile) 中打开 zip 文件时出错.java:225) 在 java.util.zip.ZipFile.(ZipFile.java:155) 在 java.util.zip.ZipFile.(ZipFile.java:169) 在 org.gradle.wrapper.Install.unzip(Install. java:215) 在 org.gradle.wrapper.Install.access$600(Install.java:27) 在 org.gradle.wrapper.Install$1.call(Install.java:75) 在 org.gradle.wrapper.Install$1。在 org.gradle.wrapper.ExclusiveFileAccessManager 调用(Install.java:48)。access(ExclusiveFileAccessManager.java:69) at org.gradle.wrapper.Install.createDist(Install.java:48) at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107) at org.gradle.wrapper.GradleWrapperMain .main(GradleWrapperMain.java:61)
As you can see that my gradle download is corrupt. All you have to do is delete this folder and rerun the command.
如您所见,我的 gradle 下载已损坏。您所要做的就是删除此文件夹并重新运行该命令。
C:\Projects\myproject\android>gradlew.bat app:installDebug
Downloading https://services.gradle.org/distributions/gradle-4.10.2-all.zip............................................................................................................... Unzipping C:\Users\codeb.gradle\wrapper\dists\gradle-4.10.2-all\9fahxiiecdb76a5g3aw9oi8rv\gradle-4.10.2-all.zip to C:\Users\codeb.gradle\wrapper\dists\gradle-4.10.2-all\9fahxiiecdb76a5g3aw9oi8rv
Welcome to Gradle 4.10.2!
Here are the highlights of this release: - Incremental Java compilation by default - Periodic Gradle caches cleanup - Gradle Kotlin DSL 1.0-RC6 - Nested included builds - SNAPSHOT plugin versions in the
plugins {}
blockFor more details see https://docs.gradle.org/4.10.2/release-notes.html
下载 https://services.gradle.org/distributions/gradle-4.10.2-all.zip..................................... ………………………………………………………………………………………………………………………………………………………… ...................... 解压 C:\Users\codeb.gradle\wrapper\dists\gradle-4.10 .2-all\9fahxiiecdb76a5g3aw9oi8rv\gradle-4.10.2-all.zip 到 C:\Users\codeb.gradle\wrapper\dists\gradle-4.10.2-all\9fahxiiecdb76a5g3aw9oi8rv
欢迎使用 Gradle 4.10.2!
以下是此版本的亮点: - 默认情况下增量 Java 编译 - 定期 Gradle 缓存清理 - Gradle Kotlin DSL 1.0-RC6 - 嵌套包含的构建 -
plugins {}
块中的SNAPSHOT 插件版本有关更多详细信息,请参阅https://docs.gradle.org/4.10.2/release-notes.html
Now, you can go back to your react native project and run
现在,您可以返回到 React Native 项目并运行
react-native run-android
info JS server already running. info Building and installing the app on the device (cd android && gradlew.bat app:installDebug)...
Task :app:installDebug 01:03:18 V/ddms: execute: running am get-config 01:03:18 V/ddms: execute 'am get-config' on 'emulator-5554' : EOF hit. Read: -1 01:03:18 V/ddms: execute: returning Installing APK 'app-debug.apk' on 'Pixel_2_API_28(AVD) - 9' for app:debug 01:03:18 D/app-debug.apk: Uploading app-debug.apk onto device 'emulator-5554' 01:03:18 D/Device: Uploading file onto device 'emulator-5554' 01:03:18 D/ddms: Reading file permision of C:\Projects\xx\android\app\build\outputs\apk\debug\app-debug.apk as: rwx------ 01:03:18 V/ddms: execute: running pm install -r -t "/data/local/tmp/app-debug.apk" 01:03:19 V/ddms: execute 'pm install -r -t "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read: -1 01:03:19 V/ddms: execute: returning 01:03:19 V/ddms: execute: running rm "/data/local/tmp/app-debug.apk" 01:03:19 V/ddms: execute 'rm "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read: -1 01:03:19 V/ddms: execute: returning Installed on 1 device.
BUILD SUCCESSFUL in 9s 27 actionable tasks: 1 executed, 26 up-to-date info Running C:\Users\codeb\AppData\Local\Android\Sdk/platform-tools/adb -s emulator-5554 reverse tcp:8081 tcp:8081 info Starting the app on emulator-5554 (C:\Users\codeb\AppData\Local\Android\Sdk/platform-tools/adb -s emulator-5554 shell am start -n com.myproject/com.myproject.MainActivity)... Starting: Intent { cmp=com.myproject/.MainActivity }
info JS 服务器已经在运行。info 在设备上构建和安装应用程序 (cd android && gradlew.bat app:installDebug)...
任务:app:installDebug 01:03:18 V/ddms:执行:运行 am get-config 01:03:18 V/ddms:在“emulator-5554”上执行“am get-config”:EOF 命中。阅读:-1 01:03:18 V/ddms:执行:返回安装 APK 'app-debug.apk' on 'Pixel_2_API_28(AVD) - 9' for app:debug 01:03:18 D/app-debug.apk :将 app-debug.apk 上传到设备“emulator-5554” 01:03:18 D/Device:将文件上传到设备“emulator-5554” 01:03:18 D/ddms:读取 C:\Projects\ 的文件权限xx\android\app\build\outputs\apk\debug\app-debug.apk 为:rwx------ 01:03:18 V/ddms:执行:运行 pm install -r -t "/data/ local/tmp/app-debug.apk" 01:03:19 V/ddms: 在 'emulator-5554' 上执行 'pm install -r -t "/data/local/tmp/app-debug.apk"':EOF打。阅读:-1 01:03:19 V/ddms:执行:返回 01:03:19 V/ddms:执行:运行 rm"/data/local/tmp/app-debug.apk" 01:03:19 V/ddms:执行 'rm"/data/local/tmp/ app-debug.apk"' 在 'emulator-5554' 上:EOF 命中。读取:-1 01:03:19 V/ddms:执行:返回已安装在 1 个设备上。
在 9 秒内成功构建 27 个可操作任务:1 个已执行,26 个最新信息正在运行 C:\Users\codeb\AppData\Local\Android\Sdk/platform-tools/adb -s emulator-5554 reverse tcp:8081 tcp: 8081 信息在 emulator-5554 上启动应用程序(C:\Users\codeb\AppData\Local\Android\Sdk/platform-tools/adb -s emulator-5554 shell am start -n com.myproject/com.myproject.MainActivity) ... 开始:意图 { cmp=com.myproject/.MainActivity }
回答by Cinzia Nicoletti
The problem is on file:
问题在文件中:
nameyourapp/android/local.properties
命名你的应用程序/android/local.properties
you have to substitute with the correct path: /Users/nameUser/AppData/Local/Android/sdk
你必须用正确的路径替换: /Users/nameUser/AppData/Local/Android/sdk
回答by Abdi
Just run sudo react-native run-android
and it will build and install ./gradlew app:installDebug inside android directory for you.
只需运行sudo react-native run-android
,它就会在 android 目录中为您构建和安装 ./gradlew app:installDebug 。