Skip to content

Commit 4e5f686

Browse files
committed
add support for android
1 parent 95e69f2 commit 4e5f686

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

buildSrc/scripts/build.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,28 @@ case "$VTYPE" in
9797
fi
9898
echo "Universal library created at /tmp/imgui/dst/libimgui-java64.dylib successfully"
9999
;;
100+
android)
101+
echo "Running Gradle task for Android..."
102+
./gradlew imgui-binding:generateLibs -Denvs=android -Dfreetype=false
103+
if [ $? -ne 0 ]; then
104+
echo "Gradle task for Android failed"
105+
exit 1
106+
fi
107+
108+
echo "Checking if the generated SO files exists..."
109+
check_file_exists /tmp/imgui/libs/arm64-v8a/libimgui-java64.so
110+
check_file_exists /tmp/imgui/libs/armeabi-v7a/libimgui-java64.so
111+
check_file_exists /tmp/imgui/libs/x86/libimgui-java64.so
112+
check_file_exists /tmp/imgui/libs/x86_64/libimgui-java64.so
113+
114+
echo "Copying the generated SO files to the destination directory..."
115+
cp /tmp/imgui/libs/* /tmp/imgui/dst
116+
if [ $? -ne 0 ]; then
117+
echo "Failed to copy SO files to /tmp/imgui/dst/libimgui-java64.so"
118+
exit 1
119+
fi
120+
echo "SO files copied to /tmp/imgui/dst/<abi> successfully"
121+
;;
100122
*)
101123
echo "Unknown vendor type: $VTYPE"
102124
exit 1

buildSrc/scripts/vendor_freetype.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ case "$VTYPE" in
9898
fi
9999
echo "Universal library created at lib/libfreetype.a"
100100
;;
101+
android)
102+
# Skip freetype building for now because freetype repo doesn't seem to support android builds.
103+
;;
101104
*)
102105
echo "Unknown vendor type: $VTYPE"
103106
exit 1

buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class GenerateLibs extends DefaultTask {
3232
private final String[] buildEnvs = System.getProperty('envs')?.split(',')
3333
private final boolean forWindows = buildEnvs?.contains('windows')
3434
private final boolean forLinux = buildEnvs?.contains('linux')
35+
private final boolean forAndroid = buildEnvs?.contains('android')
3536
private final boolean forMac = buildEnvs?.contains('macos')
3637
private final boolean forMacArm64 = buildEnvs?.contains('macosarm64')
3738

@@ -118,6 +119,12 @@ class GenerateLibs extends DefaultTask {
118119
buildTargets += linux64
119120
}
120121

122+
if (forAndroid) {
123+
buildTargets += new BuildTarget(Os.Android, Architecture.Bitness._32, new String[] {"**/*.c"}, new String[0],
124+
new String[] {"**/*.cpp"}, new String[0], new String[0], "", "-O2 -Wall -D__ANDROID__", "-O2 -Wall -D__ANDROID__",
125+
"-lm -Wl,-z,max-page-size=0x4000 -stdlib=libc++ -lc++_shared");
126+
}
127+
121128
if (forMac) {
122129
buildTargets += createMacTarget(Architecture.x86)
123130
}
@@ -137,12 +144,15 @@ class GenerateLibs extends DefaultTask {
137144
BuildExecutor.executeAnt(jniDir + '/build-windows64.xml', commonParams)
138145
if (forLinux)
139146
BuildExecutor.executeAnt(jniDir + '/build-linux64.xml', commonParams)
147+
if (forAndroid) // Contrary to the name, this builds all four ABIs (arm64, arm, x86, x86_64)
148+
BuildExecutor.executeAnt(jniDir + '/build-android32.xml', commonParams)
140149
if (forMac)
141150
BuildExecutor.executeAnt(jniDir + '/build-macosx64.xml', commonParams)
142151
if (forMacArm64)
143152
BuildExecutor.executeAnt(jniDir + '/build-macosxarm64.xml', commonParams)
144-
145-
BuildExecutor.executeAnt(jniDir + '/build.xml', '-v', 'pack-natives')
153+
// Exclude android because android packages into aar, not jar
154+
if (!forAndroid)
155+
BuildExecutor.executeAnt(jniDir + '/build.xml', '-v', 'pack-natives')
146156

147157
if (forWindows)
148158
checkLibExist("windows64/imgui-java64.dll")

0 commit comments

Comments
 (0)