如何使用Java代码在Android上以编程方式运行CMD命令

huangapple go评论72阅读模式
英文:

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

问题

我是新手,对于Java和Android Studio的开发并不熟悉。我正在开发一个需要在应用程序内部运行“gradlew assembleDebug”命令的应用程序。这是否可能?

英文:

I am new to java and Andriod studio development. I working on an app that need to run "gradlew assembleDebug" command in the app itself.
is that possible?

答案1

得分: 1

Android不会在其内部附带任何构建工具。在您的手机上,没有gradle。

理论上,您可以制作一个包含这些工具的应用,但这非常复杂;对于刚接触Java和Android开发的人来说,这听起来像是一个非常不明智的项目。

--

或者,您是指:您正在为Android Studio编写插件,并且它需要运行gradlew?那听起来不是一个好主意:Android Studio本身会围绕调用gradle执行许多操作,并且可能已经内置了它;您应该告诉Studio去调用它,而不是自己执行。我不知道该如何做到这一点,不过。

--

如果您真的想要调用命令,请使用ProcessBuilder。但正如我所说,这不是您在这里想要做的。

英文:

Android does not ship with any build tools inside it. On your phone, there is no 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.

--

Or, did you mean: You are writing a plugin for Android Studio and it needs to run 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; 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. But as I said, this is not what you want to do here.

huangapple
  • 本文由 发表于 2020年4月4日 19:08:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/61027163.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定