Skip to content

Commit 3748e21

Browse files
Merge PR: cmp-paycraft 2.0.8 — androidx-startup Initializer
2 parents 552e7b1 + 8db3e26 commit 3748e21

4 files changed

Lines changed: 75 additions & 1 deletion

File tree

cmp-paycraft/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ kotlin {
9090
androidMain.dependencies {
9191
implementation(libs.ktor.client.cio)
9292
implementation("androidx.security:security-crypto:1.1.0-alpha06")
93+
// androidx-startup hands the Application Context to PayCraftInitializer
94+
// before Application.onCreate runs — see PayCraftInitializer.kt.
95+
implementation("androidx.startup:startup-runtime:1.2.0")
9396
}
9497

9598
iosMain.dependencies {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<!--
6+
androidx-startup wiring for PayCraftInitializer.
7+
8+
The InitializationProvider node is contributed by the androidx.startup:
9+
startup-runtime library when it's on the consumer's classpath. We merge
10+
a single <meta-data> entry referencing our Initializer so the AndroidX
11+
Startup framework hands the Application Context to PayCraftPlatform
12+
before the consumer's Application.onCreate runs — no consumer-side
13+
PayCraftPlatform.init(applicationContext) call needed.
14+
15+
See PayCraftInitializer.kt for the opt-out pattern.
16+
-->
17+
<application>
18+
<provider
19+
android:name="androidx.startup.InitializationProvider"
20+
android:authorities="${applicationId}.androidx-startup"
21+
android:exported="false"
22+
tools:node="merge">
23+
<meta-data
24+
android:name="com.mobilebytelabs.paycraft.PayCraftInitializer"
25+
android:value="androidx.startup" />
26+
</provider>
27+
</application>
28+
</manifest>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.mobilebytelabs.paycraft
2+
3+
import android.content.Context
4+
import androidx.startup.Initializer
5+
6+
/**
7+
* androidx-startup [Initializer] that wires the Android application Context
8+
* into [PayCraftPlatform] at app start — BEFORE `Application.onCreate` runs.
9+
*
10+
* Why this exists:
11+
*
12+
* With this initializer the consumer's `Application.onCreate` only needs to
13+
* call `PayCraft.initialize(apiKey)` from commonMain. The Android-specific
14+
* Context handoff happens automatically via the AndroidX Startup framework
15+
* — no platform-specific bootstrap leaks into the consumer's androidMain.
16+
*
17+
* Disabling:
18+
*
19+
* Most apps don't need to. If a host app wants to delay or skip the
20+
* handoff (e.g. lazy bootstrap for cold-start optimisation), they can
21+
* remove the manifest provider node via tools:node="remove":
22+
*
23+
* ```xml
24+
* <provider
25+
* android:name="androidx.startup.InitializationProvider"
26+
* android:authorities="${applicationId}.androidx-startup"
27+
* android:exported="false"
28+
* tools:node="merge">
29+
* <meta-data
30+
* android:name="com.mobilebytelabs.paycraft.PayCraftInitializer"
31+
* tools:node="remove" />
32+
* </provider>
33+
* ```
34+
*
35+
* …and then call `PayCraftPlatform.init(applicationContext)` themselves.
36+
*/
37+
class PayCraftInitializer : Initializer<Unit> {
38+
override fun create(context: Context) {
39+
PayCraftPlatform.init(context.applicationContext)
40+
}
41+
42+
override fun dependencies(): List<Class<out Initializer<*>>> = emptyList()
43+
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ org.jetbrains.compose.experimental.macos.enabled=true
1414
android.useAndroidX=true
1515
android.nonTransitiveRClass=true
1616
#Publishing
17-
paycraft.version=2.0.7
17+
paycraft.version=2.0.8
1818
SONATYPE_HOST=CENTRAL_PORTAL
1919
SONATYPE_AUTOMATIC_RELEASE=true

0 commit comments

Comments
 (0)