Skip to content

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

Open
debanjanbasu wants to merge 1 commit into
DioxusLabs:mainfrom
debanjanbasu:fix/android-agp9-api37
Open

debanjanbasu wants to merge 1 commit into
DioxusLabs:mainfrom
debanjanbasu:fix/android-agp9-api37

Conversation

@debanjanbasu

@debanjanbasu debanjanbasu commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Updates the generated Android project for AGP 9.4.0 / Gradle 9.6.0 and API 37.

Template (packages/cli/assets/android/gen)

  • AGP 8.7.0 → 9.4.0 and Gradle 9.1.0 → 9.6.0. Drops the kotlin-gradle-plugin classpath.
  • Drops the org.jetbrains.kotlin.android plugin and kotlinOptions, since AGP 9 compiles Kotlin itself (built-in Kotlin).
  • Replaces the removed android.defaults.buildfeatures.buildconfig flag by enabling buildConfig for library subprojects. The app module already enables it.
  • Replaces android:extractNativeLibs with packaging.jniLibs.useLegacyPackaging = true, so .so files stay compressed in the APK. Uncompressed page-aligned libraries, AGP's default for minSdk >= 23, make the distributed APK much larger. The built APK still has extractNativeLibs=true.
  • Replaces the deprecated java.srcDirs(...) with java.directories.

SDK selection (packages/cli/src/build/android.rs)

  • compile_sdk defaults to 37 and target_sdk to 36. Since 2026-08-31, Google Play requires new apps and updates to target API 36 (requirements), so the old default of 34 produced apps that cannot be uploaded.
  • No minor version is hardcoded. If a newer minor release of compile_sdk is installed, such as platforms;android-37.2, dx sets compileSdkMinor to it. Otherwise AGP uses its default (android-37.0 for 37).
  • buildToolsVersion is set to the newest installed stable build-tools at or above 36.0.0, AGP 9.4's minimum. AGP ignores lower versions with a warning, so in that case dx emits nothing and lets AGP pick.
  • Previews and release candidates are skipped for both.

Plugin modules

  • When dx copies a plugin's Gradle module into the project, it now also removes the AGP 8 declarations that AGP 9 rejects: kotlin("android") / org.jetbrains.kotlin.android, kotlinOptions, and library targetSdk. Existing AGP 8 plugins keep building.
  • The geolocation example is migrated to AGP 9 and takes compileSdk, compileSdkMinor and buildToolsVersion from the generated :app module.

Testing

CI doesn't run Gradle, so I tested locally (macOS arm64, Android Studio JBR 25, NDK 30.0.16248370, build-tools 36.0.0):

  • Before migrating the plugin module, dx build --android on the geolocation example failed with Cannot add extension with name 'kotlin'. On this branch, debug and release builds succeed.
  • With compile_sdk = 37, builds succeed with only android-37.0, only android-37.2, and both installed. The generated app has no compileSdkMinor, 2, and 2 respectively.
  • On an API 37.2 emulator the example installs and launches, and "Check permissions" returns a status from the Kotlin plugin.
  • cargo test -p dioxus-cli --bin dx build::android covers platform and build-tools selection, including the below-minimum case (only build-tools/35.0.1 installed → no buildToolsVersion), and the AGP 8 normalization.

The branch is squashed to one commit on current main. The tree is unchanged from the reviewed version.

@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 thread packages/cli/assets/android/gen/app/build.gradle.kts.hbs Outdated
Comment thread packages/cli/src/build/android.rs
@debanjanbasu
debanjanbasu force-pushed the fix/android-agp9-api37 branch from 32c1041 to 9c5c784 Compare October 15, 2026 00:19
@debanjanbasu debanjanbasu changed the title fix(android): update Android template for AGP 9 and API 37.2 fix(android): update Android template for AGP 9 and API 37 Oct 15, 2026
@debanjanbasu

Copy link
Copy Markdown
Contributor Author

Before I finalize the Android plugin compatibility policy, should this PR target AGP 10 instead of AGP 9.4? The official roadmap lists AGP 10.0 for late 2026 and describes a broader DSL/API migration, so this would be more than a version bump.

Separately, should dx continue normalizing AGP 8-authored source modules for the AGP 9.4 project, or require plugin authors to migrate? I’m holding off on changing that compatibility path pending reviewer guidance.

@debanjanbasu

Copy link
Copy Markdown
Contributor Author

@LucaCappelletti94, thanks for the direct feedback. You’re right that I should have reviewed other open PRs before asking maintainers for review, and personally checked the claims in this PR instead of forwarding agent-generated text. I’m sorry for that.

I’ve addressed your technical feedback and pushed the AGP 9 module changes; the latest CI run is green. I’ll take responsibility for verifying future PR content and contribute to the review queue before requesting maintainer attention.

@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.

AGP 10 has not yet been released to my knowledge. Google Maven tops out at 9.4.1 stable and 9.5.0-alpha09, and the AGP roadmap asks projects to reach the latest 9.x without deprecation warnings before moving to 10. Therefore, I believe that staying on 9.4 is right for this PR.

Also, I believe that while arguably not the cleanest code, the normalization should stay for the time being. The same roadmap removes the android.builtInKotlin opt-out in AGP 10, so a plugin module that applies kotlin("android") keeps failing there, and stripping it in dx works on both versions. Plugin authors can still migrate their modules, and the in-tree geolocation example shows how.

Comment thread packages/cli/src/build/android.rs Outdated
Comment thread packages/cli/src/build/android.rs
Comment thread examples/01-app-demos/geolocation-native-plugin/Dioxus.toml Outdated
@debanjanbasu

Copy link
Copy Markdown
Contributor Author

Pushed the SDK defaults as part of this PR: compile_sdk now defaults to 37 and target_sdk to 36.

target_sdk = 34 is below what Google Play accepts — since 2026-08-31 new apps and updates must target API 36 (https://developer.android.com/google/play/requirements/target-sdk) — so apps generated with the current default cannot be uploaded. compile_sdk = 34 also made every generated project require platforms;android-34.

37 is the newest platform AGP 9.4 knows, and this PR already builds against the newest installed minor of it. Verified here on a machine that only has platforms;android-37.2 and build-tools;36.0.0: the generated project gets compileSdk = 37, compileSdkMinor = 2, targetSdk = 36, and the APK manifest matches. Both stay configurable in [android].

@debanjanbasu
debanjanbasu force-pushed the fix/android-agp9-api37 branch from 90d3a16 to 3c76850 Compare October 20, 2026 23:48
- AGP 8.7.0 -> 9.4.0, Gradle 9.1.0 -> 9.6.0. Drop the Kotlin Android
  plugin and kotlinOptions, since AGP 9 compiles Kotlin itself.
- Normalize AGP 8 plugin modules when bundling them: remove the Kotlin
  Android plugin, kotlinOptions and library targetSdk.
- Enable BuildConfig for library modules, replacing the removed
  android.defaults.buildfeatures.buildconfig flag.
- Set compileSdkMinor to the newest installed minor of compile_sdk, and
  buildToolsVersion to the newest stable build-tools >= 36.0.0.
- Default compile_sdk to 37 and target_sdk to 36, the minimum Google
  Play accepts.
- Keep native libraries compressed with useLegacyPackaging and replace
  the deprecated java.srcDirs.
- Migrate the geolocation plugin example to AGP 9.
@debanjanbasu
debanjanbasu force-pushed the fix/android-agp9-api37 branch from 3c76850 to 00b6fbe Compare October 22, 2026 22:22

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