Status Update
Comments
jp...@google.com <jp...@google.com>
ru...@gmail.com <ru...@gmail.com> #2
Problem location : CompressAssetsTask:189
abstract class CompressAssetsWorkAction @Inject constructor(
private val compressAssetsWorkParameters: CompressAssetsWorkParameters
): WorkAction<CompressAssetsWorkParameters> {
override fun execute() {
val output = compressAssetsWorkParameters.output.get().asFile.toPath()
val changeType = compressAssetsWorkParameters.changeType.get()
if (changeType != ChangeType.ADDED) {
Files.deleteIfExists(output)
}
if (changeType != ChangeType.REMOVED) {
Files.createDirectories(output.parent)
ZipArchive(output).use { jar ->
jar.add(
BytesSource(
compressAssetsWorkParameters.input.get().asFile.toPath(),
compressAssetsWorkParameters.entryPath.get(),
compressAssetsWorkParameters.entryCompressionLevel.get()
)
)
}
}
}
}
override fun doTaskAction(inputChanges: InputChanges) {
CompressAssetsDelegate(
workerExecutor.noIsolation(),
outputDir.get().asFile,
PackagingUtils.getNoCompressPredicateForJavaRes(noCompress.get()),
compressionLevel.get(),
inputChanges.getFileChanges(inputDirs)
).run()
}
problem
1.The change type of the files removed is not marked as "ChangeType.REMOVED" but "ChangeType.ADDED"
2.The implementation class of interface "InputChanges" is NonIncrementalInputChanges.
3.Method inputChanges.getFileChanges(inputDirs) can get the FILE PATH under "/build/intermediates/assets/officialDebug/" that already removed by my build task ExportAssetsTask.
ExportAssetsTask detail
def compressAssetsTask = project.tasks.getByName("compress${variantName}Assets")
if (compressAssetsTask != null) {
compressAssetsTask.dependsOn exportAssetsTask
}
...
for (File srcFile : item.value) {
String srcRelativePath = getAssetsRelativePath(srcFile)
String dstPathName = dstDir + File.separator + AS_SRC_DIR + File.separator + curBuisId + File.separator + AS_DIR + File.separator + srcRelativePath
println "> [VERBOSE] ExportAssetsTask, mv assets: ${srcRelativePath} -> ${dstPathName} | exist:${srcFile.exists()} "
if (srcFile.exists()) {
ant.move(file: srcFile, tofile: dstPathName)
}
}
je...@google.com <je...@google.com>
cm...@google.com <cm...@google.com>
hu...@google.com <hu...@google.com> #3
Could you attach a sample project that demonstrates this issue, ideally using a newer version of the Android Gradle plugin (e.g., 8.8.0)?
ru...@gmail.com <ru...@gmail.com> #4
Thanks for your reply! I solved this by move my assets files left into a new directory before CompressAssetsTask and change the input-dir of CompressAssetsTask, maybe something wrong and return a bad file snapshot of "build/intermediates/assets/" by Gradle cache?
hu...@google.com <hu...@google.com> #5
I don't know, but AGP 7.4.2 is a bit old. If you manage to reproduce this issue consistently with AGP 8.9.0, please let us know.
Description
Current Behavior
I build my android project with Gradle-build-tool 7.4.2, before execute compressAssetsTask, actually, my build script remove some file under build dictionary build/intermediates/assets/officialDebug/, and it went Error and got a stack below:
Expected Behavior
I think it would be worked, because InputChanges should return a FileChange list that without the file be removed, but it is a NonIncrementalInputChanges and return a full file list with files which has already removed
Gradle version 7.6.4
Build scan URL (optional)
Environment (optional)
android compileSdkVersion = 34 buildToolsVersion = "30.0.3" gradle version 7.6.4 gradle tools version 7.4.2