See first post (above) for newest install procedure ^^
[OLDER / ARCHIVED INSTRUCTIONS BELOW]2019-May-20 ver 1.3# Setup Android Development Environment on Linux (FPCUPdeluxe / LAMW)
# Tested on Xubuntu 16.04 64-bit and Xubuntu 18.04 64-bit
# Target 32-bit ARM on Android
# Target 64-bit aarch64 on Android
# 2019-May-20 ver 1.3
# Install libraries and tools
sudo apt-get install -y libx11-dev libgtk2.0-dev libgdk-pixbuf2.0-dev libcairo2-dev libpango1.0-dev libxtst-dev libatk1.0-dev libghc-x11-dev freeglut3 freeglut3-dev
sudo apt-get install -y git subversion make build-essential gdb zip unzip unrar wget
sudo apt-get install -y openjdk-8-jdk android-tools-adb ant
#Note: Next line is not needed on Ubuntu 16.04
sudo update-java-alternatives --set /usr/lib/jvm/java-1.8.0-openjdk-amd64
mkdir -p "$HOME/android/sdk"
# download and extract Android SDK Command Line Tools for Linux
# from https://developer.android.com/studio/#downloads
cd "$HOME/android/sdk"
wget "https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip"
unzip "sdk-tools-linux-4333796.zip"
rm "sdk-tools-linux-4333796.zip"
#Install SDK packages and NDK (as of 2019-May-20 this pulls in NDK r19c)
cd "$HOME/android/sdk/tools/bin"
./sdkmanager "platforms;android-26" "build-tools;26.0.3" "tools" "ndk-bundle" "extras;android;m2repository"
# make symbolic link to NDK toolchain
ln -sf "$HOME/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin" "$HOME/android/ndk-toolchain"
# work around bug, NDK 18 removed MIPS toolchains, but gradle plugin 3.0.1 won't run unless they are present
ln -sf "$HOME/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9" "$HOME/android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9"
ln -sf "$HOME/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9" "$HOME/android/sdk/ndk-bundle/toolchains/mipsel-linux-android-4.9"
# download and extract Gradle 4.10.3
# from https://gradle.org/releases/
cd "$HOME/android"
wget "https://services.gradle.org/distributions/gradle-4.10.3-bin.zip"
unzip "gradle-4.10.3-bin.zip"
rm "gradle-4.10.3-bin.zip"
# Use a text editor to open $HOME/.profile and add this text below:
# example: mousepad $HOME/.profile
export ANDROID_SDK_ROOT="${HOME}/android/sdk"
export GRADLE_HOME="${HOME}/android/gradle-4.10.3"
export PATH="${PATH}:${HOME}/android/ndk-toolchain"
export PATH="${PATH}:${GRADLE_HOME}/bin"
# Reboot (or logout of session and login)
# Download FPCUPdeluxe from https://github.com/newpascal/fpcupdeluxe/releases/latest
# (tested with version 1.6.2v)
mkdir "$HOME/fpcupdeluxe_app"
cd "$HOME/fpcupdeluxe_app"
wget "https://github.com/newpascal/fpcupdeluxe/releases/download/1.6.2v/fpcupdeluxe-x86_64-linux"
chmod +x fpcupdeluxe-x86_64-linux
./fpcupdeluxe-x86_64-linux
# Using FPCUPdeluxe install FPC/Lazarus, crosscompiler, and packages/modules:
# 1) On "Basic" tab, select FPC version "fixes3.2" & Lazarus version "fixes2.0" and click "Install/update FPC+Laz" button (if this fails, please see comments in next post)
# 2) On "Cross" tab, select CPU arm & OS android, "Install compiler" (select "yes" to missing tools message box)
# 3) On "Cross" tab, select CPU aarch64 & OS android, "Install compiler" (Ignore trunk warning, select "yes" to missing tools message box)
# 4) On Modules tab, select LAMW, Install module
# 5) (Optional but recommended) In module list: Select OPM, Install module (online package manager)
# Run Lazarus using the shortcut created by FPCUPdeluxe
# NOTE: DO NOT forget to replace references to [user] with your user name in 3 paths below
# Select Tools menu > [Lamw] Android Module Wizard > Paths Settings: [Jdk, Sdk, Ndk, ...]:
# Path to Java JDK: /usr/lib/jvm/java-8-openjdk-amd64
# Path to Ant bin: /usr/bin
# Path to Gradle: /home/[user]/android/gradle-4.10.3
# Path to Android NDK: /home/[user]/android/sdk/ndk-bundle
# NDK Version: >11
# Your Desktop System: linux-x86_64
# Path to Android SDK: /home/[user]/android/sdk
# For new LAMW projects, use Gradle for APK Builder and
# for 32-bit: ARMv7a + VFPv3 for Architecture/Instructions
# for 64-bit: Aarch64 for Architecture/Instructions
Manjaro Linux (based on Arch Linux).
(Note: not tested since 2018-Apr-19)
Manjaro requires these changes:1) Instead of apt-get, use pacman with these packages:
# Install libraries and tools
sudo pacman -S --needed libx11 gtk2 gdk-pixbuf2 cairo pango libxtst atk freeglut
sudo pacman -S --needed git subversion make gdb zip unzip unrar wget
sudo pacman -S --needed android-tools apache-ant jdk8-openjdk
2) #Install SDK packages and NDK using sdkmanager
In my test the NDK was not installing and sdkmanager gave an error "No space left on device". By default /tmp is a tmpfs limited to half the size of your RAM, if your RAM size is small, you may have to temporarily unmount /tmp from tmpfs before installing sdk/ndk packages:
sudo umount -l /tmp
(remember to manually delete files in /tmp before rebooting)
3) The PATH environment is setup in a different file:
# Use a text editor to open $HOME/.bash_profile and add this text below:
# example: kate $HOME/.bash_profile
export PATH="${PATH}:${HOME}/android/ndk-toolchain"
export PATH="${PATH}:${HOME}/android/gradle-4.10.3/bin"
export ANDROID_SDK_ROOT="$HOME/android/sdk"
4) When setting LAMW paths, the JDK has a different path on Manjaro
# Select Tools menu > [Lamw] Android Module Wizard > Paths Settings: [Jdk, Sdk, Ndk, ...]:
...
# Path to Java JDK: /usr/lib/jvm/java-8-openjdk
Comments for 2019-May-20 ver 1.3> 24. #Install SDK packages and NDK
When installing the NDK using sdkmanager, you cannot select an older version, it installs the latest version.
> 26. ./sdkmanager "platforms;android-26" "build-tools;26.0.3" "tools" "ndk-bundle" "extras;android;m2repository"
I chose to install Android platform 26. A given Android platform also supports previous API Levels. (
usage stats for Andriod API Levels). As of gradle plugin 3.0.0, the appropriate build-tools package is automatically downloaded if needed during the gradle build, but I included it here to work around a LAMW issue. To view a list of available packages use ./sdkmanager --list
> 35. # download and extract Gradle 4.10.3
note to self: LAMW uses the Gradle directory name internally to determine the Gradle version
> 42. # Use a text editor to open $HOME/.profile and add this text below:
.profile seems to be the proper file for this on Ubuntu(s). .bashrc gets re-run for every subshell which creates multiple path entries.
(NOTE: .profile is not called if ~/.bash_profile or ~./bash_login exist)
> 51. # Download FPCUPdeluxe
If the latest version of FPCUPdeluxe doesn't build FPC/Lazarus successfully (particularly if you're using stable/stable), try the same version that I tested.
> 59. # 1) On "Basic" tab, select FPC version "fixes3.2" & Lazarus version "fixes2.0"
Originally I used trunk for both FPC and Lazarus in order to work with the most current code. Depending the state of Lazarus/FPC in regards to bugs and ARM/Android issues, you may have to use different versions. As of 2019-May-20, FPC trunk is causing a "buffer error" when starting Lazarus. I switched to the latest "fixes" versions of both FPC and Lazarus which are newer than "stable", but more stable than "trunk". There are some android related bugs fixed in FPC development version 3.1.1 and later (
see here).
> 62. # 4) On Modules tab, select LAMW, Install module
Installing LAMW from FPCUPdeluxe pulls from GIT. Do this anytime you want to update LAMW to the latest code.
2019-May-20Building a simple test project:Project | New Project...
LAMW [GUI] Android Module
Set project folder, (ex. /home/user/test)
Automated Build = Gradle
For 32-bit: Architecture/Instructions = ARMv7a + VFPv3
For 64-bit: Architecture/Instructions = Aarch64
Use defaults for other settings
Click OK
Click Save if prompted to save files
Drop a label, edit box, button on the form from Android Bridge Component Tab (jTextView, jEditText, jButton)
Run | Build
From a command line run "gradle_local_build.sh" from the project folder
if successful, your compiled APK files are in ./build/outputs/apk
Installing and Using the Android Emulator:(the method described here uses the command line, another method is to install
Android Studio)
#Install the emulator and a system image
cd ~/android/sdk/tools/bin
./sdkmanager "emulator" "system-images;android-24;default;armeabi-v7a"
(to get a list of system images use ./sdkmanager --list)
#Create some android virtual devices (AVD)
#generic test device
./avdmanager create avd -n "my_test_device" -k "system-images;android-24;default;armeabi-v7a"
#Galaxy Nexus device
./avdmanager create avd -n "Galaxy_Nexus" -d "Galaxy Nexus" -k "system-images;android-24;default;armeabi-v7a"
(to get a list of devices use ./avdmanager list devices)
(after creation, AVD files are stored in: ~/.android/avd/)
#Run the emulator
cd ~/android/sdk/emulator
./emulator -no-snapshot-load -avd "my_test_device" -use-system-libs -gpu swiftshader_indirect
(to get a list of available AVDs, use ./emulator -list-avds)
(note: I had to use -gpu swiftshader_indirect to enable software rendering since I am running inside a virtual machine, more info
here. Inside my VM the emulator was running slow, so if you get any android "Process isn't responding" messages, click "Wait". The emulator was unstable when loading from a snapshot, the workaround is to use -no-snapshot-load)
#Run your project in the emulator:
From a command line run "gradle_local_run.sh",
or from the Lazarus IDE menu select Run | [LAMW] Build Android Apk and Run
How to build demos(still working on it. but have had some success by doing steps below as a 32-bit example):
Open a demo project and change
In
Project | Project Options | Compiler Options | PathsLibraries:/home/[user]/android/sdk/ndk-bundle/platforms/android-27/arch-arm/usr/lib/;/home/[user]/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/(remove [user] and replace with your user name)
Target File name:../libs/armeabi-v7a/libcontrolsIn
Project | Project Options | Compiler Options | Custom Options-Xd -CfVFPv3 -CpARMV7A -XParm-linux-androideabi- -FD/home/[user]/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin(remove [user] and replace with your user name)
Run
gradle_local_build.sh from a command line.