简体   繁体   English

我如何使用 java 代码以编程方式在 android 上运行 cmd 命令

[英]how do i run cmd command on android programmatically with java code

I am new to java and Andriod studio development.我是 java 和 Andriod 工作室开发的新手。 I working on an app that need to run "gradlew assembleDebug" command in the app itself.我正在开发一个需要在应用程序本身中运行“gradlew assembleDebug”命令的应用程序。 is that possible?那可能吗?

Android does not ship with any build tools inside it. Android 内部没有任何构建工具。 On your phone, there is no gradle.在您的手机上,没有 gradle。

In theory you can make an app that ships these tools but this is very complicated;从理论上讲,您可以制作一个包含这些工具的应用程序,但这非常复杂; that sounds like a project far beyond sensible for someone new to java and android development.对于 java 和 android 开发的新手来说,这听起来像是一个远远超出理智的项目。

-- --

Or, did you mean: You are writing a plugin for Android Studio and it needs to run gradlew?或者,您的意思是:您正在为 Android Studio 编写插件并且它需要运行 gradlew? That doesn't sound like a good idea: Android Studio itself does a bunch of stuff around invoking gradle and may have it built in;这听起来不是一个好主意:Android Studio 本身围绕调用 gradle 做了很多事情,并且可能内置了它; you should tell studio to invoke it, instead of doing it yourself.你应该告诉工作室调用它,而不是自己做。 I don't know how that's done, though.不过,我不知道这是怎么做到的。

-- --

If you really want to invoke commands, use ProcessBuilder .如果您真的想调用命令,请使用ProcessBuilder But as I said, this is not what you want to do here .但正如我所说,这不是你想在这里做的

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM