Repository navigation
Rando ANDZA0000: Unable to open app.apk as a zip archive #6067
Description
It's our favorite, hysenbugs!
There is no repro!
Context:
- https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=4935806&view=ms.vss-test-web.build-test-results-tab&runId=23180970&resultId=100203&paneView=attachments [note: will be invalid within a couple of weeks]
- https://discord.com/channels/732297728826277939/732297837953679412/860159968087113748
- …through…
- https://discord.com/channels/732297728826277939/732297837953679412/860236601267585076
- …and beyond…
Sometimes, the DebuggerAttribute"Full", False, True) unit test (and others?) will fail:
error ANDZA0000: Unable to open '/Users/runner/work/1/s/bin/TestRelease/temp/DebuggerAttribute_Full_False_True/obj/Debug/android/bin/com.xamarin.debuggerattribute.apk' as zip archive
The cause of the error is that zipalign doesn't like the file:
$ "$HOME/android-toolchain/sdk/build-tools/28.0.3/zipalign" -p 4 bin/Debug/com.xamarin.debuggerattribute.apk app-Signed.apk
Unable to open 'bin/Debug/com.xamarin.debuggerattribute.apk' as zip archive
The file does exist; it is attached here as com.xamarin.debuggerattribute.zip.
Aside: zipalign source: https://android.googlesource.com/platform/build.git/+/refs/heads/master/tools/zipalign/
Lots of spitballing and investigation later, and we we see that zipdetails -vv doesn't like it:
% zipdetails -vv com.xamarin.debuggerattribute.zip # or .apk…
…
00C06E 000004 50 4B 03 04 LOCAL HEADER #8 04034B50
00C072 000001 00 Extract Zip Spec 00 '0.0'
00C073 000001 00 Extract OS 00 'MS-DOS'
00C074 000002 00 00 General Purpose Flag 0000
00C076 000002 00 00 Compression Method 0000 'Stored'
00C078 000004 00 00 21 00 Last Mod Time 00210000 'Tue Jan 1 00:00:00 1980'
00C07C 000004 02 19 FA 61 CRC 61FA1902
00C080 000004 BC 06 00 00 Compressed Length 000006BC
00C084 000004 BC 06 00 00 Uncompressed Length 000006BC
00C088 000002 0E 00 Filename Length 000E
00C08A 000002 02 00 Extra Length 0002
00C08C 00000E 72 65 73 6F Filename 'resources.arsc'
75 72 63 65
73 2E 61 72
73 63
00C09A 000002 00 00 Malformed Extra Data 00 00
00C09C 0006BC ... PAYLOAD
Unexpecded END at offset 0000C758, value 00000000
Done
It appears that either the resources.arsc entry, or the following classes.dex entry, is somehow broken; 7zip reports:
% 7z t -bb3 com.xamarin.debuggerattribute.apk
…
ERROR: Headers Error : classes.dex
…
Sub items Errors: 1
Archives with Errors: 1
Sub items Errors: 1
Something isn't kosher here.
@grendello eventually concludes:
local header for
classes.dexis corrupted
the CD entry for it is fine
that's why listing the contents works fine
…
it appears the entry is preceded (or the previous entry followed) by two additional bytes
which then escalates to 9 extra bytes before the subsequent entries, but it appears to badly affect just the first entry with the extra leading bytes
It looks like this is due to something we're doing, but we're not sure what, why, or how to fix it.
Activity
grendello commentedon Jul 1, 2021
Other ways to diagnose:
$ unzip -t com.xamarin.debuggerattribute.apk Archive: com.xamarin.debuggerattribute.apk testing: AndroidManifest.xml OK testing: res/drawable-mdpi-v4/icon.png OK testing: res/drawable-hdpi-v4/icon.png OK testing: res/drawable-xhdpi-v4/icon.png OK testing: res/drawable-xxhdpi-v4/icon.png OK testing: res/drawable-xxxhdpi-v4/icon.png OK testing: res/layout/main.xml OK testing: resources.arsc OK file #9: bad zipfile offset (local header sig): 51032 testing: lib/arm64-v8a/libxamarin-app.so OK testing: lib/x86/libxamarin-app.so OK testing: lib/arm64-v8a/libSystem.IO.Compression.Native.so OK testing: lib/arm64-v8a/libSystem.Native.so OK testing: lib/arm64-v8a/libSystem.Security.Cryptography.Native.Android.so OK testing: lib/arm64-v8a/libmonosgen-2.0.so OK testing: lib/arm64-v8a/libmonodroid.so OK testing: lib/arm64-v8a/libxamarin-debug-app-helper.so OK testing: lib/x86/libSystem.IO.Compression.Native.so OK testing: lib/x86/libSystem.Native.so OK testing: lib/x86/libSystem.Security.Cryptography.Native.Android.so OK testing: lib/x86/libmonosgen-2.0.so OK testing: lib/x86/libmonodroid.so OK testing: lib/x86/libxamarin-debug-app-helper.so OK At least one error was detected in com.xamarin.debuggerattribute.apk.unzip -tdoesn't give name of the broken entry, alas.zipinfo -vvshows us there are extra bytes precedingclasses.dex(or following the previous entry,resources.arsc. @dellis1972 notes that the broken entry follows data we add to the apk by copying it from another zip archive creted byaapt2See if we can fix Rando ANDZA0000: Unable to open app.apk as a zip ar…
See if we can fix Rando ANDZA0000: Unable to open app.apk as a zip ar…
jonpryor commentedon Jul 16, 2021
We have another apparent instance of this bug: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=4979360&view=ms.vss-test-web.build-test-results-tab&runId=23547392&resultId=100040&paneView=attachments
See if we can fix Rando ANDZA0000: Unable to open app.apk as a zip ar…
[Xamarin.Android.Build.Tasks] `unable to open file as zip archive`? (#…
jonpryor commentedon Mar 27, 2023
We think (hope? pray?) that this was fixed by PR #7759.