Skip to content

Upgrade to AGP 9 and enable build and configuration cache#37

Open
Luna712 wants to merge 1 commit intorecloudstream:masterfrom
Luna712:agp9
Open

Upgrade to AGP 9 and enable build and configuration cache#37
Luna712 wants to merge 1 commit intorecloudstream:masterfrom
Luna712:agp9

Conversation

@Luna712
Copy link
Copy Markdown
Contributor

@Luna712 Luna712 commented Apr 27, 2026

Gradle / AGP 9 Migration Notes

I am using this to also document this migration for extension developers, so I am explaining other things that may be needed for them as well. Other than the other potential issues described here, everything else in this should be very similar for most, if not all, other plugin repositories.

Also, you will need to remove requiresResources = true from any subproject's (individual extension's) build.gradle.kts if they do not actually have any resources, or the build will now fail.


GitHub Actions (Configuration Cache)

For configuration cache support in GitHub actions, requires adding a new secret in GitHub settings:

  • GRADLE_ENCRYPTION_KEY

The value to set it to can be generated with:

openssl rand -base64 16

Upgrade Gradle (Required for AGP 9)

For simplicity you can upgrade gradle (which is required for AGP 9) using:

gradle wrapper --gradle-version 9.4.1 --distribution-type bin --gradle-distribution-sha256-sum 2ab2958f2a1e51120c326cad6f385153bb11ee93b3c216c5fccebfdfbb7ec6cb

But first replace gradle-wrapper.properties with this manually for one time consistency:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=2ab2958f2a1e51120c326cad6f385153bb11ee93b3c216c5fccebfdfbb7ec6cb
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Java Version Warnings

If you get many warnings such as:

Android Gradle plugin requires Java 17 to run. You are currently using Java 8

Replace:

fun Project.android(configuration: LibraryExtension.() -> Unit) = extensions.getByName<LibraryExtension>("android").configuration()

with:

fun Project.android(configuration: LibraryExtension.() -> Unit) {
    extensions.getByName<LibraryExtension>("android").apply {
        project.extensions.findByType(JavaPluginExtension::class.java)?.apply {
            // Use Java 17 toolchain even if a higher JDK runs the build.
            // We still use Java 8 for now which higher JDKs have deprecated.
            toolchain {
                languageVersion.set(JavaLanguageVersion.of(17))
            }
        }

        configuration()
    }
}

Make sure to add import also:

import org.gradle.api.plugins.JavaPluginExtension

And add this at the end of gradle.properties:

# Compiling with Java 8 is deprecated but we still use it for now
android.javaCompile.suppressSourceTargetDeprecationWarning=true

Kotlin Annotation Warnings

If you receive warnings in subprojects such as:

[WARNING] file:///<pathToFile>.kt:33:5 This annotation is currently applied to the value parameter only, but in the future it will also be applied to field.
- To opt in to applying to both value parameter and field, add '-Xannotation-default-target=param-property' to your compiler arguments.
- To keep applying to the value parameter only, use the '@param:' annotation target.

Add this right after buildscript, above allprojects in root build.gradle.kts:

subprojects {
    tasks.withType<KotlinCompile>().configureEach {
        compilerOptions {
            freeCompilerArgs.add("-Xannotation-default-target=param-property")
        }
    }
}

Make sure to add import also:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

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.

1 participant