Skip to content

Commit 4aeb732

Browse files
authored
Merge pull request #24 from powersync-ja/android-prefab
Custom prefab build for Android
2 parents 408ee30 + 9e03137 commit 4aeb732

File tree

22 files changed

+146
-52
lines changed

22 files changed

+146
-52
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
on:
22
push:
3-
tags:
4-
- "*"
53
name: "android"
64
jobs:
75
build:
@@ -17,10 +15,6 @@ jobs:
1715
distribution: "temurin"
1816
java-version: "17"
1917

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

.github/workflows/ios.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
on:
22
push:
3-
tags:
4-
- "*"
53
name: "ios"
64
jobs:
75
build:

.github/workflows/linux.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
on:
22
push:
3-
tags:
4-
- "*"
53
workflow_dispatch:
64
name: "linux"
75
jobs:

.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

.github/workflows/wasm.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
on:
2+
push:
3+
name: "linux"
4+
jobs:
5+
build_wasm:
6+
name: Basic WASM build
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
with:
11+
submodules: true
12+
13+
- name: Install Rust Nightly
14+
uses: dtolnay/rust-toolchain@stable
15+
with:
16+
toolchain: nightly-2024-05-18
17+
components: rust-src
18+
19+
- name: Build WASM bytecode
20+
run: RUSTFLAGS="--emit=llvm-bc -C linker=/bin/true" cargo build -p powersync_loadable --profile wasm --no-default-features --features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/static sqlite_nostd/omit_load_extension" -Z build-std=panic_abort,core,alloc --target wasm32-unknown-emscripten

.github/workflows/windows.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
on:
22
push:
3-
tags:
4-
- "*"
53
name: "windows"
64
jobs:
75
build_windows:

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ inherits = "release"
2525
lto = false
2626

2727
[workspace.package]
28-
version = "0.2.0"
28+
version = "0.2.1"
2929
edition = "2021"
3030
authors = ["JourneyApps"]
3131
keywords = ["sqlite", "powersync"]

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: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
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
}
87

98
group = "co.powersync"
10-
version = "0.2.0"
9+
version = "0.2.1"
1110
description = "PowerSync Core SQLite Extension"
1211

1312
repositories {
1413
mavenCentral()
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/aar/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,9 @@ signing {
147155
}
148156

149157
tasks.withType<AbstractPublishToMaven>() {
150-
dependsOn("assembleRelease")
158+
dependsOn(prefabAar)
151159
}
160+
161+
tasks.named("build") {
162+
dependsOn(prefabAar)
163+
}

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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"abi": "x86",
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": "x86_64",
3+
"api": 21,
4+
"ndk": 25,
5+
"stl": "none",
6+
"static": false
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"export_libraries": [],
3+
"android": {}
4+
}

android/src/prefab/prefab.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "powersync_sqlite_core",
3+
"schema_version": 2,
4+
"dependencies": [],
5+
"version": "0.2.1"
6+
}

build-pod.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ function createXcframework() {
2828
<key>MinimumOSVersion</key>
2929
<string>11.0</string>
3030
<key>CFBundleVersion</key>
31-
<string>0.2.0</string>
31+
<string>0.2.1</string>
3232
<key>CFBundleShortVersionString</key>
33-
<string>0.2.0</string>
33+
<string>0.2.1</string>
3434
</dict>
3535
</plist>
3636
EOF

powersync-sqlite-core.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'powersync-sqlite-core'
3-
s.version = '0.2.0'
3+
s.version = '0.2.1'
44
s.summary = 'PowerSync SQLite Extension'
55
s.description = <<-DESC
66
PowerSync extension for SQLite.

0 commit comments

Comments
 (0)