From 1fc46d35ee2dd7c83dd2e3c4d17c9e5b494d7405 Mon Sep 17 00:00:00 2001 From: Fadi George Date: Fri, 31 Jul 2026 11:24:17 -0700 Subject: [PATCH 1/3] fix: [SDK-4969] support AGP 9 Android builds Co-authored-by: Cursor --- android/README.md | 4 ++-- android/build.gradle.kts | 18 ++++++++---------- android/gradle/libs.versions.toml | 1 - .../demo-no-location/android/app/build.gradle | 2 +- .../demo-nx/apps/shop/android/app/build.gradle | 2 +- examples/demo/android/app/build.gradle.kts | 2 +- examples/demo_cap7/android/app/build.gradle | 2 +- .../demo_pods/android/app/build.gradle.kts | 2 +- 8 files changed, 15 insertions(+), 18 deletions(-) diff --git a/android/README.md b/android/README.md index de7537a..f5c6989 100644 --- a/android/README.md +++ b/android/README.md @@ -4,7 +4,7 @@ Thin Capacitor wrapper around the OneSignal Android SDK. Designed to be consumed ## Kotlin / AGP toolchain -The plugin module declares its own `buildscript` classpath for the Android Gradle Plugin and the Kotlin Gradle Plugin. This is required because Capacitor 7's host `build.gradle` does not classpath the Kotlin Gradle Plugin for sub-projects; without our own classpath the `kotlin-android` plugin would fail to resolve. +The plugin module declares its own `buildscript` classpath for the Android Gradle Plugin and the Kotlin Gradle Plugin. This is required because Capacitor 7's host `build.gradle` does not classpath the Kotlin Gradle Plugin for sub-projects. Under AGP 8 the module applies `kotlin-android`; under AGP 9 it uses AGP's built-in Kotlin support instead. Defaults live in [`gradle/libs.versions.toml`](gradle/libs.versions.toml): @@ -15,7 +15,7 @@ Host apps that need to pin a different Kotlin compiler can do so via any standar ## SDK levels -`compileSdk`, `minSdk`, and `targetSdk` default to the Capacitor 8 floors (36 / 24 / 36). Host apps override any of them by setting the matching `Version` property through any Gradle property source (`rootProject.ext`, `gradle.properties`, or `-P`) — Capacitor 7 host apps that ship with `variables.gradle` defaults of 35 / 23 / 35 will continue to take precedence over the catalog defaults. +`compileSdk` and `minSdk` default to the Capacitor 8 floors (36 / 24). Host apps override either value by setting the matching `Version` property through any Gradle property source (`rootProject.ext`, `gradle.properties`, or `-P`). The consuming application owns `targetSdk`; AGP 9 no longer exposes it in the Android library DSL. ## Library versions diff --git a/android/build.gradle.kts b/android/build.gradle.kts index c27d0fc..ab5c01c 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -99,23 +99,21 @@ extra["junitVersion"] = junitVersion extra["androidxAppCompatVersion"] = androidxAppCompatVersion apply(plugin = "com.android.library") -apply(plugin = "kotlin-android") -configure { +val androidPluginVersion = com.android.build.api.AndroidPluginVersion.getCurrent() + +// AGP 9 provides Kotlin support itself, while AGP 8 hosts still require this plugin. +if (androidPluginVersion < com.android.build.api.AndroidPluginVersion(9, 0)) { + apply(plugin = "kotlin-android") +} + +configure { namespace = "com.onesignal.capacitor" compileSdk = intPropertyOrCatalog("compileSdkVersion", "compileSdk") defaultConfig { minSdk = intPropertyOrCatalog("minSdkVersion", "minSdk") - @Suppress("DEPRECATION") - targetSdk = intPropertyOrCatalog("targetSdkVersion", "targetSdk") testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } - buildTypes { - getByName("release") { - isMinifyEnabled = false - proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") - } - } compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 diff --git a/android/gradle/libs.versions.toml b/android/gradle/libs.versions.toml index e23c5c2..e3b6cd6 100644 --- a/android/gradle/libs.versions.toml +++ b/android/gradle/libs.versions.toml @@ -26,7 +26,6 @@ junit = "4.13.2" kotlin = "2.2.20" minSdk = "24" onesignal = "5.9.8" -targetSdk = "36" [libraries] androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidxAppCompat" } diff --git a/examples/demo-no-location/android/app/build.gradle b/examples/demo-no-location/android/app/build.gradle index 898b4f0..cdb501b 100644 --- a/examples/demo-no-location/android/app/build.gradle +++ b/examples/demo-no-location/android/app/build.gradle @@ -19,7 +19,7 @@ android { buildTypes { release { minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } diff --git a/examples/demo-nx/apps/shop/android/app/build.gradle b/examples/demo-nx/apps/shop/android/app/build.gradle index 2102dfd..39116f9 100644 --- a/examples/demo-nx/apps/shop/android/app/build.gradle +++ b/examples/demo-nx/apps/shop/android/app/build.gradle @@ -19,7 +19,7 @@ android { buildTypes { release { minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } diff --git a/examples/demo/android/app/build.gradle.kts b/examples/demo/android/app/build.gradle.kts index 7396b28..4e2e94c 100644 --- a/examples/demo/android/app/build.gradle.kts +++ b/examples/demo/android/app/build.gradle.kts @@ -21,7 +21,7 @@ android { buildTypes { release { isMinifyEnabled = false - proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") // Sign release with Android's auto-generated debug keystore so // `assembleRelease` produces an installable app-release.apk for // Appium E2E. Don't ship release builds to users this way. diff --git a/examples/demo_cap7/android/app/build.gradle b/examples/demo_cap7/android/app/build.gradle index 8c0a7f2..cde090c 100644 --- a/examples/demo_cap7/android/app/build.gradle +++ b/examples/demo_cap7/android/app/build.gradle @@ -19,7 +19,7 @@ android { buildTypes { release { minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } diff --git a/examples/demo_pods/android/app/build.gradle.kts b/examples/demo_pods/android/app/build.gradle.kts index db27ea1..dd9404b 100644 --- a/examples/demo_pods/android/app/build.gradle.kts +++ b/examples/demo_pods/android/app/build.gradle.kts @@ -21,7 +21,7 @@ android { buildTypes { release { isMinifyEnabled = false - proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") } } } From 041649fc32895c4aa342623a44bf7bfd7ff50d27 Mon Sep 17 00:00:00 2001 From: Fadi George Date: Fri, 31 Jul 2026 13:09:48 -0700 Subject: [PATCH 2/3] fix: [SDK-4969] bump AGP 9 and Gradle in demo --- examples/demo/android/gradle/libs.versions.toml | 2 +- examples/demo/android/gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/demo/android/gradle/libs.versions.toml b/examples/demo/android/gradle/libs.versions.toml index 31df2a8..240687f 100644 --- a/examples/demo/android/gradle/libs.versions.toml +++ b/examples/demo/android/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -agp = "8.13.0" +agp = "9.1.1" kotlin = "2.1.20" googleServices = "4.4.4" diff --git a/examples/demo/android/gradle/wrapper/gradle-wrapper.properties b/examples/demo/android/gradle/wrapper/gradle-wrapper.properties index 7705927..5f38436 100644 --- a/examples/demo/android/gradle/wrapper/gradle-wrapper.properties +++ b/examples/demo/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-all.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME From bef6546a0c5ade7c95f05c0b47810bc3c05d9498 Mon Sep 17 00:00:00 2001 From: Fadi George Date: Fri, 31 Jul 2026 13:15:58 -0700 Subject: [PATCH 3/3] fix: [SDK-4969] scope Kotlin JVM target to AGP 8 only --- android/build.gradle.kts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/android/build.gradle.kts b/android/build.gradle.kts index ab5c01c..8dd5acd 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -105,6 +105,10 @@ val androidPluginVersion = com.android.build.api.AndroidPluginVersion.getCurrent // AGP 9 provides Kotlin support itself, while AGP 8 hosts still require this plugin. if (androidPluginVersion < com.android.build.api.AndroidPluginVersion(9, 0)) { apply(plugin = "kotlin-android") + + tasks.withType().configureEach { + compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17) + } } configure { @@ -120,10 +124,6 @@ configure { } } -tasks.withType().configureEach { - compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17) -} - repositories { google() mavenCentral()