@@ -3,9 +3,11 @@ import com.vanniktech.maven.publish.JavadocJar
33
44buildscript {
55 repositories {
6+ google()
67 mavenCentral()
78 jcenter()
89 }
10+
911}
1012
1113plugins {
@@ -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
2326group = ' com.uber'
2932}
3033
3134repositories {
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+
8498processResources {
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+
116210mavenPublishing {
117211 coordinates(project. group, " h3" , project. version)
118212
@@ -160,3 +254,89 @@ mavenPublishing {
160254sourcesJar {
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+ }
0 commit comments