dotnet / android-libzipsharp

A managed wrapper (and then some) around libzip (https://libzip.org/)
MIT License
30 stars 12 forks source link

Error when build an Android project when added a .NET7 binding library #130

Closed entdark closed 1 year ago

entdark commented 1 year ago

Environment: VS for Mac 17.5.4 (build 8)
.NET7 Android application

Partial build log before the issue:

/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.46/tools/Xamarin.Android.Javac.targets(55,5): error XADJL7024: Xamarin.Tools.Zip.ZipIOException: The file obj/Debug/net7.0-android/lp/165/jl/libs/D2648AD79002B2B3.jar failed consistency checks.
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.46/tools/Xamarin.Android.Javac.targets(55,5): error XADJL7024:    at Xamarin.Tools.Zip.ZipArchive.Open(String path, FileMode mode, String defaultExtractionDir, Boolean strictConsistencyChecks, IPlatformOptions options) in /Users/runner/work/1/s/LibZipSharp/Xamarin.Tools.Zip/ZipArchive.cs:line 282
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.46/tools/Xamarin.Android.Javac.targets(55,5): error XADJL7024:    at Microsoft.Android.Build.Tasks.Files.ReadZipFile(String filename, Boolean strictConsistencyChecks) in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/Files.cs:line 335
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.46/tools/Xamarin.Android.Javac.targets(55,5): error XADJL7024:    at Microsoft.Android.Build.Tasks.Files.ZipAny(String filename, Func`2 filter) in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/Files.cs:line 340
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.46/tools/Xamarin.Android.Javac.targets(55,5): error XADJL7024:    at Xamarin.Android.Tasks.DetermineJavaLibrariesToCompile.HasClassFiles(String jar)
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.46/tools/Xamarin.Android.Javac.targets(55,5): error XADJL7024:    at Xamarin.Android.Tasks.DetermineJavaLibrariesToCompile.RunTask()
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.46/tools/Xamarin.Android.Javac.targets(55,5): error XADJL7024:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 22

The issue started happening after I added a binding library compiled against net7-android.
When the application project and the binding library projects targeted monodroid11.0 it was fine.

The problematic autogenerated file:
D2648AD79002B2B3.jar.zip

The problematic binding library:
Xamarin.DevToDev.Analytics.Android.zip

jonpryor commented 1 year ago

I don't think that this is a LibZipSharp bug; I think that .jar is corrupt:

% unzip D2648AD79002B2B3.jar.zip
% jar tf D2648AD79002B2B3.jar
java.util.zip.ZipException: invalid END header (bad central directory offset)
    at java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1607)
    at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1519)
    at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1308)
    at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1271)
    at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:733)
    at java.base/java.util.zip.ZipFile$CleanableResource.get(ZipFile.java:850)
    at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:248)
    at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:177)
    at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:148)
    at jdk.jartool/sun.tools.jar.Main.list(Main.java:1499)
    at jdk.jartool/sun.tools.jar.Main.run(Main.java:380)
    at jdk.jartool/sun.tools.jar.Main.main(Main.java:1680)

If I use unzip -l:

% unzip -l D2648AD79002B2B3.jar
Archive:  D2648AD79002B2B3.jar
error [D2648AD79002B2B3.jar]:  missing 1 bytes in zipfile
  (attempting to process anyway)
  Length      Date    Time    Name
---------  ---------- -----   ----
     2643  01-01-1981 01:01   com/devtodev/google/AdvertisingData$ExceptionData.class
     3064  01-01-1981 01:01   com/devtodev/google/AdvertisingData$GoogleAdvertisingId.class
     1193  01-01-1981 01:01   com/devtodev/google/AdvertisingData.class
     2342  01-01-1981 01:01   com/devtodev/google/GoogleAdvertising.class
       24  01-01-1981 01:01   META-INF/DTDGoogle_productionAndroidRelease.kotlin_module
---------                     -------
     9266                     5 files

I don't know how or why this file is "missing 1 bytes", but it is a corrupt/invalid ZIP file.

Where did you get D2648AD79002B2B3.jar from? It looks like the classes.jar from the android-google 1.0 maven package, but with a 1 byte file size difference: 5629 bytes for android-google.aar!classes.jar vs. 5628 bytes for D2648AD79002B2B3.jar. I don't know how or why that would happen.

entdark commented 1 year ago

File D2648AD79002B2B3.jar got automatically created in the obj/Debug/net7.0-android/lp/165/jl/libs/D2648AD79002B2B3.jar path. The obj folder is next to Android project.

entdark commented 1 year ago

Summary of discussion on Discord: the issue was in a corrupt .jar file that was in our binding library. The corruption happened because we had .gitattributes that replaces line endings and we did not have a rule to ignore .jar files. So git "corrupted" the file. The issue has nothing to do with LibZipSharp or Xamarin.Android/.NET7 Android. Closing.