Bug 35422 - XA doesn't handle invalid Jar; "jar is not a valid zip file" error in binding project
Summary: XA doesn't handle invalid Jar; "jar is not a valid zip file" error in binding...
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 6.0.0
Hardware: PC Mac OS
: --- enhancement
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2015-10-30 16:27 UTC by David Hathaway
Modified: 2016-09-16 23:12 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

diagnostic build containing relevant exception (237.06 KB, application/octet-stream)
2015-11-05 09:44 UTC, Radek Doulik

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description David Hathaway 2015-10-30 16:27:46 UTC
While trying to do a binding for New Relic's Android agent, I'm getting an error message when packaging that one of the reference jars is not a valid zip file, but I can successfully open it up with tools like Jarzilla.

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Error executing task BuildApk: /Users/davidhathaway/Projects/dwhathaway/xamarin-bindings/NewRelic/NewRelicDroidSample/obj/Debug/__library_projects__/NewRelic.Binding.Droid/library_project_imports/__reference__class.rewriter.jar is not a valid zip file (NewRelicDroidSample)

Build log is here, which shows that the app did build successfully:


Reproduction can be found at - just clean/rebuild/run the "NewRelicDroidSample" app.


Version information:

=== Xamarin Studio ===

Version 5.10 (build 860)
Installation UUID: e16d0ece-7353-4886-83b5-86d62e1d480c
	Mono 4.2.1 (explicit/8862921)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010091

=== Xamarin.Profiler ===

Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 7.1 (9079)
Build 7B91b

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: 9ce9e8b
Branch: master
Build date: 2015-10-28 19:11:03-0400

=== Xamarin.Android ===

Version: (Enterprise Edition)
Android SDK: /Users/davidhathaway/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.1

Java SDK: /usr
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Enterprise Edition)

=== Build Information ===

Release ID: 510000860
Git revision: 7c46a0b709d51ad5d5a5ed90a4671cc7b6928e62
Build date: 2015-10-29 17:17:52-04
Xamarin addins: b9337905aca5dc276190d78819728a59cda33a43
Build lane: monodevelop-lion-cycle6

=== Operating System ===

Mac OS X 10.10.5
Darwin dwhathaway-macbook.local 14.5.0 Darwin Kernel Version 14.5.0
    Tue Sep  1 21:23:09 PDT 2015
    root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64
Comment 1 Atsushi Eno 2015-11-01 23:30:31 UTC
The sample link does not work: "This account's public links are generating too much traffic and have been temporarily disabled!"
Comment 3 Atsushi Eno 2015-11-04 03:12:25 UTC
The project contains broken links to your local files:

	/svn/monodroid/monodroid/out/lib/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets: error : Specified reference jar not found: ../../../../../../../Downloads/okhttp-2.5.0.jar

This is the first one I saw, there might be more.
Comment 4 Atsushi Eno 2015-11-04 03:22:35 UTC
I manually downloaded okhttp-2.5.0.jar from maven central, replaced in the .csproj, set build item as EmbeddedReferenceJar and could build without such a jar problem.

Can *you* or anyone else in your team reproduce the issue? I'll also ask at Android team.
Comment 5 David Hathaway 2015-11-04 13:13:04 UTC
This issue is reproducible by running the Android app itself.  Consolidated repro (including OkHttp) can be found here:


Also including a video recording of the problem:


Steps to reproduce:

1. Build the solution.  Note that everything builds fine.
2. Set the '' project as your startup project, and run.
3. Receive packaging error on deployment.
Comment 6 Radek Doulik 2015-11-05 09:44:49 UTC
Created attachment 13686 [details]
diagnostic build containing relevant exception
Comment 7 Atsushi Eno 2015-11-05 10:07:31 UTC
Radek figured out that the mentioned jar (class.rewriter.jar) is indeed problematic and it contains META-INF/LICENSE.txt *twice*. While some tools wouldn't complain about that it is indeed invalid zip.
Comment 8 Atsushi Eno 2015-11-05 10:12:14 UTC
While we could still do some workaround, it is basically invalid zip that should be corrected.
Comment 9 David Hathaway 2015-11-06 01:18:30 UTC
unpacked / repacked the jar with the following command, and it's fine now.  Even though the jar showed a duplicate license.txt file when I opened it with Jarzilla, exploding it into a folder did not result in duplicate files.  Simply unpacking (jar -xvf class.rewriter.jar) and repacking (jar -cvf class.rewriter2.jar .)

After re-packing, I'm now able to compile, and deploy the app including the bound libraries.
Comment 10 David Hathaway 2016-09-16 23:12:47 UTC
Marking resolved.  JAR file was invalid.  repacking JAR fixed the issue.