Skip to content

AGP 9.0+ Compatibility Crash: Unable to find method setTargetSdk in library module #41

Description

@andreagobbetto

When migrating an Ionic/Capacitor project to Android Gradle Plugin (AGP) 8.1.1 / 9.x, the Android Studio AGP Upgrade Assistant (and Gradle Sync) fails to evaluate the project and crashes with the following error:

Unable to find method '' void com.android.build.api.dsl.LibraryDefaultConfig.setTargetSdk(java.lang.Integer)''

In newer versions of the Android Gradle Plugin (specifically 8.0/9.0+), it is strictly prohibited to define targetSdk / targetSdkVersion inside a library module (com.android.library). The setter method has been completely removed from the AGP API for libraries.

However, the onesignal-capacitor-plugin still explicitly declares targetSdk in its Kotlin DSL build script: File: android/build.gradle.kts (Line 110)

targetSdk = intPropertyOrCatalog("targetSdkVersion", "targetSdk")
When AGP parses this Kotlin DSL line, it attempts to call the setTargetSdk JVM method under the hood, which throws the missing method exception and halts the entire project sync.

Expected Behavior: The plugin's android/build.gradle.kts (and any other Groovy/KTS build scripts) should not declare targetSdk / targetSdkVersion, as library modules do not need a target SDK (they inherit it from the consuming application module).

Steps to Reproduce:

  1. Create a Capacitor project and install @onesignal/capacitor-plugin (v1.1.5 or latest).
  2. Open the android folder in Android Studio.
  3. Attempt to run the AGP Upgrade Assistant to migrate to AGP 8.1.1 or 9.1.1.
  4. The Gradle Sync will crash with the setTargetSdk error.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions