Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build android apk from command line?

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.

like image 882
zeus Avatar asked Sep 23 '16 11:09

zeus


People also ask

What does gradlew assembleDebug do?

For instance, to build a debug version of your Android application, you can run ./gradlew assembleDebug from the root of your repository. In a default project setup, the resulting apk can then be found in app/build/outputs/apk/app-debug.

Can Android Studio make Android apps without?

So technically, you don't need an IDE at all. Basically, every project has at least a build. gradle file that contains the instructions to build it. You only have to launch Gradle with the appropriate command to compile your app.

How do I make an apk file?

To generate a signed APK file, open the Build menu from the toolbar and select Generate Signed Bundle/APK. This opens up a screen where you have to select between creating an Android App Bundle and creating an APK file. Check the APK radio button and proceed to the next window.


2 Answers

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.

like image 175
blong Avatar answered Oct 17 '22 12:10

blong


I found:

 MSBuild Project1.dproj /p:Config=Debug /p:Platform=Android /t:Deploy
like image 23
zeus Avatar answered Oct 17 '22 12:10

zeus