Skip to content

Commit e9d0f1b

Browse files
committed
feat: add third-party LiveUpdates provider support and upgrade dependencies
- Add support for custom LiveUpdates managers via setLiveUpdateManager() - Upgrade Capacitor from 7.x to 8.x - Upgrade Android compile/target SDK from 35 to 36 - Upgrade Kotlin from 1.9.25 to 2.1.0 - Upgrade Android Gradle Plugin from 8.7.3 to 8.13.0 - Upgrade Gradle from 8.9 to 9.3.1 - Upgrade Java compatibility from 17 to 21 - Bump minimum SDK from 23 to 24 - Add live-updates-provider dependency
1 parent 68d3ac3 commit e9d0f1b

File tree

7 files changed

+87
-31
lines changed

7 files changed

+87
-31
lines changed

IonicPortals/build.gradle.kts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ if (System.getenv("PORTALS_PUBLISH") == "true") {
1010

1111
android {
1212
namespace = "io.ionic.portals"
13-
compileSdk = 35
13+
compileSdk = 36
1414

1515
defaultConfig {
16-
minSdk = 23
16+
minSdk = 24
1717
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
1818
}
1919

@@ -30,11 +30,11 @@ android {
3030
}
3131
}
3232
compileOptions {
33-
sourceCompatibility = JavaVersion.VERSION_17
34-
targetCompatibility = JavaVersion.VERSION_17
33+
sourceCompatibility = JavaVersion.VERSION_21
34+
targetCompatibility = JavaVersion.VERSION_21
3535
}
3636
kotlinOptions {
37-
jvmTarget = "17"
37+
jvmTarget = "21"
3838
}
3939
publishing {
4040
singleVariant("release")
@@ -44,8 +44,9 @@ android {
4444
dependencies {
4545
implementation(kotlin("reflect"))
4646

47-
api("com.capacitorjs:core:[7.0.0,7.1.0)")
47+
api("com.capacitorjs:core:[8.0.0,9.0.0)")
4848
compileOnly("io.ionic:liveupdates:0.5.5")
49+
compileOnly("io.ionic:live-updates-provider:LOCAL-SNAPSHOT")
4950

5051
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
5152
implementation("androidx.core:core-ktx:1.15.0")

IonicPortals/src/main/kotlin/io/ionic/portals/Portal.kt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
package io.ionic.portals
22

33
import android.content.Context
4+
import android.util.Log
5+
import com.getcapacitor.JSObject
46
import com.getcapacitor.Plugin
57
import io.ionic.liveupdates.LiveUpdate
68
import io.ionic.liveupdates.LiveUpdateManager
9+
import io.ionic.liveupdates.data.model.FailResult
10+
import io.ionic.liveupdatesprovider.LiveUpdatesError
11+
import io.ionic.liveupdatesprovider.SyncCallback
12+
import io.ionic.liveupdatesprovider.models.SyncResult
13+
import io.ionic.liveupdatesprovider.LiveUpdatesManager as LiveUpdatesManagerProvider
14+
715

816
/**
917
* A class representing a Portal that contains information about the web content to load and any
@@ -85,6 +93,11 @@ class Portal(val name: String) {
8593
}
8694
}
8795

96+
/**
97+
* A LiveUpdate manager, if live updates is being used.
98+
*/
99+
var liveUpdatesManager: LiveUpdatesManagerProvider? = null
100+
88101
/**
89102
* Whether to run a live update sync when the portal is added to the manager.
90103
*/
@@ -309,6 +322,7 @@ class PortalBuilder(val name: String) {
309322
private var portalFragmentType: Class<out PortalFragment?> = PortalFragment::class.java
310323
private var onCreate: (portal: Portal) -> Unit = {}
311324
private var liveUpdateConfig: LiveUpdate? = null
325+
private var liveUpdatesManager: LiveUpdatesManagerProvider? = null
312326
private var devMode: Boolean = true
313327

314328
internal constructor(name: String, onCreate: (portal: Portal) -> Unit) : this(name) {
@@ -561,6 +575,44 @@ class PortalBuilder(val name: String) {
561575
return this
562576
}
563577

578+
/**
579+
* Set a custom [LiveUpdateManager] instance to be used with the Portal.
580+
*
581+
* Example usage (kotlin):
582+
* ```kotlin
583+
* val liveUpdateManager = LiveUpdateManager()
584+
* builder = builder.setLiveUpdateManager(liveUpdateManager)
585+
* ```
586+
*
587+
* Example usage (java):
588+
* ```java
589+
* LiveUpdateManager liveUpdateManager = new LiveUpdateManager();
590+
* builder = builder.setLiveUpdateManager(liveUpdateManager);
591+
* ```
592+
*
593+
* @param liveUpdateManager a custom LiveUpdateManager instance
594+
* @return the instance of the PortalBuilder with the LiveUpdateManager set
595+
*/
596+
@JvmOverloads
597+
fun setLiveUpdateManager(context: Context, liveUpdatesManager: LiveUpdatesManagerProvider, updateOnAppLoad: Boolean = true): PortalBuilder {
598+
this.liveUpdatesManager = liveUpdatesManager
599+
if (updateOnAppLoad) {
600+
liveUpdatesManager.sync(
601+
callback = object : SyncCallback {
602+
override fun onComplete(result: SyncResult) {
603+
Log.d("TestApplication", "Live Update sync complete. Did update: ${result.didUpdate}, latest app dir: ${result.latestAppDirectory}")
604+
}
605+
606+
override fun onError(error: LiveUpdatesError.SyncFailed) {
607+
Log.e("TestApplication", "Live Update sync failed: ${error.message}")
608+
}
609+
}
610+
611+
)
612+
}
613+
return this
614+
}
615+
564616
/**
565617
* Set development mode on the Portal which will look for a server URL set by the Portals CLI.
566618
* This is set to true by default but can be turned off manually if desired.
@@ -598,6 +650,7 @@ class PortalBuilder(val name: String) {
598650
portal.initialContext = this.initialContext
599651
portal.portalFragmentType = this.portalFragmentType
600652
portal.liveUpdateConfig = this.liveUpdateConfig
653+
portal.liveUpdatesManager = this.liveUpdatesManager
601654
portal.devMode = this.devMode
602655
onCreate(portal)
603656
return portal

IonicPortals/src/main/kotlin/io/ionic/portals/PortalFragment.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ open class PortalFragment : Fragment {
271271
*/
272272
fun reload() {
273273
if(portal?.liveUpdateConfig != null) {
274-
val latestLiveUpdateFiles = LiveUpdateManager.getLatestAppDirectory(requireContext(), portal?.liveUpdateConfig?.appId!!)
274+
val latestLiveUpdateFiles = portal?.liveUpdatesManager?.latestAppDirectory() ?: LiveUpdateManager.getLatestAppDirectory(requireContext(), portal?.liveUpdateConfig?.appId!!)
275275
if (latestLiveUpdateFiles != null) {
276276
if (liveUpdateFiles == null || liveUpdateFiles!!.path != latestLiveUpdateFiles.path) {
277277
liveUpdateFiles = latestLiveUpdateFiles
@@ -285,7 +285,6 @@ open class PortalFragment : Fragment {
285285
bridge?.setServerAssetPath(portal?.startDir!!)
286286
}
287287
}
288-
289288
// Reload the bridge to the existing start url
290289
bridge?.reload()
291290
}
@@ -327,7 +326,7 @@ open class PortalFragment : Fragment {
327326
.addWebViewListeners(webViewListeners)
328327

329328
if (portal?.liveUpdateConfig != null) {
330-
liveUpdateFiles = LiveUpdateManager.getLatestAppDirectory(requireContext(), portal?.liveUpdateConfig?.appId!!)
329+
liveUpdateFiles = portal?.liveUpdatesManager?.latestAppDirectory() ?: LiveUpdateManager.getLatestAppDirectory(requireContext(), portal?.liveUpdateConfig?.appId!!)
331330
bridgeBuilder = if (liveUpdateFiles != null) {
332331
if (config == null) {
333332
val configFile = File(liveUpdateFiles!!.path + "/capacitor.config.json")
@@ -516,4 +515,4 @@ open class PortalFragment : Fragment {
516515
}
517516
}
518517
}
519-
}
518+
}

TestApp/build.gradle.kts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99

1010
android {
1111
namespace = "io.ionic.portals.testapp"
12-
compileSdk = 35
12+
compileSdk = 36
1313

1414
buildFeatures {
1515
buildConfig = true
@@ -18,7 +18,7 @@ android {
1818
defaultConfig {
1919
applicationId = "io.ionic.portals.testapp"
2020
minSdk = 24
21-
targetSdk = 35
21+
targetSdk = 36
2222
versionCode = 1
2323
versionName = "1.0"
2424

@@ -33,22 +33,24 @@ android {
3333
}
3434

3535
compileOptions {
36-
sourceCompatibility = JavaVersion.VERSION_1_8
37-
targetCompatibility = JavaVersion.VERSION_1_8
36+
sourceCompatibility = JavaVersion.VERSION_21
37+
targetCompatibility = JavaVersion.VERSION_21
3838
}
3939

4040
kotlinOptions {
41-
jvmTarget = "1.8"
41+
jvmTarget = "21"
4242
}
4343
}
4444

4545
androidComponents {
4646
onVariants {
47-
it.buildConfigFields.put("PORTALS_KEY", BuildConfigField("String", getPortalsKey(), "portals registration key"))
47+
it.buildConfigFields?.put("PORTALS_KEY", BuildConfigField("String", getPortalsKey(), "portals registration key"))
4848
}
4949
}
5050

5151
dependencies {
52+
implementation("io.ionic:live-updates-provider:LOCAL-SNAPSHOT")
53+
5254
implementation(project(":IonicPortals"))
5355
implementation("androidx.core:core-ktx:1.12.0")
5456
implementation("androidx.fragment:fragment-ktx:1.6.2")
@@ -68,4 +70,4 @@ fun getPortalsKey(): String {
6870
val properties = Properties()
6971
properties.load(FileInputStream(propFile))
7072
return properties.getProperty("portals_key") ?: ""
71-
}
73+
}

TestAppCompose/build.gradle.kts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import com.android.build.api.variant.BuildConfigField
55
plugins {
66
id("com.android.application")
77
id("org.jetbrains.kotlin.android")
8+
id("org.jetbrains.kotlin.plugin.compose")
89
}
910

1011
android {
1112
namespace = "io.ionic.portals.composetestapp"
12-
compileSdk = 35
13+
compileSdk = 36
1314

1415
buildFeatures {
1516
buildConfig = true
@@ -18,7 +19,7 @@ android {
1819
defaultConfig {
1920
applicationId = "io.ionic.portals.composetestapp"
2021
minSdk = 24
21-
targetSdk = 35
22+
targetSdk = 36
2223
versionCode = 1
2324
versionName = "1.0"
2425

@@ -35,18 +36,15 @@ android {
3536
}
3637
}
3738
compileOptions {
38-
sourceCompatibility = JavaVersion.VERSION_1_8
39-
targetCompatibility = JavaVersion.VERSION_1_8
39+
sourceCompatibility = JavaVersion.VERSION_21
40+
targetCompatibility = JavaVersion.VERSION_21
4041
}
4142
kotlinOptions {
42-
jvmTarget = "1.8"
43+
jvmTarget = "21"
4344
}
4445
buildFeatures {
4546
compose = true
4647
}
47-
composeOptions {
48-
kotlinCompilerExtensionVersion = "1.5.15"
49-
}
5048
packaging {
5149
resources {
5250
excludes += "/META-INF/{AL2.0,LGPL2.1}"
@@ -56,7 +54,7 @@ android {
5654

5755
androidComponents {
5856
onVariants {
59-
it.buildConfigFields.put("PORTALS_KEY",
57+
it.buildConfigFields?.put("PORTALS_KEY",
6058
BuildConfigField("String", getPortalsKey(), "portals registration key")
6159
)
6260
}
@@ -88,4 +86,4 @@ fun getPortalsKey(): String {
8886
val properties = Properties()
8987
properties.load(FileInputStream(propFile))
9088
return properties.getProperty("portals_key") ?: ""
91-
}
89+
}

build.gradle.kts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ plugins {
88
}
99

1010
buildscript {
11-
val kotlinVersion = "1.9.25"
11+
//val kotlinVersion = "1.9.25"
12+
val kotlinVersion = "2.1.0"
1213
extra.apply {
1314
set("kotlinVersion", kotlinVersion)
1415
}
@@ -27,9 +28,10 @@ buildscript {
2728
}
2829

2930
classpath("org.jetbrains.dokka:dokka-base:1.7.20")
30-
classpath("com.android.tools.build:gradle:8.7.3")
31+
classpath("com.android.tools.build:gradle:8.13.0")
3132
classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion")
3233
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
34+
classpath("org.jetbrains.kotlin:compose-compiler-gradle-plugin:$kotlinVersion")
3335
}
3436
}
3537

@@ -40,6 +42,7 @@ if (System.getenv("PORTALS_PUBLISH") == "true") {
4042

4143
allprojects {
4244
repositories {
45+
mavenLocal()
4346
google()
4447
mavenCentral()
4548
}
@@ -56,4 +59,4 @@ allprojects {
5659
// register Clean task
5760
tasks.register("clean").configure {
5861
delete("build")
59-
}
62+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Mon May 08 10:58:01 CDT 2023
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)