build: AGP 9.4.1 and Gradle 9.6.0 - #2052
Draft
edusperoni wants to merge 9 commits into
Draft
edusperoni wants to merge 9 commits into
edusperoni wants to merge 9 commits into
Conversation
Android Studio now builds with AGP 9.4, whose minimum (and default) Gradle is 9.6.0, and apps pick up these wrapper and plugin versions from the packaged project template. - test-app and root wrappers move to Gradle 9.6.0 (scripts and wrapper jar regenerated by the wrapper task). - NS_DEFAULT_ANDROID_BUILD_TOOLS_VERSION -> 9.4.1 and the default build tools -> 36.0.0, the minimum AGP 9.4 accepts. compileSdk stays at 35 since it decides which APIs the metadata generator exposes to apps. - The com.android.tools:r8 buildscript pin (and NS_DEFAULT_R8_VERSION / -Pr8Version) is dropped: it only existed because the R8 bundled with AGP 8.13 could not read Kotlin 2.4 metadata, and AGP 9.4 bundles a newer R8. - The explicit org.apache.groovy:groovy-all classpath entry dates from the Gradle 7 migration; Gradle 9 ships Groovy 4 itself. - BuildToolTask becomes abstract: Gradle 9 turned JavaExec's injected services into abstract getters, so a concrete subclass no longer compiles. The app module still applies kotlin-android, which AGP 9 rejects; that is addressed in the following commit.
… API
AGP 9 compiles Kotlin itself and fails the build when kotlin-android is
applied, and its new DSL hides the legacy variant API
(android.applicationVariants, android.sdkDirectory, compileSdkVersion)
that the app script relied on. The script is copied into every app, so
it is migrated rather than opting out with android.newDsl=false or
android.builtInKotlin=false.
app/build.gradle:
- Drop `apply plugin: 'kotlin-android'` and `kotlinOptions`; the Kotlin
JVM target already defaults to compileOptions.targetCompatibility (17).
kotlin-parcelize stays, it is a compiler plugin that works with
built-in Kotlin.
- androidComponents.onVariants for the selected build type captures the
compile classpath (for the jar extraction tasks) and the merged ASSETS
artifact (the directory copyMetadata writes into). The classpath is
resolved in afterEvaluate, as before, and is now also an input of
cleanupAllJars so the producers of generated jars on it (the
compile-time R class jar that AGP 9 builds in generate<Variant>RFile)
run first.
- buildMetadata's per-variant task lookups become one lazily resolved
dependsOn over the same task names for the selected build type.
- The SDK directory comes from androidComponents.sdkComponents and the
platform name is built from compileSdk/compileSdkMinor/compileSdkPreview.
- cleanupAllJars, buildMetadata and validateAppIdMatch no longer read
Task.project at execution time. validateAppIdMatch also compared the
namespace against an undefined `appIdentifier`, which threw instead of
warning whenever app.gradle changed applicationId.
runtime/build.gradle:
- getDefaultProguardFile('proguard-android.txt') is rejected by AGP 9;
use proguard-android-optimize.txt (release minification is disabled
for the runtime, so the output is unchanged).
- Library modules have no targetSdk in the AGP 9 DSL; set it for tests
and lint instead.
- Remove createPackageConfigFileTask: it only hooked tasks named
bundleDebug/bundleRelease, which a library module does not have, and
it relied on APIs Gradle 9 removed (Project.exec, archivesBaseName).
- Gradle 9 deprecates resolving an undeclared property from the parent project. The app script, and plugin include.gradle files applied to it, read the root's extra properties that way (outLogger, nativescriptDependencies, getAppResourcesPath, the additional_gradle.properties values, ...). The root now copies its extra properties into each subproject before it is evaluated, the same way it already does for the App_Resources gradle.properties, skipping -P properties so those keep their own value in the subproject. - Dependencies declared with group/name/version maps become single-string coordinates. - The metadata generator's compileKotlin uses compilerOptions instead of kotlinOptions.
Gradle 9 removed the -b/--build-file option and Project.exec. - runTests/runTestsAndVerifyResults ran `gradlew -b runtests.gradle` in test-app. That script is now its own build in test-app/runtests (with a settings.gradle) and is run with `-p runtests`. Its Exec tasks keep test-app as working directory, which the node tools and the nested `gradlew :app:installDebug` depend on. - The CCache version probe used Project.exec, which no longer exists; the surrounding catch turned that into "CCache not found!" on every build. It now uses providers.exec.
AGP 9 deprecates android.enableJetifier (its default is now false and the option goes away in AGP 10) and warns on every build that sets it. Jetifier rewrites pre-AndroidX support-library references in third-party binaries; an app that still depends on a support-library artifact needs android.enableJetifier=true passed as a Gradle property (for example -Pandroid.enableJetifier=true or ~/.gradle/gradle.properties).
The test jobs left org.gradle.caching off because the SBG AST tests ran nested `gradlew -b` builds, which failed with "Build cache controller already set" when the cache was on. Those builds now use `-p` with a settings file (and -b no longer exists in Gradle 9), so the test jobs use the same Gradle settings as the build job.
getPackageVersion and getCommitVersion looked up -PpackageVersion, -PpreReleaseVersion and -PgitCommitVersion through Task.project inside doLast, which Gradle 9 deprecates and Gradle 10 rejects. They are now read when the tasks are configured.
…ator With built-in Kotlin, AGP writes the Kotlin classes to intermediates/built_in_kotlinc/<buildType>/<compile task>/classes rather than KGP's tmp/kotlin-classes/<buildType>. buildMetadata only scanned the latter, so app and plugin Kotlin classes were missing from the metadata and 31 Kotlin specs in the test app failed. Both locations are scanned, so a project module still built by KGP keeps working.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Brings in android-dts-generator 5fcf611 so the submodule no longer trips Gradle's multi-string dependency deprecation, the last one left in the build.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrates the build to what current Android Studio uses: AGP 9.4.1 + Gradle 9.6.0, with no opt-out flags (
android.newDsl,android.builtInKotlinstay at their AGP 9 defaults). Targeted at the 9.2 release. Draft because several items below change what every NativeScript app build sees and need a maintainer decision.The full device suite passes on an API 36 arm64 emulator (
runtestsAndVerifyResults -Pabis=arm64-v8a: 1248 passed, 0 failed), the CI Build job's root./gradlewbuilds all four ABIs,runSbgTestspasses, and--warning-mode allreports 0 Gradle deprecations from this repo and 0 D8 Kotlin-metadata warnings (AGP 9.4.1 bundles R8 9.4.24, so the R8 pin from #2050 is gone).Commits
com.android.tools:r8pin (NS_DEFAULT_R8_VERSION/-Pr8Version, only ever shipped in today's dev builds) and thegroovy-allclasspath entry (a Gradle 7 workaround; Gradle 9 bundles Groovy 4).BuildToolTaskis nowabstract, since Gradle 9 madeJavaExec's injected services abstract.androidComponentsvariant API inapp/build.gradle.kotlin-androidandkotlinOptionsare gone (kotlin-parcelizestays and works).onVariantsfor the selected build type captures the compile classpath andSingleArtifact.ASSETS; the compile classpath is also an input ofcleanupAllJars, because AGP 9 builds the compile-timeR.jaringenerate<Variant>RFileand the build otherwise fails on an implicit dependency. The 19 per-taskfindByNameblocks onbuildMetadataare one lazydependsOn. SDK directory comes fromsdkComponents.sdkDirectory; the platform name is built fromcompileSdk/compileSdkMinor/compileSdkPreview.Task.projectreads at execution time are gone.validateAppIdMatchreferenced an undefinedappIdentifier, so it threw instead of warning wheneverapp.gradleoverrodeapplicationId; fixed. Inruntime/build.gradle:proguard-android.txt→proguard-android-optimize.txt(AGP 9 rejects the old file; minify is off, output unchanged), librarytargetSdkVersion→testOptions/linttargetSdk, andcreatePackageConfigFileTaskdeleted (it hookedbundleDebug/bundleRelease, which don't exist on a library, and used the removedProject.exec).outLogger,nativescriptDependencies,additional_gradle.propertiesvalues, ...) and plugininclude.gradlefiles use too. The root'sallprojects.beforeEvaluatenow copies the root extra properties into each subproject, the same wayuserDefinedGradlePropertiesalready was, skipping-Pnames so they keep precedence. Multi-string dependency notation converted;kotlinOptions→compilerOptionsin the metadata generator.-bis removed in Gradle 9.test-app/runtests.gradlemoved totest-app/runtests/with its ownsettings.gradle, run with-p runtests; its Exec tasks keep test-app as the working directory. The ccache probe usesproviders.exec(under Gradle 9 the oldProject.execcall was silently caught and printed "CCache not found!" on every build).org.gradle.cachinglike the build job. The comment that justified disabling it described the old-bnested builds. Verified locally, not yet on CI.getPackageVersion/getCommitVersionread their-Pproperties at configuration time instead of viaTask.projectindoLast.intermediates/built_in_kotlinc/<buildType>/<task>/classes, nottmp/kotlin-classes.buildMetadatanow scans both, otherwise Kotlin classes are missing from the metadata (31 Kotlin specs failed). This affects every app with Kotlin code.Open questions (shipped-behavior decisions)
android.dependency.useConstraints(most important). AGP 9 defaults it to false, so compile-classpath versions are no longer aligned with runtime-classpath versions. In the test app the compile classpath now resolvescore-ktx 1.2.0/core-runtime 2.1.0while the runtime ships 1.13.0 / 2.2.0 (AGP 8 aligned both). Metadata and SBG jars are built from the compile classpath, so apps can get metadata for older API versions than they ship. Options: setandroid.dependency.useConstraints=truein the shippedgradle.properties(AGP 8 behavior, slower configuration) or accept the drift. Left at the AGP default here.App_Resources/Android/gradle.propertiesdoes not re-enable it (those become extra properties, which AGP never reads); only-P,~/.gradle/gradle.propertiesor a CLI change would. Revert commit 5 if that is too aggressive before AGP 10.include.gradle/ userapp.gradlecompatibility. Anything usingapply plugin: 'kotlin-android',kotlinOptions {},android.applicationVariants/libraryVariants/variantFilterorandroid.sdkDirectorynow fails.android.newDsl=false/android.builtInKotlin=falserestore those until AGP 10, but they are Gradle properties, so an escape hatch would have to be written by the CLI into the generatedplatforms/android/gradle.properties.Rclass is no longer final (android.enableAppCompileTimeRClassdefault true). User Java inApp_Resources/Android/srcthat doesswitchonR.id.*stops compiling. Default kept.uniquePackageNames,defaultTargetSdkToCompileSdkIfUnset(the script always sets targetSdk),onlyEnableUnitTestForTheTestedBuildType,proguard.failOnMissingFiles,r8.strictFullModeForKeepRules,r8.optimizedResourceShrinking(only matter with minify/shrinking on),proguardAndroidTxt.disallowed(the shipped app script references no proguard file).getMergedAssetsOutputPathnow throws a clear error when no variant of the selected build type exists, instead of falling back to an AGP 3.5 path that no longer exists.Not done
Configuration 'debugCompileClasspath' was resolved during configuration timeis an AGP performance warning from the per-jar extraction tasks being created at configuration time (existing design); fixing it means one extraction task at execution time.revertVersionFilehook matches task names containingStrip, while AGP's task isstripReleaseDebugSymbols(lowercase), so the root build leavesruntime/src/main/cpp/Version.hmodified. Not checked whethermainbehaves the same.