Compiling .aia Files to .apk Using CLI Tool

Hello, community!

I've been working on developing a new CLI tool aimed at automating tasks for App Inventor projects. The project is currently in its development phase. While drafting the todo list, a question came to mind, and I could use some clarification.

I came across this command from the App Inventor buildserver documentation:

$ ant RunMain -Dzip.file=$HOME/MyDownloads/ImageUpload.zip -Duser.name=$USER -Doutput.dir=/tmp

Source: App Inventor Buildserver README

My question is: Can this command be used to compile a .aia file (renamed to .zip) into an .apk?

Additionally, I have a few other related questions:

  1. Will this command successfully compile an .aia into an .apk?
  2. What additional dependencies (such as Java or Ant) are required to make it work?
  3. Is the Android SDK necessary for this process?
  4. Is the entire buildserver folder required, or are only specific components/files needed?
  5. Could someone explain the internal process of compiling .aia to .apk? I understand this might be a lengthy explanation, so a summary would be greatly appreciated.
  6. What is that Duser.name? And why is it required

Note: I don't want to use the full mit-cml repo cloned and then using the Build Server from there, instead only downloading the buildserver from the mit-cml repo and then using it with the CLI tool

I would like to take suggestions over this by Sir @ewpatton too

Thank you for your time and insights!

Best regards,
Horizon

2 Likes

Yes.

You do not need ant to run this. The minimum required set of items is the appropriate version of the JRE (e.g., Java 11) and the contents of the buildserver/build/run/lib directory after having compiled App Inventor. Then, from a directory containing the libs you can run:

java -cp '*' com.google.appinventor.buildserver.Main --childProcessRamMb 2048 --inputZipFile foo.zip --userName foo --outputDir `pwd` --dexCacheDir /tmp/dexCache --ext apk

This runs a build of foo.zip for user 'foo' and outputs the APK file (foo.apk) in the current working directory. If you need an AAB instead of an APK, adjust --ext accordingly.

We decompose the compilation process into a sequence of discrete tasks. You can look at the logic in AndroidBuildFactory.java in the buildserver module to see how the extension derives the specific sequence of tasks needed to compile the target. I won't go into detail since the code outlines what steps are needed to convert the AIA into the APK.

If the user doesn't have an existing android.keystore file, the username is used as the Common Name (CN) field of the certificate in a newly generated android.keystore file.

We don't publish compiled versions, so there isn't really a way to avoid this. To minimize the amount of building involved, you should cd buildserver and run ant to compile the buildserver. At that point you can copy the directory mentioned earlier to whatever system you are using to deploy your build infrastructure.

4 Likes

Thank you Sir @ewpatton for your explanation and consideration :slightly_smiling_face:

1 Like

Why have you mentioned the Java 11 here, and not conventional Java 8 (means any JDK or JRE version can be used either it be the latest?)

We will be deprecating Java 8 support in the near future as Google has dropped support for it from App Engine and the newer build tools for Android need Java 11 at a minimum (and likely soon to be Java 17). Currently, our code base can be built with either Java 8 or 11.

You will need the JDK to build the buildserver code, but once its built you only need the JRE to run it as the buildserver itself is self-contained.

Means compilation part will be from my side and then users just need JRE to continue to build apk directly from aia

Correct. This is effectively what we do in App Inventor. We compile with the JDK, but the buildserver images we deploy on our servers only bundle the JRE.

1 Like

Awesome sir :sunglasses::sunglasses:
Btw thanks for consideration and your valuable time :slightly_smiling_face:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.