Skip to content

Commit ba0e581

Browse files
authored
refactor(android): make sync callback optional (#7)
1 parent 2603a3e commit ba0e581

39 files changed

+484
-800
lines changed
Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish to Maven Central
1+
name: Publish Native Android Library
22

33
on:
44
release:
@@ -9,30 +9,47 @@ jobs:
99
publish-android:
1010
runs-on: ubuntu-latest
1111
permissions: write-all
12-
1312
steps:
14-
- name: Checkout code
15-
uses: actions/checkout@v4
16-
17-
- name: Setup Java
13+
- uses: actions/checkout@v2
14+
- name: set up JDK 17
1815
uses: actions/setup-java@v4
1916
with:
20-
java-version: '21'
17+
java-version: '17'
2118
distribution: 'temurin'
22-
19+
2320
- name: Grant execute permission for gradlew
2421
run: chmod +x ./android/gradlew
2522

26-
- name: Grant execute permission for publish script
23+
- name: Grant execute permission for publishing script
2724
run: chmod +x ./scripts/publish-android.sh
2825

26+
- name: Make local props
27+
run: |
28+
cat << EOF > "./android/local.properties"
29+
centralUsername=${{ secrets.ANDROID_CENTRAL_USERNAME }}
30+
centralPassword=${{ secrets.ANDROID_CENTRAL_PASSWORD }}
31+
sonatypeStagingProfileId=${{ secrets.ANDROID_SONATYPE_STAGING_PROFILE_ID }}
32+
signing.keyId=${{ secrets.ANDROID_SIGNING_KEY_ID }}
33+
signing.password=${{ secrets.ANDROID_SIGNING_PASSWORD }}
34+
signing.key=${{ secrets.ANDROID_SIGNING_KEY }}
35+
EOF
36+
echo "local.properties file has been created successfully."
37+
38+
- name: Assemble release and add artifact to GH Release
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
if: ${{ github.event_name == 'release' }}
42+
run: |
43+
cd android && ./gradlew assembleRelease
44+
gh release upload ${{ github.event.release.tag_name }} ./android/live-update-provider/build/outputs/aar/*.aar
45+
2946
- name: Run publish script
3047
working-directory: ./scripts
3148
env:
32-
ANDROID_OSSRH_USERNAME: ${{ secrets.ANDROID_OSSRH_USERNAME }}
33-
ANDROID_OSSRH_PASSWORD: ${{ secrets.ANDROID_OSSRH_PASSWORD }}
49+
ANDROID_CENTRAL_USERNAME: ${{ secrets.ANDROID_CENTRAL_USERNAME }}
50+
ANDROID_CENTRAL_PASSWORD: ${{ secrets.ANDROID_CENTRAL_PASSWORD }}
3451
ANDROID_SIGNING_KEY_ID: ${{ secrets.ANDROID_SIGNING_KEY_ID }}
3552
ANDROID_SIGNING_PASSWORD: ${{ secrets.ANDROID_SIGNING_PASSWORD }}
36-
ANDROID_SIGNING_KEY: ${{ secrets.ANDROID_SIGNING_SECRET_KEY }}
53+
ANDROID_SIGNING_KEY: ${{ secrets.ANDROID_SIGNING_KEY }}
3754
ANDROID_SONATYPE_STAGING_PROFILE_ID: ${{ secrets.ANDROID_SONATYPE_STAGING_PROFILE_ID }}
3855
run: ./publish-android.sh

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ build/
2121

2222
# Gradle files
2323
.gradle/
24-
**/. gradle/
24+
**/.gradle/
2525
local.properties
26-
gradle-wrapper.jar
2726

2827
# Gradle build cache
2928
.gradle-cache/

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
# Live Updates Provider SDK
22

3-
This repository contains the Live Updates Provider API for Android and iOS, which defines an abstraction layer for live update implementations.
3+
This repository contains the Live Updates Provider API for Android, which defines an abstraction layer for live update implementations.
44

55
## Project Structure
66

77
```
8-
live-updates-provider-sdk/
8+
live-update-provider-sdk/
99
├── android/ # Android implementation
10-
│ ├── live-updates-provider/
10+
│ ├── live-update-provider/
1111
│ └── README.md
12-
└── ios/ # iOS implementation (coming soon)
12+
└── scripts/ # Publishing scripts
1313
```
1414

15-
## Platform Documentation
15+
## Documentation
1616

1717
- [Android Implementation](android/README.md)
18-
- iOS Implementation (coming soon)
1918

2019
## Overview
2120

@@ -31,4 +30,4 @@ Each platform implementation provides a default Ionic provider that integrates w
3130

3231
## License
3332

34-
Copyright © 2024 Ionic
33+
Copyright © 2026 Ionic

android/README.md

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,80 @@
22

33
Android implementation of the Live Updates Provider API, which defines an abstraction layer for live update implementations.
44

5+
## Installation
6+
7+
Add the dependency to your `build.gradle` or `build.gradle.kts`:
8+
9+
**Gradle (Groovy)**
10+
```groovy
11+
dependencies {
12+
implementation 'io.ionic:liveupdateprovider:0.1.0-alpha.1'
13+
}
14+
```
15+
16+
**Gradle (Kotlin DSL)**
17+
```kotlin
18+
dependencies {
19+
implementation("io.ionic:liveupdateprovider:0.1.0-alpha.1")
20+
}
21+
```
22+
523
## Building
624

725
```bash
826
# Build the library
9-
./gradlew :live-updates-provider:build
27+
./gradlew :live-update-provider:build
1028

1129
# Run tests
12-
./gradlew :live-updates-provider:test
30+
./gradlew :live-update-provider:test
1331

1432
# Generate AAR
15-
./gradlew :live-updates-provider:assembleRelease
33+
./gradlew :live-update-provider:assembleRelease
1634
```
1735

1836
The output AAR will be located at:
1937
```
20-
android/live-updates-provider/build/outputs/aar/live-updates-provider-release.aar
38+
android/live-update-provider/build/outputs/aar/live-update-provider-release.aar
2139
```
2240

2341
## Requirements
2442

25-
- Android SDK 21+ (minSdk)
26-
- Kotlin 1.9.25
43+
- Android SDK 24+ (minSdk)
44+
- Kotlin 2.1.0
2745
- Java 17
28-
- Gradle 8.9+
46+
- Gradle 8.13+
2947

3048
## Dependencies
3149

3250
The provider API module depends on:
3351
- AndroidX Core KTX
34-
- Kotlin Coroutines for Android
3552

3653
## Usage
3754

38-
Providers register themselves with the `LiveUpdatesRegistry`:
55+
Providers register themselves with the `LiveUpdateProviderRegistry`:
3956

4057
```kotlin
4158
// Register a provider implementation
42-
LiveUpdatesRegistry.register(myProviderInstance)
59+
LiveUpdateProviderRegistry.register(myProviderInstance)
4360

4461
// Resolve and create a manager
45-
val provider = LiveUpdatesRegistry.require("provider-id") // LiveUpdatesRegistry.resolve("provider-id")
46-
val config = ProviderConfig(mapOf("appId" to "my-app", "channel" to "your-channel"))
62+
val provider = LiveUpdateProviderRegistry.require("provider-id") // LiveUpdateProviderRegistry.resolve("provider-id")
63+
val config = mapOf("appId" to "my-app", "channel" to "your-channel")
4764
val manager = provider.createManager(context, config)
4865

49-
// Sync and check for updates
50-
val result = manager.sync()
51-
if (result.didUpdate) {
52-
val assetsDir = result.latestAppDirectory
53-
}
66+
// Sync (with callback)
67+
manager.sync(object : ProviderSyncCallback {
68+
override fun onSuccess(result: ProviderSyncResult) {
69+
// Check if update was applied
70+
if (result is FederatedCapacitorSyncResult && result.didUpdate) {
71+
val assetsDir = manager.latestAppDirectory
72+
}
73+
}
74+
75+
override fun onFailure(error: LiveUpdateError.SyncFailed) {
76+
// Handle error
77+
}
78+
})
5479
```
5580

5681
## Publishing
@@ -60,23 +85,33 @@ if (result.didUpdate) {
6085
Publish to your local Maven repository for testing:
6186

6287
```bash
88+
export LIVE_UPDATE_PROVIDER_SDK_VERSION=0.1.0-alpha.1
6389
./gradlew publishToMavenLocal
6490
```
6591

6692
### Maven Central
6793

68-
Production releases are automated via CI. The version is managed in `android/package.json`.
69-
70-
1. Update the version in `android/package.json`
71-
2. Create a GitHub release
72-
3. The `publish-android.yml` workflow automatically runs `scripts/publish-android.sh`
73-
4. The script publishes to Maven Central if the version is not already published
94+
Production releases are automated via CI using `.github/workflows/publish-android.yml`.
7495

75-
To manually publish, run the script from the repository root:
96+
**Prerequisites:**
97+
Configure the following GitHub secrets in your repository:
98+
- `ANDROID_CENTRAL_USERNAME` - Maven Central username
99+
- `ANDROID_CENTRAL_PASSWORD` - Maven Central password
100+
- `ANDROID_SONATYPE_STAGING_PROFILE_ID` - Sonatype staging profile ID
101+
- `ANDROID_SIGNING_KEY_ID` - GPG signing key ID
102+
- `ANDROID_SIGNING_PASSWORD` - GPG signing password
103+
- `ANDROID_SIGNING_KEY` - GPG signing key (base64 encoded)
76104

77-
```bash
78-
./scripts/publish-android.sh
79-
```
105+
**Release Process:**
106+
1. Update the version in `android/package.json`
107+
2. Commit and merge changes to the main branch
108+
3. Create a GitHub release with tag matching the version (e.g., `v0.1.0-alpha.1`)
109+
4. The GitHub Actions workflow will:
110+
- Build the Android library
111+
- Upload the AAR artifact to the GitHub release
112+
- Publish the library to Maven Central
113+
114+
The version is read from `android/package.json` and the publish script checks if the version already exists on Maven Central before publishing.
80115

81116
## License
82117

android/build.gradle.kts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
plugins {
2+
id("org.jetbrains.dokka") version "2.0.0"
3+
}
4+
15
buildscript {
26
val kotlinVersion = "2.1.0"
37
extra.apply {
@@ -7,30 +11,38 @@ buildscript {
711
repositories {
812
google()
913
mavenCentral()
14+
maven {
15+
url = uri("https://plugins.gradle.org/m2/")
16+
}
1017
}
11-
18+
1219
dependencies {
13-
if (System.getenv("LIVEUPDATESPROVIDER_PUBLISH") == "true") {
20+
if (System.getenv("LIVE_UPDATE_PROVIDER_PUBLISH") == "true") {
1421
classpath("io.github.gradle-nexus:publish-plugin:2.0.0")
1522
}
1623

24+
classpath("org.jetbrains.dokka:dokka-base:1.9.20")
1725
classpath("com.android.tools.build:gradle:8.13.0")
1826
classpath(kotlin("gradle-plugin", version = kotlinVersion))
27+
classpath(kotlin("serialization", version = kotlinVersion))
1928
}
2029
}
2130

22-
if (System.getenv("LIVEUPDATESPROVIDER_PUBLISH") == "true") {
31+
if (System.getenv("LIVE_UPDATE_PROVIDER_PUBLISH") == "true") {
2332
apply(plugin = "io.github.gradle-nexus.publish-plugin")
24-
apply(from = file("./live-updates-provider/scripts/publish-root.gradle"))
33+
apply(from = file("./live-update-provider/scripts/publish-root.gradle"))
2534
}
2635

2736
allprojects {
2837
repositories {
2938
google()
3039
mavenCentral()
3140
}
41+
42+
apply(plugin = "org.jetbrains.dokka")
3243
}
3344

34-
tasks.register<Delete>("clean") {
35-
delete(rootProject.layout.buildDirectory)
45+
// register Clean task
46+
tasks.register("clean").configure {
47+
delete("build")
3648
}
47.8 KB
Binary file not shown.

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-9.3.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-all.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

android/gradlew

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
3+
plugins {
4+
id("com.android.library")
5+
id("maven-publish")
6+
kotlin("android")
7+
}
8+
9+
if (System.getenv("LIVE_UPDATE_PROVIDER_PUBLISH") == "true") {
10+
apply(from = file("./scripts/publish-module.gradle"))
11+
}
12+
13+
android {
14+
namespace = "io.ionic.liveupdateprovider"
15+
compileSdk = 36
16+
17+
defaultConfig {
18+
minSdk = 24
19+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
20+
}
21+
22+
sourceSets {
23+
getByName("main").java.srcDirs("src/main/kotlin")
24+
getByName("test").java.srcDirs("src/test/kotlin")
25+
}
26+
27+
buildTypes {
28+
getByName("release") {
29+
isMinifyEnabled = false
30+
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
31+
}
32+
}
33+
34+
compileOptions {
35+
sourceCompatibility = JavaVersion.VERSION_17
36+
targetCompatibility = JavaVersion.VERSION_17
37+
}
38+
39+
kotlinOptions {
40+
jvmTarget = "17"
41+
}
42+
43+
publishing {
44+
singleVariant("release")
45+
}
46+
}
47+
48+
kotlin {
49+
compilerOptions {
50+
jvmTarget = JvmTarget.JVM_17
51+
}
52+
}
53+
54+
dependencies {
55+
implementation("androidx.core:core-ktx:1.17.0")
56+
testImplementation("junit:junit:4.13.2")
57+
}

android/live-update-provider/consumer-rules.pro

Whitespace-only changes.

0 commit comments

Comments
 (0)