Android Project - QB64 Wiki

Android Project

From QB64 Wiki

Jump to: navigation, search

IMPORTANT (you really should read this)
  • Windows users should follow the numbered steps below in the correct order or you will have problems
  • QB64 currently builds projects which target ARM-based processors not x86 processors. No testing on x86 has been done (it should work in theory if you change the target).
  • QB64 Android projects have only been extensively tested on a Samsung Galaxy S5 (but should run on other Android devices too)
  • If you already have the Android NDK installed from the days when QB64 used Eclipse+NDK remove it to avoid potential conflicts (or set an explict path to the new NDK in located_files.txt [see notes below])
  • Android Studio and its tools are constantly being updated. As such, the version of Android Studio you install won't come preconfigured with the components to build your project's version.

In most cases, you simply need to open the Android SDK manager (as we do in Step 4 below) to install required components if your project fails to build in Android Studio

Android Setup Instructions (.ZIP with PNG pictures)
Do not attempt to build an Android project until JDK and Android Studio are installed!
QB64 will search for C: for specific files in the NDK and Android Studio and it can be a long wait if it cannot find them.
  • 2) Android Studio requires the Java Development Kit (JDK) 6 or higher (NOT the JRE, JRE will be installed automatically by the JDK), so download & install this first:
√ CHECK BOX: You must accept the Oracle Binary Code License Agreement for Java SE to download this software.
For example, if you are using 64-bit Windows you would download "Windows x64 - jdk-7u79-windows-x64.exe" [~140MB]
  • 3) Download and install Android Studio (includes SDK) with the default options from the following link [~1.1GB]
√ Agree to Terms and Conditions before download is available! Windows x86 or x64 bit determined by site. (This is a 1.1GB download)
  • 4) Open Android Studio and select configure [1.png] and then SDK manager [2.png].
In the SDK Platforms tab, install API level 21 (Android 5.0.1) and/or versions for older or newer devices. [3.png]
√ Check Show Package Details box to add ARM virtual device images to test programs without a USB Android device.
Note that the system virtual device images including ARM EABI va7 are NOT selected by default.
If you want to run and test with an Android virtual device (AVD), you will want to check those options!!
In the SDK Tools tab, install Android NDK [4.png]
Now exit Android studio (Sometimes Android Studio needs to be restarted to detect changes)
  • 5) Locate the file "C:\Users\{YourUserName}\AppData\Local\Android\sdk\ndk-bundle\build\core\"
Modify the TARGET_CXXFLAGS line to also contain "-fpermissive" as shown below:

TARGET_CXXFLAGS = $(TARGET_CFLAGS) -fno-exceptions -fno-rtti -fpermissive

  • 6) Open QB64 and Enable the Google Android Run Menu commands in Options now. [5.png & 6.png]
  • 7) Create the test program provided, save it as HelloAndroid.bas, then select Make Android Project from the Run menu [7.png]

DO COLOR RND * 15 PRINT "Hello Android!"; _DISPLAY _LIMIT 30 LOOP UNTIL INKEY$ = CHR$(27) 'Press KB and Show to get keyboard to hit Esc key quit bottom right SYSTEM ' avoids Press any key entry

Open the project in Android Studio [8.png]
Your project will begin to build immediately, open the Gradle Console tab (bottom right) [9.png] and wait for it to complete
Note: It is normal to get warnings here, but you should not get any errors!
  • 8) Press the green play triangle icon in the middle of the row of icons at the top of Android Studio
Wait for Android Studio to display a list of available devices. If devices is not listed, check Device Manager drivers!
Make sure your Android device is in Developer USB-debugging mode and select trust this computer if prompted.
1) Go to Settings and tap About device usually near bottom of list.
2) Tap the Build Number 7 times to become a developer. (prompt may keep a count for you)
3) A new Developer option will appear in Settings usually near About at bottom of list
4) Tap the USB debugging mode listed in Developer options and confirm in dialog popup.
Setting Developer USB debugging mode video(YouTube)
  • 9) Select your device or a Virtual Device you installed in Step 4 and run your APP [10.png]

Setting up Android Device Drivers in Windows Device Manager
1) Check Device Manager and see if your plugged in Android USB device is listed with a ! warning next to it.
2) If it does then download Download latest Android(Nexus) Drivers for Windows and UNZIP folder.
3) In Device Manager Right Click Update Driver and Browse my computer and used the path to the zip Download:
Use the path latest_usb_driver_windows\usb_driver folder. Do not chose the i386 or amd64 folders.
4) Accept all prompts and device should have no warnings! Android Composite ADB Interface(Android Debug Bridge) will also be installed.
Driver Install Instruction Pictures     OEM USB ADB Driver(video)

QB64 Android path NOTES (read this if you get stuck or are curious)
  • QB64 will search C: for specific Android Studio, SDK and NDK files. You can help it find the files faster by adding the full path to the list of files in:
If some of the paths listed in this file are incorrect don't worry, QB64 will only use files it has physically verified the existance of.
These files currently are:

AVD Manager.exe ndk-build (no extension) gradle.bat

Typically located_files.txt should look similar to the text below. NOTE: QB64 may search for user files a long time!:

c:\Users\username\AppData\Local\Android\sdk\AVD Manager.exe c:\Users\username\AppData\Local\Android\sdk\ndk-bundle\ndk-build c:\Program Files\Android\Android Studio\gradle\gradle-2.4\bin\gradle.bat

Put more paths in for different versions of gradle that may be useful later on...
If you installed components on a different drive you will have to manually add paths to these user files!
Be aware that if QB64 cannot find the files, it will put default locations into your project which won't work!
  • When your programs run, "File not found" errors will probably be the most common:
Use the $INSTALLFILES and $INSTALLFOLDER commands in your .BAS file to tell QB64 which assets to include
The typical pattern I use for specific files in a folder is:
$INSTALLFILES "folder_relative_to_bas_file\*.jpg" IN "bas_file_folder_relative_to_qb64_exe\folder_relative_to_bas_file"
The typical pattern I use for a folder containing all assets (including all files in sub-folders and maintaining directory structure) is:
$INSTALLFOLDER "folder_relative_to_bas_file" IN "bas_file_folder_relative_to_qb64_exe\folder_relative_to_bas_file"
You can specify multiple $INSTALLFILES/FOLDERS metacommands if you need to.
Remember that Android is Linux based, so all your file names are case sensitive.
(I usually make everything lowercase, in fact you can get tools to convert entire directory trees to lowercase)
Android Setup Instructions.ZIP (with PNG pictures which may open zipped in Windows)

Solving the “gradle DSL method not found: android()” issue in Android Studio
Double click on the "build.gradle" selection under Projects and the file will come up and remove following lines:

android { compileSdkVersion 21 buildToolsVersion '21.1.2' }

See also:

Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
Personal tools