Skip to content

Commit 853ac3a

Browse files
authored
Adds support to build as an Android module (#184)
* updates * maven local publish * both artifacts into h3 but still creating h3-android when publishing * manual delete of the intermediary local library * no intermediary step * h3-android path * arm arch support * version stuff
1 parent 1c4df54 commit 853ac3a

File tree

4 files changed

+186
-3
lines changed

4 files changed

+186
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ The public API of this library consists of the public functions declared in
55
file [H3Core.java](./src/main/java/com/uber/h3core/H3Core.java), and support
66
for the Linux x64 and Darwin x64 platforms.
77

8+
## Unreleased Changes
9+
### Changed
10+
- Added option to build and publish as an Android module into h3-android
11+
812
## [4.3.1] - 2025-08-27
913
### Changed
1014
- Upgraded build process for Android 16kb support. (#181)

build.gradle

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import com.vanniktech.maven.publish.JavadocJar
33

44
buildscript {
55
repositories {
6+
google()
67
mavenCentral()
78
jcenter()
89
}
10+
911
}
1012

1113
plugins {
@@ -18,6 +20,7 @@ plugins {
1820
id 'com.diffplug.spotless' version '7.2.1'
1921
id 'com.github.nbaztec.coveralls-jacoco' version '1.2.20'
2022
id 'com.vanniktech.maven.publish' version '0.34.0'
23+
2124
}
2225

2326
group = 'com.uber'
@@ -29,6 +32,7 @@ java {
2932
}
3033

3134
repositories {
35+
google()
3236
mavenCentral()
3337
}
3438

@@ -81,6 +85,16 @@ task buildH3(type: Exec) {
8185
outputs.dir("${projectDir}/src/main/resources")
8286
}
8387

88+
// Task to build H3 native code for Android only
89+
task buildH3Android(type: Exec) {
90+
workingDir "${projectDir}"
91+
commandLine './src/main/c/h3-java/build-h3.sh', h3GitRemote, h3GitReference, 'true',
92+
h3SystemPrune, h3DockcrossTag, 'android-arm android-arm64',
93+
h3GithubArtifactsUse, h3GithubArtifactsByRun
94+
dependsOn compileJava
95+
outputs.dir("${projectDir}/src/main/resources")
96+
}
97+
8498
processResources {
8599
dependsOn buildH3
86100
}
@@ -113,6 +127,86 @@ jar {
113127
duplicatesStrategy = DuplicatesStrategy.WARN
114128
}
115129

130+
// Android-specific configurations
131+
configurations {
132+
androidCompile
133+
androidRuntime
134+
}
135+
136+
// Android compilation task - compiles Java without native build
137+
task compileAndroidJava(type: JavaCompile) {
138+
source = sourceSets.main.java
139+
classpath = sourceSets.main.compileClasspath
140+
destinationDirectory = file("${buildDir}/android-classes")
141+
options.compilerArgs += ['-h', "${projectDir}/src/main/c/h3-java/src"]
142+
}
143+
144+
// Android JAR task - creates JAR with only Android native libraries
145+
task androidJar(type: Jar) {
146+
dependsOn compileAndroidJava
147+
archiveBaseName = 'h3-android'
148+
archiveVersion = project.version
149+
150+
from compileAndroidJava.destinationDirectory
151+
from(sourceSets.main.resources) {
152+
include 'android-arm/**'
153+
include 'android-arm64/**'
154+
include 'META-INF/**'
155+
}
156+
157+
duplicatesStrategy = DuplicatesStrategy.WARN
158+
159+
manifest {
160+
attributes(
161+
'Implementation-Title': 'H3 Android',
162+
'Implementation-Version': project.version,
163+
'Implementation-Vendor': 'Uber Technologies, Inc.'
164+
)
165+
}
166+
}
167+
168+
// Generate AndroidManifest.xml
169+
task generateAndroidManifest {
170+
def manifestFile = file("${buildDir}/android/AndroidManifest.xml")
171+
outputs.file manifestFile
172+
173+
doLast {
174+
manifestFile.parentFile.mkdirs()
175+
manifestFile.text = '''<?xml version="1.0" encoding="utf-8"?>
176+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
177+
package="com.uber.h3core">
178+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="34" />
179+
</manifest>'''
180+
}
181+
}
182+
183+
// Android AAR task - creates AAR file
184+
task androidAar(type: Zip) {
185+
dependsOn androidJar, generateAndroidManifest
186+
archiveBaseName = 'h3-android'
187+
archiveVersion = project.version
188+
archiveExtension = 'aar'
189+
190+
// Map android-arm to armeabi-v7a (32-bit ARM)
191+
from('src/main/resources/android-arm') {
192+
into 'jni/armeabi-v7a'
193+
}
194+
195+
// Map android-arm64 to arm64-v8a (64-bit ARM)
196+
from('src/main/resources/android-arm64') {
197+
into 'jni/arm64-v8a'
198+
}
199+
200+
from(androidJar.outputs.files) {
201+
rename { 'classes.jar' }
202+
}
203+
204+
// Create AndroidManifest.xml for AAR
205+
from(generateAndroidManifest.outputs.files) {
206+
into '/'
207+
}
208+
}
209+
116210
mavenPublishing {
117211
coordinates(project.group, "h3", project.version)
118212

@@ -160,3 +254,89 @@ mavenPublishing {
160254
sourcesJar {
161255
dependsOn buildH3
162256
}
257+
258+
259+
260+
// Android sources JAR
261+
task androidSourcesJar(type: Jar) {
262+
archiveBaseName = 'h3-android'
263+
archiveVersion = project.version
264+
archiveClassifier = 'sources'
265+
266+
from sourceSets.main.allSource
267+
}
268+
269+
270+
// Android-specific publishing configuration
271+
publishing {
272+
publications {
273+
androidMaven(MavenPublication) {
274+
groupId = project.group
275+
artifactId = 'h3-android'
276+
version = project.version
277+
278+
artifact androidAar
279+
artifact androidSourcesJar
280+
281+
// Generate POM for Android
282+
pom {
283+
name = 'h3'
284+
description = 'H3 library with Android support - hierarchical hexagonal geospatial indexing system.'
285+
url = 'https://github.com/uber/h3-java'
286+
287+
licenses {
288+
license {
289+
name = 'The Apache License, Version 2.0'
290+
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
291+
distribution = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
292+
}
293+
}
294+
295+
organization {
296+
name = 'Uber Open Source'
297+
url = 'https://github.com/uber/'
298+
}
299+
300+
developers {
301+
developer {
302+
id = 'isaacbrodsky'
303+
name = 'Isaac Brodsky'
304+
305+
}
306+
}
307+
308+
scm {
309+
url = 'http://github.com/uber/h3-java/tree/master'
310+
connection = 'scm:git:git://github.com/uber/h3-java.git'
311+
developerConnection = 'scm:git:ssh://[email protected]/uber/h3-java.git'
312+
}
313+
}
314+
}
315+
}
316+
317+
repositories {
318+
mavenLocal()
319+
}
320+
}
321+
322+
// Convenience tasks
323+
task buildAndroid {
324+
dependsOn androidAar, androidJar, androidSourcesJar
325+
description = 'Build all Android artifacts'
326+
group = 'build'
327+
}
328+
329+
task publishAndroidLocal {
330+
dependsOn publishAndroidMavenPublicationToMavenLocal
331+
description = 'Publish Android artifacts to local repository in dedicated h3-android directory'
332+
group = 'publishing'
333+
334+
doLast {
335+
def m2Repo = "${System.getProperty('user.home')}/.m2/repository"
336+
def androidDir = "${m2Repo}/com/uber/h3-android/${project.version}"
337+
338+
if (file(androidDir).exists()) {
339+
println "Published Android artifacts to com/uber/h3-android/${project.version}/"
340+
}
341+
}
342+
}

gradle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
org.gradle.configuration-cache=false
66

77
# No spaces on the following line, needed by release.yml:
8-
version=4.3.1
9-
8+
version=4.3.2-SNAPSHOT

src/main/c/h3-java/build-h3.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ if ! command -v docker; then
179179
fi
180180

181181
# Needed for older versions of dockcross
182-
UPGRADE_CMAKE=true
182+
UPGRADE_CMAKE=false
183183
CMAKE_ROOT=target/cmake-3.23.2-linux-x86_64
184184
mkdir -p $CMAKE_ROOT
185185

0 commit comments

Comments
 (0)