Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,34 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
aaptOptions {
noCompress['.keep_gz']
}
applicationVariants.all { variant ->

Choose a reason for hiding this comment

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

critical

The applicationVariants.all API was removed in Android Gradle Plugin (AGP) 8.0. Since your project is configured with AGP 8.9.0 (as per your root build.gradle), this code will cause a build failure. You need to migrate to the new androidComponents extension to iterate over variants. The approach to modifying assets is different with this new API, and it typically involves creating custom tasks and wiring them into the variant's asset processing pipeline. You can find more details in the AGP migration guide.

variant.mergeAssetsProvider.configure {
doFirst {
renameFiles("${projectDir}/src/main/assets", ".gz", ".keep_gz")

Choose a reason for hiding this comment

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

high

Modifying source files directly from your build script is a risky practice. If the build fails after this doFirst block but before the corresponding doLast block (line 55) runs, your source files in src/main/assets will be left in a renamed state. This can cause issues with your version control system and break subsequent builds.

A safer approach is to work with files in an intermediate directory inside build/. This ensures your source tree remains untouched by the build process.

println "---> Rename src files: *.gz to *.keep_gz at: " + projectDir;
}
doLast {
def assetsDir = "${project.layout.buildDirectory.get().asFile}/intermediates/assets/${variant.dirName}"
renameFiles(assetsDir, ".keep_gz", ".gz")
println "---> Rename APK files before pack: *.keep_gz to *.gz at: " + assetsDir;

renameFiles("${projectDir}/src/main/assets", ".keep_gz", ".gz")
println "---> Rename src files: *.keep_gz to *.gz at: " + projectDir;
}
}
}
}

def renameFiles(String dirPath, String fromExt, String toExt) {
fileTree(dir: dirPath, include: "**/*" + fromExt).each { file ->
if (file.name.endsWith(fromExt) && file.isFile()) {
def newName = file.name.substring(0, file.name.length() - fromExt.length()) + toExt
file.renameTo(new File(file.parent, newName))
}
}
}

dependencies {
Expand Down