Skip to content

chore(android): remove targetSdkVersion declarations#8507

Merged
OS-ruimoreiramendes merged 2 commits into
nextfrom
chore/RMET-5256/remove-targetsdkversion
Jun 12, 2026
Merged

chore(android): remove targetSdkVersion declarations#8507
OS-ruimoreiramendes merged 2 commits into
nextfrom
chore/RMET-5256/remove-targetsdkversion

Conversation

@OS-ruimoreiramendes

@OS-ruimoreiramendes OS-ruimoreiramendes commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Description

Remove the explicit targetSdkVersion declarations from Capacitor's Android library modules, the Android template, and the Cordova plugins template. AGP 9 infers targetSdkVersion from compileSdkVersion when unset, so the explicit declarations were redundant.

Reference: RMET-5256

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation
  • Other (CI, chores, etc.)

Rationale / Problems Fixed

AGP 9.0 changed the default behavior so that targetSdkVersion is inferred from compileSdkVersion when not explicitly set (via the android.sdk.defaultTargetSdkToCompileSdkIfUnset property, which flipped
to true by default). With both values aligned at 37 today, the explicit declarations were noise. Removing them simplifies the build configuration without any change in build output, the inferred value matches the previously declared one.

This is a follow-up from the AGP 9 / Gradle 9 upgrade (#8498).

Tests or Reproductions

  • ./gradlew assembleDebug in android/: BUILD SUCCESSFUL
  • ./gradlew :capacitor-android:testDebugUnitTest :capacitor-cordova-android:testDebugUnitTest: BUILD SUCCESSFUL
  • npm run build in cli/: regenerated templates tarballs successfully
  • Generated a fresh Capacitor app with the local CLI, built with ./gradlew assembleDebug: BUILD SUCCESSFUL, and confirmed the merged manifest reports android:targetSdkVersion="37" (inferred from compileSdkVersion)
  • Tested the override path on the same app: adding targetSdkVersion back to variables.gradle and app/build.gradle correctly sets the explicit value in the merged manifest (verified with targetSdkVersion = 35)

Platforms Affected

  • Android
  • iOS
  • Web

@jcesarmobile jcesarmobile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the targetSdkVersion = 37 in variables.gradle, since it's just a variable declaration and not an usage, just in case the user has plugins that haven't been updated yet and they still have something like targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36, so, since targetSdkVersion variable would not be there if we remove it, it will be set to 36.

@OS-ruimoreiramendes

Copy link
Copy Markdown
Contributor Author

I think we should keep the targetSdkVersion = 37 in variables.gradle, since it's just a variable declaration and not an usage, just in case the user has plugins that haven't been updated yet and they still have something like targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36, so, since targetSdkVersion variable would not be there if we remove it, it will be set to 36.

Good point, reverting that one.

@OS-ruimoreiramendes OS-ruimoreiramendes merged commit 908bb1a into next Jun 12, 2026
5 of 6 checks passed
@OS-ruimoreiramendes OS-ruimoreiramendes deleted the chore/RMET-5256/remove-targetsdkversion branch June 12, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants