7

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.

5
  • 4
    I find those downvotes rather disappointing. This is a perfectly reasonable question to me; one which the documentation fails to correctly inform upon. Indeed what has been tried thus far and the results attained were included.....
    – blong
    Sep 23, 2016 at 20:28
  • @blong Voting seems fine to me. The asker's answer is code only and rather low quality. Your answer is excellent. What I don't understand is how the asker's answer got an up vote. That's the real mystery and shame. Quality is what matters. Sep 25, 2016 at 21:35
  • Well, before it reverted to 0, the question was sat at -2, which seemed particularly unwarranted. So I nudged it back up towards 0, as did someone else. I'm not referring to votes against any answers.
    – blong
    Sep 25, 2016 at 21:40
  • @David: It's not the weight of a book that make a good book !
    – zeus
    Sep 26, 2016 at 14:45
  • Indeed. Quality is what counts. Sep 26, 2016 at 14:56

2 Answers 2

8

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.

4
  • ^#{@#{^ starckoverflow forbid me to do so :( it's look like someone put -1 on my answer (i wrote it before your's) and now i m banned from stackoverflow, i can just comment :(
    – zeus
    Sep 24, 2016 at 18:25
  • i can't understand why people put -1 on my question, and -1 on my response resulting that now i m blacklisted from stackoverflow. The question is usefull, well tagged/keyworded so that someone who will have the same problem can find it easily, and the question point to a bug in the documentation ... doesn't matter just to say
    – zeus
    Sep 24, 2016 at 18:36
  • @loki it looks like your -ve numbers have gone. Does that resolve your Stackoverflow issues?
    – blong
    Sep 26, 2016 at 9:00
  • @blong, yes now it's resolve :) thanks ! i succeed to accept your answer :) thanks again :)
    – zeus
    Sep 26, 2016 at 14:52
1

I found:

 MSBuild Project1.dproj /p:Config=Debug /p:Platform=Android /t:Deploy
2
  • Does this really answer your question which you asked? Can you explain for the sake of future readers why this works? Sep 23, 2016 at 16:24
  • Does not work, i get a "no target" error here. So it seems a rather specific solution for "your" project.
    – T.S
    Sep 8, 2021 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.