Skip to content

Commit 5dea390

Browse files
Made Linux setup for Android alot easier and fixed the Asset path. Tested in a fresh Ubuntu VM.
1 parent 3798288 commit 5dea390

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

README.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ cmake --build build -j8 --target run
3131
Linux users will need to install some pre-requisites for this template to compile.
3232

3333
```shell
34-
sudo apt-get update
35-
sudo apt-get install cmake libx11-dev libxfixes-dev libegl-dev libgbm-dev libfontconfig-dev
34+
sudo apt update
35+
sudo apt install cmake libx11-dev libxfixes-dev libegl-dev libgbm-dev libfontconfig-dev
3636
```
3737

3838
# Android
@@ -45,6 +45,45 @@ This template also supports building and running APKs for Android! Setup for thi
4545

4646
To build for Android, you need a few SDKs! [Android Studio](https://developer.android.com/studio) has a good interface for grabbing these, and doubles as a nice tool for inspecting APKs.
4747

48+
49+
### If building on Linux (CLI): Quick setup
50+
If you prefer the command line on Linux, this is a minimal setup that matches the versions this template targets.
51+
52+
```bash
53+
# 1) Base tools
54+
sudo apt update
55+
sudo apt install cmake libx11-dev libxfixes-dev libegl-dev libgbm-dev libfontconfig-dev unzip curl zip ninja-build openjdk-8-jdk adb google-android-cmdline-tools-13.0-installer
56+
57+
# 2) to rule out potential errors, we explicitly tell sdkmanager where to install the Android SDK & NDK
58+
59+
export ANDROID_HOME="$HOME/Android/Sdk"
60+
61+
sdkmanager --sdk_root=$ANDROID_HOME \
62+
"platform-tools" \
63+
"platforms;android-32" \
64+
"build-tools;32.0.0" \
65+
"ndk;25.2.9519653"
66+
67+
# 3) More environment variable setup...:
68+
69+
export ANDROID_SDK_ROOT="$ANDROID_HOME"
70+
export PATH="$ANDROID_HOME/platform-tools:$PATH"
71+
72+
# 5) Point CMake to the NDK and set JAVA_HOME (OpenJDK 8 on Ubuntu)
73+
export ANDROID_NDK_HOME="$ANDROID_HOME/ndk/25.2.9519653"
74+
export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"
75+
76+
# (Optional) Persist these to your shell profile (after install)
77+
echo 'export ANDROID_HOME="$HOME/Android/Sdk"' >> "$HOME/.bashrc"
78+
echo 'export ANDROID_SDK_ROOT="$HOME/Android/Sdk"' >> "$HOME/.bashrc"
79+
echo 'export ANDROID_NDK_HOME="$HOME/Android/Sdk/ndk/25.2.9519653"' >> "$HOME/.bashrc"
80+
echo 'export PATH="$ANDROID_HOME/platform-tools:$PATH"' >> "$HOME/.bashrc"
81+
echo 'export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"' >> "$HOME/.bashrc"
82+
```
83+
84+
### Now you can continue to Android Build section.
85+
86+
4887
### Android SDKs
4988
From [Android Studio](https://developer.android.com/studio), go to Tools->SDK Manager.
5089
- Under SDK Platforms, add **API Level 32**
@@ -102,6 +141,7 @@ mkdir build-android
102141

103142
# Configure the build, I'll often make a .bat file for this configure command
104143
# just to make it easier to do!
144+
105145
cmake -B build-android ^
106146
-G Ninja ^
107147
-DCMAKE_ANDROID_NDK=%ANDROID_NDK_HOME% ^
@@ -110,6 +150,11 @@ cmake -B build-android ^
110150
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a
111151
# Same, but as a single line. Nicer if not using a .bat
112152
cmake -B build-android -G Ninja -DCMAKE_ANDROID_NDK=%ANDROID_NDK_HOME% -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=32 -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a
153+
154+
#Or for Linux:
155+
cmake -B build-android -G Ninja -DCMAKE_ANDROID_NDK=$ANDROID_NDK_HOME -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=32 -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a
156+
157+
113158
# Build an APK, install, and run it
114159
cmake --build build-android -j8 --target run
115160
# Or just build an APK

android/AndroidBuild.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ add_custom_command(
178178
# Assemble the base APK, resources and assets
179179
add_custom_command(
180180
DEPENDS
181-
${CMAKE_SOURCE_DIR}/assets
181+
${CMAKE_SOURCE_DIR}/Assets
182182
${APK_TEMP}/obj/classes.dex
183183
${APK_TEMP}/obj/apk_resources.zip
184184
${APK_TEMP}/obj/AndroidManifest.xml
@@ -188,7 +188,7 @@ add_custom_command(
188188
COMMAND ${AAPT2} link # Link all the files into an APK
189189
-o ${APK_BASE}
190190
--manifest ${APK_TEMP}/obj/AndroidManifest.xml
191-
-A ${CMAKE_SOURCE_DIR}/assets
191+
-A ${CMAKE_SOURCE_DIR}/Assets
192192
-I ${ANDROID_SDK_ROOT}/platforms/android-${CMAKE_SYSTEM_VERSION}/android.jar
193193
${APK_TEMP}/obj/apk_resources.zip
194194
COMMAND cd ${APK_TEMP}/obj

0 commit comments

Comments
 (0)