Skip to content

Commit 590a318

Browse files
committed
Custom prefab build for Android.
1 parent 408ee30 commit 590a318

File tree

14 files changed

+113
-35
lines changed

14 files changed

+113
-35
lines changed

.cargo/config.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,26 @@ rustflags = [
5252
"-C", "link-arg=-mmacosx-version-min=10.13",
5353
]
5454

55+
56+
# For Android, it is important to set the soname.
57+
# Otherwise, the linker hardcodes the path in the lib,
58+
# which breaks loading.
59+
[target.aarch64-linux-android]
60+
rustflags = [
61+
"-C", "link-arg=-Wl,-soname,libpowersync.so",
62+
]
63+
64+
[target.armv7-linux-androideabi]
65+
rustflags = [
66+
"-C", "link-arg=-Wl,-soname,libpowersync.so",
67+
]
68+
69+
[target.x86_64-linux-android]
70+
rustflags = [
71+
"-C", "link-arg=-Wl,-soname,libpowersync.so",
72+
]
73+
74+
[target.i686-linux-android]
75+
rustflags = [
76+
"-C", "link-arg=-Wl,-soname,libpowersync.so",
77+
]

.github/workflows/android.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ jobs:
1717
distribution: "temurin"
1818
java-version: "17"
1919

20-
- uses: nttld/setup-ndk@v1
21-
with:
22-
ndk-version: r26
23-
2420
- name: Validate Gradle wrapper
2521
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3
2622

.github/workflows/release.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ jobs:
4545
distribution: "temurin"
4646
java-version: "17"
4747

48-
- uses: nttld/setup-ndk@v1
49-
with:
50-
ndk-version: r26
51-
5248
- name: Setup
5349
run: |
5450
rustup toolchain install nightly-2024-05-18-x86_64-unknown-linux-gnu

RELEASING.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ Bump the version number in these places:
55
1. Cargo.toml
66
2. powersync-sqlite-core.podspec.
77
3. android/build.gradle.kts
8-
4. build-pod.sh - CFBundleVersion and CFBundleShortVersionString.
9-
5. `cargo build` to update Cargo.lock
8+
4. android/src/prefab/prefab.json
9+
5. build-pod.sh - CFBundleVersion and CFBundleShortVersionString.
10+
6. `cargo build` to update Cargo.lock
1011

1112
Create a tag:
1213

android/build.gradle.kts

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import java.util.Base64
22

33
plugins {
4-
id("com.android.library") version "8.0.1"
54
id("maven-publish")
65
id("signing")
76
}
@@ -15,7 +14,7 @@ repositories {
1514
google()
1615
}
1716

18-
val buildRust = tasks.register("buildRust", Exec::class.java) {
17+
val buildRust = tasks.register<Exec>("buildRust") {
1918
workingDir("..")
2019
commandLine(
2120
"cargo",
@@ -38,36 +37,39 @@ val buildRust = tasks.register("buildRust", Exec::class.java) {
3837
)
3938
}
4039

41-
android {
42-
compileSdk = 33
43-
44-
namespace = "co.powersync.sqlitecore"
40+
val prefabAar = tasks.register<Zip>("prefabAar") {
41+
dependsOn(buildRust)
4542

46-
defaultConfig {
47-
minSdk = 21
43+
from("build/intermediates/jniLibs") {
44+
include("**/*")
45+
into("jni")
4846
}
4947

50-
sourceSets {
51-
getByName("main") {
52-
jniLibs.srcDir("build/intermediates/jniLibs")
53-
}
48+
from("src/") {
49+
include("**/*")
5450
}
5551

56-
buildTypes {
57-
release {
58-
isMinifyEnabled = false
59-
}
60-
}
52+
val architectures = listOf(
53+
"armeabi-v7a",
54+
"arm64-v8a",
55+
"x86",
56+
"x86_64"
57+
)
6158

62-
publishing {
63-
singleVariant("release") {
64-
withSourcesJar()
59+
architectures.forEach { architecture ->
60+
from("build/intermediates/jniLibs/$architecture/") {
61+
include("libpowersync.so")
62+
into("prefab/modules/powersync/libs/android.$architecture/")
6563
}
6664
}
65+
66+
archiveFileName.set("build/outputs/powersync-sqlite-core.aar")
67+
destinationDirectory.set(file("./"))
6768
}
6869

69-
tasks.named("preBuild") {
70-
dependsOn(buildRust)
70+
val sourcesJar = tasks.register<Jar>("sourcesJar") {
71+
// We don't have any actual java sources to bundle
72+
archiveClassifier.set("sources")
7173
}
7274

7375
publishing {
@@ -78,7 +80,13 @@ publishing {
7880
version = project.version.toString()
7981

8082
afterEvaluate {
81-
from(components["release"])
83+
artifact(prefabAar) {
84+
extension = "aar"
85+
}
86+
87+
artifact(sourcesJar) {
88+
classifier = "sources"
89+
}
8290
}
8391

8492
pom {
@@ -147,5 +155,5 @@ signing {
147155
}
148156

149157
tasks.withType<AbstractPublishToMaven>() {
150-
dependsOn("assembleRelease")
158+
dependsOn(prefabAar)
151159
}

android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

android/src/AndroidManifest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="co.powersync.sqlitecore" >
4+
5+
<uses-sdk android:minSdkVersion="21" />
6+
7+
</manifest>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef POWERSYNC_H
2+
#define POWERSYNC_H
3+
4+
#include "sqlite3.h"
5+
6+
extern "C" int sqlite3_powersync_init(sqlite3 *db, char **pzErrMsg,
7+
const sqlite3_api_routines *pApi);
8+
9+
#endif
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"abi": "arm64-v8a",
3+
"api": 21,
4+
"ndk": 25,
5+
"stl": "none",
6+
"static": false
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"abi": "armeabi-v7a",
3+
"api": 21,
4+
"ndk": 25,
5+
"stl": "none",
6+
"static": false
7+
}

0 commit comments

Comments
 (0)