-
Notifications
You must be signed in to change notification settings - Fork 2
fix: prevent decompress .gz files
#7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,34 @@ android { | |
| kotlinOptions { | ||
| jvmTarget = '1.8' | ||
| } | ||
| aaptOptions { | ||
| noCompress['.keep_gz'] | ||
| } | ||
| applicationVariants.all { variant -> | ||
| variant.mergeAssetsProvider.configure { | ||
| doFirst { | ||
| renameFiles("${projectDir}/src/main/assets", ".gz", ".keep_gz") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modifying source files directly from your build script is a risky practice. If the build fails after this A safer approach is to work with files in an intermediate directory inside |
||
| 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 { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
applicationVariants.allAPI was removed in Android Gradle Plugin (AGP) 8.0. Since your project is configured with AGP 8.9.0 (as per your rootbuild.gradle), this code will cause a build failure. You need to migrate to the newandroidComponentsextension 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.