diffuse
diffuse copied to clipboard
IllegalStateException parsing APKs with no resource table. In AGP 7, android-test APKs will have no resource table if src/androidTest/res is empty
In AGP 7, if you execute (e.g.)
./gradlew lib:assembleDebugAndroidTest
on an Android library project that doesn't have any resources (no androidTest/res directory), and then attempt to compare that APK with one built with AGP 4, you'll get an error like this:
$ diffuse diff --apk test4.apk test7.apk
Exception in thread "main" java.lang.IllegalStateException: ResourceTableChunk package count was < 1.
at com.android.apksig.ApkSigner.checkState(ApkSigner.java:1)
at com.google.devrel.gmscore.tools.apk.arsc.ResourceTableChunk.<init>(ResourceTableChunk.java:7)
at com.google.devrel.gmscore.tools.apk.arsc.Chunk.newInstance(Chunk.java:57)
at com.jakewharton.diffuse.Arsc$Companion.create(Arsc.kt:42)
at com.jakewharton.diffuse.Apk$Companion.parse(Apk.kt:84)
at com.jakewharton.diffuse.DiffCommand.run(diffuse.kt:117)
at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:5266)
at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:5274)
at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:281)
at com.jakewharton.diffuse.Diffuse.main(diffuse.kt:23324)
Note that this issue arises regardless of whether the library project uses
android.buildFeatures.androidResources = false
That value appears to be ignored, at least in AGP 7.0.3. The mere presence of a resource in androidrTest/res can workaround this issue.
apktool has a similar issue when executing apktool d path/to/apk -o foo, but there's a CLI option, -r, that solves the problem: apktool -r d path/to/apk -o foo.
Might just need a dependency bump on the arsc parser? Or maybe to call a method which fails more gracefully. Presumably the arsc file still exists (I believe the APK spec mandates it) but it simply no longer contains an entry for the actual resource table (as opposed to containing an empty one before).
Yes, the arsc file still exists. In the scenario I'm describing, it's about ~40B, vs about ~400B when the APK is built with AGP 4 (and diffuse can parse it). I could provide a minimal reproducer, and/or arsc files, whichever would be most useful.
Nah I'll be able to figure it out. Thanks.