A tutorial on how to compile the X11-Basic app for Android from sources and 
how to include a specific X11-Basic program for autostart.

(Make an .apk out of a .bas file)  

############################################################################



Part I --- Setting up a development environment
===============================================

1. Setup a regular Ubuntu linux PC. A minimal server edition will do.
   I use Ubuntu 16.4 32-bit (*)
2. install following packages with 
   sudo apt-get install git default-jdk
3. Setup the Android development environment
   The development kits can be downloaded and unpackt to /opt from:
   https://developer.android.com/ndk/downloads/index.html
   and
   https://developer.android.com/studio/index.html

Make sure that you now have following directories:
/opt/android-ndk-r7c
/opt/android-sdk-linux
/opt/android-sdk-linux/build-tools/19.1.0/
/opt/android-sdk-linux/platforms/android-17

Maybe another version than r7c will do and maybe 
android-sdk-linux_x86 instead of android-sdk-linux.

(If you cannot get the right version numbers (19.1.0 and -17), you 
could try to adapt gradle.properties after step II.4 to other versions, but 
I cannot garantee that the compilation will work, but maybe it is woth a shot.)

(*)
As of 2018, I have tested to use Android Studio on a 64bit Ubuntu 17.04 linux
system. Build-Tools: 28.0.1, API-level (compile=28, min=8, target=17), 
NDK version r10e. I have not yet used a higher NDK version, since the more recent
versions also want to compile 64bit excecutables. But X11-Basic for Android
is not yet configured to compile correctly on 64bit targets. 


Part II --- compiling the X11-Basic-App
=======================================
1. create your private keystore:
   keytool -genkey -alias mydomain -keyalg RSA -keystore KeyStore.jks -keysize 2048   
   
   Instead of mydomain please use any name (for the key) you like. You will be asked to 
   enter two passwords, one for the keystore file and another for the key itself.

   This key will be used to sign the .apk file. This is necessary to make the 
   app created really yours.

   You can of course also use an existing key from an existing keystore, 
   if you have one already.

2. set the environement variable to the location of the keystore file
   export KEYSTORE=/path/to/your/keystore/file/KeyStore.jks

3. goto an empty directory and do a 
   git clone --recursive https://gitlab.com/kollo/X11-Basic.git
   (do not forget the --recursive flag!)

4. goto the X11-Basic directory
   cd X11-Basic
5. now make gradle aware of the name of the key by 
   replacing "drhoffmannsoftware" with your own key alias (mydomain) in the 
   file build.gradle.
        
6. set the environment variables to the Android SDK and NDK
   export ANDROID_HOME=/opt/android-sdk-linux
   export ANDROID_NDK_HOME=/opt/android-ndk-r7c
7. change the path to the android NDK folder in local.properties (line 1)

8. then do a 
   ./gradlew build
(Enter passwords for the keystore and the key)
(the compile process will take a while, clapack really has many files)

The apk should finally be in build/outputs/apk/X11-Basic-release.apk


Part III --- include your own BASIC program
===========================================
Goto the X11-Basic folder and
a) empty the folder src/main/assets/bas and put only your program there, 
   rename it to autorun.bas
   This will make the App copy autorun.bas to the sdcard in the usual 
   folder bas/ and run it at startup. The original X11-Basic app also will 
   auto run it, so you may want to name your program differently and
   put the filename in src/main/assets/autorun.inf. 
   This will also work with bytecode compiled .b files. 
b) Optional: Change the apps icon in src/main/res/drawable (x11basic.png). 
   Make sure that the new pictures are in .png format and have the same size 
   as the original file. Also change the icons in all drawable-* folders 
   (they are for different screen resolutions) In tools/ there is a script on
   how to create all these files from a single .eps file.
c) not so optional: do any other changes you like, especially the name of the 
   app should be changed and also the domain path (which is 
   net.sourceforge.x11basic by default). These changes affect a lot of files, 
   (and they all need to be consistend). I Try to give a list here:

   change "X11-Basic" to something else in:
     src/main/res/values*/strings.xml
   
   change "net.sourceforge.x11basic" to something else in:
     src/main/AndroidManifest.xml
     src/main/java/net/sourceforge/x11basic/*.java
   
   change "net_sourceforge_x11basic" to something else in:
     src/main/jni/android.c

Finally trigger the compilation again, rename the .apk file and you should be 
done.
  
Does anybody want to write a script for doing all this?




This tutorial was written by Markus Hoffmann with the help of bruno 
