Skip to content

fix(android): update Android template for AGP 9 and API 37.2 - #5906

Open
debanjanbasu wants to merge 4 commits into
DioxusLabs:mainfrom
debanjanbasu:fix/android-agp9-api37
Open

debanjanbasu wants to merge 4 commits into
DioxusLabs:mainfrom
debanjanbasu:fix/android-agp9-api37

Conversation

@debanjanbasu

Copy link
Copy Markdown
Contributor

Summary

Updates the generated Android project template so dx can build Android apps with AGP 9 / Gradle 9.6 and target API 37, whose latest platform is published as minor version 37.2.

  • gen/build.gradle.kts: AGP 8.7.0 → 9.4.0; drops the kotlin-gradle-plugin classpath
  • gen/app/build.gradle.kts.hbs: sets compileSdkMinor = 2 when compileSdk == 37; adds packaging { jniLibs { useLegacyPackaging = true } }; drops the org.jetbrains.kotlin.android plugin and the kotlinOptions block
  • gen/app/src/main/AndroidManifest.xml.hbs: drops android:extractNativeLibs, superseded by packaging.jniLibs.useLegacyPackaging
  • gen/gradle.properties: drops the deprecated android.defaults.buildfeatures.buildconfig flag
  • gen/gradle/wrapper/gradle-wrapper.properties: Gradle 9.1.0 → 9.6.0

The Kotlin Android plugin and kotlinOptions are dropped because AGP 9 enables built-in Kotlin support by default: https://developer.android.com/build/migrate-to-built-in-kotlin

compileSdk is set by the user under [android] in Dioxus.toml (compile_sdk), so this stays opt-in: the template only sets the minor version when compileSdk == 37.

AGP 9.4.0 and Gradle 9.6.0 support API 37.\nSelect the installed 37.2 platform with compileSdkMinor and\nuse AGP's built-in Kotlin support.
Use per-module BuildConfig and JNI packaging DSL.
@debanjanbasu

Copy link
Copy Markdown
Contributor Author

Requesting review from @jkelleyrtp and @ealmloff — fork authors can't request reviewers directly (no push access on this repo), hence the ping. @jkelleyrtp has merged most of the recent Android / CLI-template PRs (#4726 gradle wrapper, #4842 AndroidManifest.xml customization).

Change: Android project template → AGP 9.4 / Gradle 9.6; compileSdkMinor = 2 for API 37 (platform 37.2); Kotlin Android plugin + kotlinOptions dropped per AGP 9's built-in Kotlin support; android:extractNativeLibs replaced by packaging.jniLibs.useLegacyPackaging.

CI: everything green except Lint | Links, which fails on a pre-existing README.md link (notes/translations/ko-kr, status 503; the same URL returns 200 on re-fetch). Unrelated to this diff.

@LucaCappelletti94 LucaCappelletti94 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rather than tagging maintainers to get a review, you could help by reviewing some of the other open PRs (157 of the 165 open PRs have no review yet). Every PR you review moves the queue forward, including your own.

Also, please don't be a meat proxy. The PR body, the commit messages and the review ping read as forwarded agent output whose claims nobody checked. Your fork PR says the change was "Verified with a release dx build", yet the in-tree plugin example no longer builds, CI never runs Gradle, and commit 80b88b6 carries a literal \n in its message. You should read what the agent produces, verify it, and post only what you can stand behind.

You should migrate the in-tree plugin module to AGP 9, as shown below.

 plugins {
-    id("com.android.library") version "8.4.2"
-    kotlin("android") version "1.9.24"
+    id("com.android.library") version "9.4.0"
 }
@@
     defaultConfig {
         minSdk = 24
-        targetSdk = 34
         consumerProguardFiles("consumer-rules.pro")
     }
@@
         targetCompatibility = JavaVersion.VERSION_17
     }
-
-    kotlinOptions {
-        jvmTarget = "17"
-    }
 }

Comment on lines +10 to +14
compileSdk = {{ compile_sdk }}
// API 37's latest platform is published as minor version 37.2.
if (compileSdk == 37) {
compileSdkMinor = 2
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should drop the hardcoded minor version.

AGP 9.4.0 builds compileSdk = 37 against platforms;android-37.0, but this block makes the same build fail with Failed to find target with hash string 'android-37.2' when 37.2 is not installed and SDK auto-download is off, or silently download it otherwise.

Suggested change
compileSdk = {{ compile_sdk }}
// API 37's latest platform is published as minor version 37.2.
if (compileSdk == 37) {
compileSdkMinor = 2
}
compileSdk = {{ compile_sdk }}

debanjanbasu and others added 2 commits October 13, 2026 09:07
The geolocation plugin module applied kotlin("android") and
kotlinOptions, which AGP 9's built-in Kotlin rejects. Remove both
and the library targetSdk, and bump AGP to 9.4.0.

Stop forcing compileSdkMinor = 2 for API 37 so compile_sdk = 37
builds against platforms;android-37.0, the AGP default.

Amp-Thread-ID: https://ampcode.com/threads/T-01a13217-b5a6-7065-a56a-fa4cc484512d
Co-authored-by: Amp <amp@ampcode.com>
AGP resolves compileSdk = 37 to platforms;android-37.0. When a newer
minor release such as android-37.2 is installed, set compileSdkMinor
so the build uses it instead of requiring 37.0.

Also set buildToolsVersion to the newest installed stable build-tools.
AGP ignores versions below its minimum, so older SDKs keep the default.

Previews and release candidates are skipped, and nothing is emitted
when no matching package is installed.

This branch has not been deployed

No deployments
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.

2 participants