Termux-app: Run Kotlin for android apps on android

Created on 31 May 2020  路  1Comment  路  Source: termux/termux-app

Hello. I have tried installing Java on termux but I had problems make it work correctly . I want to run Kotlin on my android in order to build android apps on it . Please if it's possible , could you help please. Even if I need to install another Linux environment like Ubuntu or Arch etc. I also know that termux runs in JVM so help is needed 馃檹馃檹

>All comments

Well, it's possible (though at the moment not convenient because I haven't managed to make gradle work, nor have I written a script for the job, so dependencies have to be downloaded manually - ouch).

First, install all the non-kotlin stuff you need to make an android app (dx, apksigner, zip, aapt)

You will also need an android jar to compile against (there is this one I just found and compiled against, which works: https://drive.google.com/file/d/1-IUO3-gXHAkOJCmB2jgP83LpvNhYfNVg/view).

Next, install arch on termux (https://wiki.termux.com/wiki/Arch).

Then, proot into arch and whilst prooted install the kotlin compiler (packman -S kotlin), in order to use the kotlin compiler (kotlinc).

After that, you will be able to use kotlinc from outside of arch by using ~/arch/startarch c kotlinc ARGUMENTS, however I prefer to make a script with the same name (kotlinc) in $PATH, that contains /data/data/com.termux/files/home/arch/startarch c kotlinc $@, so for the rest of this I will be calling that instead of the long winded command.

Next what you're gonna want to do is compile the kotlin files for your app into a classes.dex file (which will be put into the apk)

To do this, first gather the dependencies for your app (I found that for whatever reason it wouldn't work unless the dependencies were in the current directory, but that's probably just me misusing the compiler).

Now run the command (without including my bracketed comments): kotlinc -cp $jar_files (this is a colon seperated list of jar dependencies, which you'll have to install/write installer for yourself) -d output_name.jar $(find -name *.kt)

After that you'll have a jar file called output_name.jar - you'll want to put this (and any other dependencies that need to be packaged into the app) into a dex file. You can do this by doing: dx --dex --output=classes.dex output_name.jar dep1.jar dep2.jar (and so on, so forth)

After that, you will want to make an apk. You can do this using aapt to first create an apk from your resources folder and your manifest file: aapt p -M path/to/AndroidManifest.xml -I android.jar -S res -F output.apk.

Now you have an apk, you need to do two more things:

1: Add your classes.dex file to the apk, like so: zip -u output.apk classes.dex

2: Sign the apk with apksigner by doing apksigner -p passwordThatShouldBeSecret keystore output.apk output-signed.apk (Note: keystore creates a file called keystore, you don't need to worry too much about it)

After this, you'll have a signed apk, which you should be able to install and use.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nomxs picture nomxs  路  4Comments

QGB picture QGB  路  3Comments

baconicsynergy picture baconicsynergy  路  5Comments

darth-cequella picture darth-cequella  路  3Comments

msh2050 picture msh2050  路  4Comments