Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
blog:190226_compile_apk_online [2020/03/04 10:18] – Ignas | blog:190226_compile_apk_online [2021/07/15 09:55] (current) – Ignas | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Compile APK online ====== | ||
+ | It was long time i was dreaming about ability to compile apk online. So this blog post (tutorial) will be how to prepare < | ||
+ | |||
+ | This post will not be about " | ||
+ | |||
+ | First of all, create new empty ubuntu box < | ||
+ | |||
+ | ====== Prepare your system ====== | ||
+ | <WRAP center round info 80%>I prepending everyhing with //sudo// command, in case any permission will be missing.</ | ||
+ | |||
+ | So lets begin from very basic. At first you need JAVA, so add OpenJDK repository and install java | ||
+ | |||
+ | <code bash> | ||
+ | sudo apt-get update</ | ||
+ | |||
+ | Install Java headless, because you do not need GUI here | ||
+ | <code bash> | ||
+ | |||
+ | Download SDK zip from android home. You may use my provided link | ||
+ | <code bash> | ||
+ | |||
+ | Make directory for android SDK and extract ZIP | ||
+ | <code bash> | ||
+ | sudo unzip sdk-tools-linux-4333796.zip -d / | ||
+ | |||
+ | Now add environment variables to your system. | ||
+ | <code bash> | ||
+ | and at the very end add following lines | ||
+ | <WRAP center round important 80%> | ||
+ | <code bash> | ||
+ | export JAVA_HOME="/ | ||
+ | export PATH=$JAVA_HOME/ | ||
+ | |||
+ | Save and exit by pressing CTRL+X on keyboard and confirming that you want to save changes by Y. Restart your machine or environment. | ||
+ | |||
+ | Now you need to add SDK, Tools and platform stuff. I have chosen 24 version so i have used this command | ||
+ | <code bash> | ||
+ | in case you want something else or want to see available list use // | ||
+ | |||
+ | Looks like everything is prepared, now need "Hello world!" | ||
+ | |||
+ | Steps needs to be done to get APK file | ||
+ | - Generate R.java file **AAPT** | ||
+ | - Compile java file with **javac** | ||
+ | - Translate it to Dalvik Bytecode with **DX** | ||
+ | - Make apk with **AAPT** | ||
+ | - Align apk package with **ZIPALIGN** | ||
+ | - Sign your apk file with **APKSIGNER** | ||
+ | |||
+ | AS you can see, there is a step to sign you apk install file with certificate. You can create your own. In main project directory, the same where AndroidManifest.xml file exist, run following command to create private key: | ||
+ | <code bash> | ||
+ | Answer all questions and provide password. | ||
+ | |||
+ | Thats it. Now you can create APK file from command line. To create automated, here is prepared bash script witch you should save in project root directory (the same as android manifest) and run to build your project. I have chosen to name it make.sh | ||
+ | |||
+ | <code bash make.sh> | ||
+ | #!/bin/bash | ||
+ | |||
+ | set -e | ||
+ | |||
+ | AAPT="/ | ||
+ | DX="/ | ||
+ | ZIPALIGN="/ | ||
+ | APKSIGNER="/ | ||
+ | PLATFORM="/ | ||
+ | |||
+ | echo " | ||
+ | rm -rf obj/* | ||
+ | rm -rf src/ | ||
+ | rm -rf bin/* | ||
+ | |||
+ | echo " | ||
+ | $AAPT package -f -m -J src -M AndroidManifest.xml -S res -I $PLATFORM | ||
+ | |||
+ | echo " | ||
+ | javac -d obj -classpath src -bootclasspath $PLATFORM -source 1.7 -target 1.7 src/ | ||
+ | javac -d obj -classpath src -bootclasspath $PLATFORM -source 1.7 -target 1.7 src/ | ||
+ | |||
+ | echo " | ||
+ | $DX --dex --output=classes.dex obj | ||
+ | |||
+ | echo " | ||
+ | $AAPT package -f -m -F bin/ | ||
+ | $AAPT add bin/ | ||
+ | |||
+ | echo " | ||
+ | $ZIPALIGN -f 4 bin/ | ||
+ | $APKSIGNER sign --ks mykey.keystore bin/ | ||
+ | </ | ||
+ | |||
+ | In case you have used different versions in sdkmanager command- edit path in header accordingly. | ||
+ | Just run this script with following command. If you can not run it __chmod +x make.sh__ | ||
+ | <code bash> | ||
+ | Script will ask password for your keystore that you provided earlier. | ||
+ | |||
+ | This solution works if your application does not have any dependencies on external libs and gradle wrapper is not used. | ||
+ | Probably, automated install script can be made but that's for another times. | ||
+ | In case you have any suggestions, | ||
+ | |||
+ | {{tag> goorm cloud android linux console compile apk online tutorial NoGradle}} | ||
+ | |||
+ | ~~DISCUSSION~~ | ||