如何从命令行构建android apk? [英] How to build android apk from command line?

查看:245
本文介绍了如何从命令行构建android apk?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从命令行构建一个APK文件?我试过

  MSBuild myProject.dproj / p:Config = Release / p:Platform = Android 

但没有生成APK文件,只有.so文件。

解决方案

一些实验表明,各种拟议的行动方案的以下方面将发挥更加完整的作用。



你创建一个新的Delphi多目标项目(让我们称之为Foo)你有一个MSBuild兼容文件创建:Foo.dproj Delphi项目文件。在Android(这个问题的平台)的情况下,这足以构建最终成为已部署的.apk文件的一部分的目标libFoo.so库文件,但还不足以使.apk文件尚未。 / p>

您可以使用如下命令行构建包含ARM机器代码的.so文件:

  msbuild Foo.dproj / property:Config = Debug / property:Platform = Android / target:Build 

或这个更简洁的版本:

  msbuild Foo.dproj / p:Config = Debug / p:Platform = Android / t:Build 

根据文档,您可以使用Deployment Manager的Deploy按钮创建一个附加的MSBuild文件,或者确实只是选择 Project 部署libFoo.so 菜单项。此部署的初始步骤是创建一个Foo.deployproj文件,该文件是另一个与MSBuild兼容的文件。



使用Foo.deployproj文件,以下行将采用libFoo.so文件以及部署所需的其他任何东西,并使用它们构建.apk Android应用程序包文件:

  msbuild Foo .dproj / p:Config = Debug / p:Platform = Android / t:部署

如果所需的文件(如libFoo.so)不存在,则部署目标将失败,比如先前使用构建使 MSBuild目标运行MSBuild:s (431,5):错误:未找到必需的本地文件Android\Debug\libFoo.so。部署失败



此外,如果您没有为您的项目生成Foo.deployproj文件,则部署目标将失败: em>错误MSB4057:目标部署不存在于项目中。



那就是说,如果你有Foo.deployproj存在,你可以建立并单独部署如下:

  msbuild Foo.dproj / p:Config = Debug / p:Platform = Android / t:构建;部署

当然要避免编译没有更改的文件可能更好:

  msbuild Foo.dproj / p:Config = Debug / p:Platform = Android / t:Make; Deploy 

事实上,文档没有提及任何关于部署目标的事情有点混乱。有可能认为这意味着您运行MSBuild对Foo.deployproj文件,但这不会产生任何喜悦。看来这些文件已经过时或者是错误的。


How can I build an APK file from the command line? I've tried

MSBuild myProject.dproj /p:Config=Release /p:Platform=Android 

but no APK file is produced, only the .so file.

解决方案

Some experimentation shows that the following aspects of the various proposed courses of action come into play for a more complete picture.

When you create a new Delphi multi-target project (let's call it Foo) you have one MSBuild-compatible file created: the Foo.dproj Delphi project file. In the case of Android (the platform in this question) this is enough to build the target libFoo.so library file that would eventually become part of a deployed .apk file, but is not enough to make the .apk file just yet.

You can build your .so file, which contains the ARM machine code, using a command line like this:

msbuild Foo.dproj /property:Config=Debug /property:Platform=Android /target:Build

or this more concise version:

msbuild Foo.dproj /p:Config=Debug /p:Platform=Android /t:Build

As per the documentation you can use the Deployment Manager's Deploy button to create an additional MSBuild file, or indeed just choose the Project, Deploy libFoo.so menu item. The initial step of this deployment is to create a Foo.deployproj file, which is another MSBuild-compatible file.

With Foo.deployproj file present this following line will take the libFoo.so file and anything else required for deployment and use these to build up the .apk Android application package file:

msbuild Foo.dproj /p:Config=Debug /p:Platform=Android /t:Deploy

The Deploy target will fail if the required files such as libFoo.so are not present, say by previously running MSBuild using the Build or Make MSBuild targets: s(431,5): error : Required local file "Android\Debug\libFoo.so" not found. Deployment failed.

Additionally the Deploy target fails if you have not got a Foo.deployproj file generated for your project: error MSB4057: The target "Deploy" does not exist in the project.

That said, if you have the Foo.deployproj present you can build and deploy in one fell swoop with something like:

msbuild Foo.dproj /p:Config=Debug /p:Platform=Android /t:Build;Deploy

Of course to avoid compiling files that have not changed this is perhaps better:

msbuild Foo.dproj /p:Config=Debug /p:Platform=Android /t:Make;Deploy

The fact that the documentation doesn't mention anything about the Deploy target is a little confusing. There is potential to think that it implies you run MSBuild against Foo.deployproj file, but that yields no joy whatsoever. It seems the documentation is out of date or plain wrong.

这篇关于如何从命令行构建android apk?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆