Search code examples
androidideapkdalviktoolchain

Alternative language or toolchain for creating Android programs


Is there some sort of alternative toolchain or language for Android, which can generate standalone APK files?

Ideally it should not depend on the huge and ever-changing, ever-upgraded official Android SDK.

As a parable, I am looking for a rough equivalent to how PowerBASIC and Mingw targets plain Windows just fine, despite Microsoft releasing new Visual Studios all the time.

Bonus points if this language or toolchain itself is an Android program...


Solution

  • As you may or may not be aware, the Android toolchain is based on a few simple ideas:

    • Your code is compiled using the plain old java compiler, and linked against the Android stubs (android.jar) for linkage against the system library.
    • After being compiled, the code is converted to dex format. You can actually run this yourself, just do a dx --help. The job of the dx tool is to take Java class files and convert them to dex code, a pretty straightforward compilation which involves going from a stack based to register based vm, and a few other changes.
    • After having this in place, an apk is built using a set of apk tools. It used to be apkbuilder, but this has since been deprecated. You can actually run this yourself as well. All an APK is is simply a collection of the manifest, resources, and a single file for all the code in dex form. (I.e., many .class files compile to a single .dex which is quite a bit smaller because of a wrapped web of pointers).

    So the Android toolchain isn't really all that complex. The custom build process is handled by ant build rules, which are defined in an SDK wide build.xml, which you can find in the platform-tools/ directory (iirc). However, to generate new baseline projects using this custom build environment you simply use the android update project command.

    While I'm not sure if this is the response you'd hoped for, I hope it will disambiguate the build process. It's not really all that complex of a toolchain, the majority of it is off the shelf Java, and not Android specific (all that makes it Android specific is library specific stubs for dynamically linked system code). Beyond this, once you have a set of classes, you need only run a few commands to make an executable APK which Android unpacks. I would suspect that any tool targeting the JVM (and capable of linking with the Android specific dynamically linked API) could perform a similar process of producing class files and using this toolchain to compile the rest of the way, though obviously the automated ant build process makes it much simpler.

    EDIT:

    After some more digging, I found this relevant android-developers thread. An unsettling quote:

    At this time we simply don't have the resources to support people who want to use their own build system, but we really wish we could. In many ways we try to make it easy on other tools vendor by clearly separating logic to eclipse or ant specific code (hence the multitude of jar files everywhere in the tools and in ADT), but this is not one of them.

    However, you may also find this link helpful.