Skip to content

Commit a8daed4

Browse files
committed
fix(android): Support AGP 9+
Guards apply plugin: 'kotlin-android' because AGP 9 pre-registers the kotlin extension itself (built-in Kotlin support), so a second registration throws Cannot add extension with name 'kotlin'. On AGP 8 the guard is false → unchanged. On AGP 9 the apply is skipped AGP supplies Kotlin compilation via its bundled KGP 2.2.10. Source: https://developer.android.com/build/migrate-to-built-in-kotlin Fixes #815
1 parent 273e4c1 commit a8daed4

3 files changed

Lines changed: 117 additions & 115 deletions

File tree

.github/workflows/main.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ jobs:
3838

3939
verify-android:
4040
runs-on: ubuntu-24.04
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
include:
45+
- agp: '8.13.0'
46+
gradle: '8.14.3'
47+
- agp: '9.1.1'
48+
gradle: '9.3.1'
49+
name: verify-android (AGP ${{ matrix.agp }} / Gradle ${{ matrix.gradle }})
4150
steps:
4251
- uses: actions/checkout@v3
4352
- uses: actions/setup-node@v4
@@ -48,7 +57,12 @@ jobs:
4857
java-version: '21'
4958
distribution: 'zulu'
5059
- run: npm ci
51-
- run: npm run verify:android
60+
- name: Update Gradle wrapper to ${{ matrix.gradle }}
61+
working-directory: android
62+
run: ./gradlew wrapper --gradle-version=${{ matrix.gradle }} --distribution-type=all
63+
- name: Build & test with AGP ${{ matrix.agp }}
64+
working-directory: android
65+
run: ./gradlew clean build test -PagpVersion=${{ matrix.agp }}
5266

5367
verify-ios:
5468
runs-on: macos-15

android/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ buildscript {
1616
mavenCentral()
1717
}
1818
dependencies {
19-
classpath 'com.android.tools.build:gradle:8.13.0'
19+
classpath "com.android.tools.build:gradle:${project.findProperty('agpVersion') ?: '8.13.0'}"
2020
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2121
}
2222
}
2323

2424
apply plugin: 'com.android.library'
25-
apply plugin: 'kotlin-android'
25+
if (project.extensions.findByName('kotlin') == null) {
26+
apply plugin: 'kotlin-android'
27+
}
2628

2729
android {
2830
namespace = "com.capacitorjs.community.plugins.bluetoothle"

0 commit comments

Comments
 (0)