Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/of.yml
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,9 @@ jobs:
TARGET: ${{ matrix.cfg.target }}
ARCH: ${{ matrix.cfg.opt }}
ANDROID_SDK_ROOT: $ANDROID_HOME
# keep in sync with apothecary build-android.yml (NDK r29, min API 25);
# cmake.sh resolves $ANDROID_HOME/ndk/$NDK, gradle uses ndkVersion
NDK: "29.0.14206865"
# NDK r30 LTS is installed on ubuntu-24.04 at $ANDROID_HOME/ndk/$NDK.
# cmake.sh uses that path. Gradle ndkVersion matches. Min API stays 25.
NDK: "30.0.16248370"
ANDROID_API: "25"

steps:
Expand Down Expand Up @@ -557,3 +557,6 @@ jobs:
echo "ERROR: Build Failed not found: [$LIB_PATH]"
exit 1
fi

- name: Build Android examples
run: scripts/ci/android/build_examples.sh "$ARCH"
21 changes: 15 additions & 6 deletions docs/android_studio.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ Setting up openFrameworks with Android Studio is fairly straightforward. The bas
- Install the latest version of [Android Studio](https://developer.android.com/studio/index.html) (tested with Android Studio Meerkat | 2024.3.1).

### Select the following to be installed in SDK Manager (options)
- Android SDK 36.0 (or latest) - add any older APIs if targetting
- Build Tools 36.0.0 (or latest)
- NDK 28.0.13004108 (Side by Side)
- Android SDK Platform 34. The template compiles and targets API 34. Install a newer platform as well if an example needs it.
- Build Tools 37.0.0
- NDK r30, side by side package `30.0.16248370` (SDK Manager: NDK (Side by side))
- Android SDK Command Line Tools 19.0 (or latest)
- CMake 3.31.6 (or latest)

## Install openFrameworks
- Download openFrameworks 0.12.1 or later from the [download page](http://openframeworks.cc/download/) or from [github](https://github.com/openframeworks/openFrameworks/).
- If you got openFrameworks from git:
- Run `scripts/android/download_libs.sh` to download libraries.
- If you got openFrameworks from git:
- Run `scripts/android/download_libs.sh` to download the current apothecary `latest` Android libraries (arm64, armv7, and x86_64).
- Use the Project Generator to generate Android Studio project files for android examples.
- In Android Studio, use **Open an existing Android Studio project** and select an openFrameworks example from the `examples/android` folder.
- It will ask you for NDK location, either put the path in `local.properties` or click *Project Structure* and select the NDK location.
Expand Down Expand Up @@ -50,7 +50,7 @@ Press the Play button next to the `androidEmptyExample` shown in the toolbar. It
- The `compileSdkVersion`, `buildToolsVersion`, `minSdkVersion`, `targetSdkVersion` values
in `/addons/ofxAndroid/ofAndroidLib/build.gradle` and `/apps/myApps/androidEmptyExample/build.gradle`

- If you get strange linker errors, make sure you are using NDK version r15c. Newer NDKs might work but usually require some changes.
- If you get strange linker errors, check that Android Studio is using NDK `30.0.16248370`. The template, the core Android project, and the GitHub Android job all pin that version. An older side-by-side NDK will not match this tree.

- If your connected device is not recognized by Android Studio, restart adb
with `adb kill-server && adb start-server`.
Expand All @@ -59,3 +59,12 @@ Press the Play button next to the `androidEmptyExample` shown in the toolbar. It
messages does not solve the problem regarding a missing dependency of the
android API (like for example Android API 22), open the sdk from the console,
select the missing API and install it.

## Rabbit R1

The Rabbit R1 is a small arm64 device with a 320×240 touchscreen and a MediaTek Helio P35. A community Android 13 image can install a normal openFrameworks APK. The stock Rabbit OS is not a build target.

- Generate an example with the Project Generator, then in `ofApp/build.gradle` keep `ndkVersion '30.0.16248370'` and set both `ndk.abiFilters` lines to `'arm64-v8a'`.
- `minSdkVersion 25` is below Android 13, so the package installs.
- Build with `./gradlew assembleDebug`. The debug package is `ofApp-playstore-debug.apk`.
- Sideload with `adb install -r` and that APK. Touch events reach openFrameworks. The scroll wheel does not act as a mouse, and layouts written for a phone will be tight on 320×240.
2 changes: 1 addition & 1 deletion examples/android/androidAccelerometerExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void ofApp::update(){
messages[0] = "g(x) = " + ofToString(accel.x,2);
messages[1] = "g(y) = " + ofToString(accel.y,2);
messages[2] = "g(z) = " + ofToString(accel.z,2);
normAccel = accel.getNormalized();
normAccel = glm::length(accel) > 0 ? glm::normalize(accel) : accel;
}

//--------------------------------------------------------------
Expand Down
22 changes: 22 additions & 0 deletions examples/android/androidGuiExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ void ofApp::dragEvent(ofDragInfo dragInfo){
}

//--------------------------------------------------------------
void ofApp::pause(){
}

void ofApp::stop(){
}

void ofApp::resume(){
}

void ofApp::reloadTextures(){
}

bool ofApp::backPressed(){
return false;
}

void ofApp::okPressed(){
}

void ofApp::cancelPressed(){
}

void ofApp::deviceRefreshRateChanged(int refreshRate) {
}

Expand Down
3 changes: 2 additions & 1 deletion examples/android/androidGuiExample/src/ofApp.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#pragma once

#include "ofMain.h"
#include "ofxAndroid.h"
#include "ofxGui.h"

class ofApp : public ofBaseApp{
class ofApp : public ofxAndroidApp{

public:
void setup();
Expand Down
22 changes: 22 additions & 0 deletions examples/android/androidSwipeExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,28 @@ void ofApp::deviceRefreshRateChangedEvent(int &refreshRate) {
void ofApp::deviceHighestRefreshRateChangedEvent(int &refreshRate) {
}

void ofApp::pause(){
}

void ofApp::stop(){
}

void ofApp::resume(){
}

void ofApp::reloadTextures(){
}

bool ofApp::backPressed(){
return false;
}

void ofApp::okPressed(){
}

void ofApp::cancelPressed(){
}

//--------------------------------------------------------------
void ofApp::exit(){

Expand Down
4 changes: 2 additions & 2 deletions examples/android/androidVBOExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ void ofApp::update(){
int z = (j * space) - center.y;
int index = (j*GRID_WIDTH+i) * LENGTH;

pos[index].set(x, y, z);
pos[index+1].set(x+ofRandom(-r,r), y+ofRandom(-r,r), z+ofRandom(-r,r));
pos[index] = glm::vec3(x, y, z);
pos[index+1] = glm::vec3(x+ofRandom(-r,r), y+ofRandom(-r,r), z+ofRandom(-r,r));
pos[index+1].y -= 1.0;

for (int k=2; k<LENGTH; k++) {
Expand Down
12 changes: 8 additions & 4 deletions libs/openFrameworksCompiled/project/android/cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ APOTHECARY_LEVEL="$(cd "$SCRIPT_DIR/../.." && pwd)"
export MAKE_TARGET="${MAKE_TARGET:-cmake}"
export CPP_STANDARD="${CPP_STANDARD:-23}"
export C_STANDARD="${C_STANDARD:-17}"
# Keep in sync with apothecary (.github/workflows/build-android.yml, configure/android_configure.sh)
export NDK="${NDK:-29.0.14206865}" # pinned NDK (major.minor.build) under $ANDROID_SDK_PATH/ndk
# NDK r30 LTS. ubuntu-24.04 runners install this side-by-side package.
# Prebuilt libs stay the apothecary latest archives.
export NDK="${NDK:-30.0.16248370}" # pinned NDK (major.minor.build) under $ANDROID_SDK_PATH/ndk
export NDK_VERSION_MAJOR="${NDK_VERSION_MAJOR:-${NDK%%.*}}"
export ANDROID_API="${ANDROID_API:-25}" # min compile API (Android 7.1). Not the SDK version.
ANDROID_PLATFORM="android-${ANDROID_API}"
Expand Down Expand Up @@ -96,11 +97,14 @@ else
exit 1
fi

if [ -n "${1:-}" ] && [ -z "${ARCH:-}" ]; then
ARCH="$1"
fi
if [ -z "$ARCH" ] || [ "$ARCH" == "all" ]; then
ARCH="$DEFAULT_ARCHS"
fi

echo "build for architecture(s): $ARCHES"
echo "build for architecture(s): $ARCH"
for ARCHE in $ARCH; do
echo "-------------------------------------"
echo "Building for $ARCHE..."
Expand Down Expand Up @@ -129,7 +133,7 @@ for ARCHE in $ARCH; do
-DCONFIGURATION_BUILD_DIR="$OUTPUT_DIR" \
"$CMAKELISTS_DIR"

ninja -j "$NUM_CORES"
ninja -j "${NUM_CORES:-$PARALLEL_MAKE}"

cd "$SCRIPT_DIR"
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tasks.register("prepareKotlinBuildScriptModel"){}
android {
namespace 'cc.openframeworks.android'
compileSdkVersion 34
ndkVersion '29.0.14206865'
ndkVersion '30.0.16248370'
buildToolsVersion '37.0.0'

defaultConfig {
Expand Down
110 changes: 110 additions & 0 deletions scripts/ci/android/build_examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env bash
# Build examples/android with the Android template and the libraries already
# in libs/. The core .so for $ABI must already exist. Each example is copied
# to apps/myApps, which is gitignored.
set -euo pipefail

ABI="${1:-arm64-v8a}"
shift || true

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
TEMPLATE="$ROOT/scripts/templates/android"
LIB="$ROOT/libs/openFrameworksCompiled/lib/android/${ABI}/libopenFrameworksAndroid.so"

if [[ ! -f "$LIB" ]]; then
echo "Missing $LIB. Build the core for ${ABI} before the examples." >&2
exit 1
fi

if [[ -z "${ANDROID_HOME:-}" && -d "${HOME}/Library/Android/sdk" ]]; then
export ANDROID_HOME="${HOME}/Library/Android/sdk"
fi
export ANDROID_SDK_ROOT="${ANDROID_SDK_ROOT:-${ANDROID_HOME:-}}"

GRADLE_BIN="${GRADLE:-gradle}"
if ! command -v "$GRADLE_BIN" >/dev/null 2>&1; then
echo "gradle is not on PATH. Set GRADLE to a Gradle 8.14 binary." >&2
exit 1
fi

# The template jar is the historical Gradle 2.10 wrapper. `gradle wrapper`
# replaces it with the 8.14.3 jar. Do that once, then copy gradlew and the jar
# into every example. Repeating the wrapper task rechecks services.gradle.org.
WRAPPER_GRADLEW="$ROOT/libs/openFrameworksCompiled/project/android/gradlew"
WRAPPER_JAR="$ROOT/libs/openFrameworksCompiled/project/android/gradle/wrapper/gradle-wrapper.jar"
if [[ ! -x "$WRAPPER_GRADLEW" || ! -f "$WRAPPER_JAR" ]]; then
cache="$ROOT/apps/myApps/.gradle-wrapper"
WRAPPER_GRADLEW="$cache/gradlew"
WRAPPER_JAR="$cache/gradle-wrapper.jar"
fi

failed=()
names=("$@")
if [[ ${#names[@]} -eq 0 ]]; then
for dir in "$ROOT"/examples/android/android*; do
[[ -d "$dir/src" ]] || continue
names+=("$(basename "$dir")")
done
fi

for name in "${names[@]}"; do
example="$ROOT/examples/android/$name"
if [[ ! -d "$example/src" ]]; then
echo "No example source at $example" >&2
exit 1
fi
dest="$ROOT/apps/myApps/$name"
rm -rf "$dest"
mkdir -p "$dest"
cp "$TEMPLATE/build.gradle" "$TEMPLATE/settings.gradle" "$TEMPLATE/gradle.properties" "$TEMPLATE/proguard.cfg" "$dest/"
cp -R "$TEMPLATE/gradle" "$TEMPLATE/ofApp" "$dest/"
cp -R "$example/src" "$dest/src"
if [[ -f "$example/addons.make" ]]; then
cp "$example/addons.make" "$dest/addons.make"
fi
id="$(printf '%s' "$name" | tr '[:upper:]' '[:lower:]')"
perl -i.bak -pe "s/applicationId\\s+\"[^\"]*\"/applicationId \"cc.openframeworks.${id}\"/" "$dest/ofApp/build.gradle"
rm -f "$dest/ofApp/build.gradle.bak"

echo "-----------------------------------------------------------------"
echo "Building $name for $ABI"
# A subshell on the left of || ignores set -e, so run the build as its own
# bash and keep the status.
set +e
bash -c '
set -euo pipefail
cd "$1"
if [[ ! -x "$2" || ! -f "$5" ]]; then
"$6" wrapper --gradle-version 8.14.3
mkdir -p "$(dirname "$2")" "$(dirname "$5")"
cp ./gradlew "$2"
cp ./gradle/wrapper/gradle-wrapper.jar "$5"
chmod +x "$2"
fi
cp "$2" ./gradlew
cp "$5" ./gradle/wrapper/gradle-wrapper.jar
chmod +x ./gradlew
./gradlew assembleDebug -Pandroid.injected.build.abi="$3" --stacktrace
apk=""
while IFS= read -r candidate; do
apk="$candidate"
break
done < <(find ofApp/build -name "*.apk" -type f)
listing="$(unzip -l "$apk" 2>/dev/null || true)"
if [[ -z "$apk" ]] || ! grep -q "lib/${3}/libofApp.so" <<<"$listing"; then
echo "No ${3} APK produced for $4" >&2
exit 1
fi
echo "APK: $1/$apk"
' bash "$dest" "$WRAPPER_GRADLEW" "$ABI" "$name" "$WRAPPER_JAR" "$GRADLE_BIN"
rc=$?
set -e
if [[ $rc -ne 0 ]]; then
failed+=("$name")
fi
done

if [[ ${#failed[@]} -gt 0 ]]; then
echo "Failed examples: ${failed[*]}" >&2
exit 1
fi
Binary file modified scripts/templates/android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
10 changes: 5 additions & 5 deletions scripts/templates/android/ofApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ println "addonFile = ${addonFile.absolutePath}"

// Get all addon paths from addons.make

def ofRoot = "/../../../"
def ofRoot = "../../../"

def addonPaths = []
if (addonFile.exists()) {
addonFile.eachLine { line ->
def addonRelPath = ofRoot + "/addons/" + line.trim()
def addonRelPath = ofRoot + "addons/" + line.trim()
def addonPath = new File(projectRoot, addonRelPath).canonicalFile
println "Resolved addon path: ${addonPath}"
if (addonPath.exists()) {
Expand Down Expand Up @@ -159,8 +159,8 @@ addonPaths.each { addon ->
println "Addon Libraries found: [${addonLibs}]"

// Convert lists to CMake arguments
def cmakeIncludeArgs = "-DADDON_INCLUDE_DIRS=\"" + addonIncludeDirs.join(";") + "\""
def cmakeLibArgs = "-DADDON_LIBS=\"" + addonLibs.join(";") + "\""
def cmakeIncludeArgs = "-DADDON_INCLUDE_DIRS=" + addonIncludeDirs.join(";")
def cmakeLibArgs = "-DADDON_LIBS=" + addonLibs.join(";")
def cmakeSrcArgs = "-DADDON_SOURCES=" + addonSourceFiles.join(";")

println "Found addons: " + addonPaths
Expand All @@ -172,7 +172,7 @@ android {
compileSdkVersion 34
buildToolsVersion '37.0.0'
//ndkPath "/Users/x/android-ndk-r21e" // Point to your own NDK if needed
ndkVersion '29.0.14206865' // keep in sync with apothecary build-android.yml
ndkVersion '30.0.16248370' // NDK r30 LTS, same pin as cmake.sh and the Android CI job
buildFeatures {
prefab true
}
Expand Down
Loading