Bug 44187 - Build error when Proguard or MultiDex options are enabled
Summary: Build error when Proguard or MultiDex options are enabled
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild (show other bugs)
Version: 7.0 (C8)
Hardware: PC Windows
: --- normal
Target Milestone: 15.2
Assignee: Atsushi Eno
URL:
: 53242 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-09-12 12:41 UTC by Leon
Modified: 2017-05-17 16:35 UTC (History)
21 users (show)

See Also:
Tags: XATriaged
Is this bug a regression?: ---
Last known good build:


Attachments
Test case, minimal (25.02 KB, application/zip)
2017-05-17 04:47 UTC, Brendan Zagaeski (Xamarin Support)
Details

Description Leon 2016-09-12 12:41:58 UTC
Whenever the Multidex or Proguard option are enabled in a Xamarin.Android 7.0 project (using Java JDK 1.8) the following error appears during the build process, indicating a Java version mismatch:

>Error: Can't read [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v7.0\mono.android.jar] (Can't process class [android/app/ActivityTracker.class] (Unsupported class version number [52.0] (maximum 51.0, Java 1.7))) [CREATEMULTIDEXMAINDEXCLASSLIST]

The Proguard jar bundled with the Android SDK (<sdk-folder/tools/proguard/lib) hasn't been updated since 2011 since Proguard is now handled by the gradle plugin of Android Studio in Java based Android development. This outdated version of Proguard doesn't support Java 8.

Seems the mainDexClasses.bat script in the Android SDK build tools calls this outdated bundled Proguard jar and  therefore breaks whenever it is used to handle projects using Java 8 (e.g. Xamarin.Android 7.0 projects)

A temporary solution is to download the latest version of Proguard ( https://sourceforge.net/projects/proguard/files/proguard/ ) and copy the contents of the zip to the <android-sdk-folder>/tools/proguard folder
Comment 1 Atsushi Eno 2016-09-13 04:02:59 UTC
It is being handled at https://github.com/xamarin/xamarin-android/pull/209
Comment 2 Jon Douglas [MSFT] 2016-09-16 19:44:13 UTC
I have a Stack Overflow answer out there to help those who run into this:

http://stackoverflow.com/questions/39514518/xamarin-android-proguard-unsupported-class-version-number-52-0/39514706#39514706
Comment 3 Laurent Dutrillaux 2016-11-14 11:09:33 UTC
I have the same issue, not yet solved.
https://github.com/xamarin/xamarin-android/pull/267
Did this merge will be included to the next Xamarin.Android release ?
Comment 4 softlion 2016-11-21 20:11:12 UTC
Bug still in Xamarin Android v7.1.0.2
Comment 5 klark 2016-11-29 07:41:03 UTC
I had download and replace the latest version of Proguard(5.3.1),but it still not work!
Comment 6 softlion 2016-11-29 08:25:55 UTC
It does work. Check the android sdk folder you are using.
Comment 7 klark 2016-12-01 01:25:35 UTC
Thanks,clean and rebuild,id does work!
Comment 8 Brendan Zagaeski (Xamarin Support) 2017-04-12 18:59:49 UTC
*** Bug 53242 has been marked as a duplicate of this bug. ***
Comment 9 Akash Kakkar 2017-05-13 18:33:34 UTC
The bug is still in the latest release of xamarin
Comment 10 Brendan Zagaeski (Xamarin Support) 2017-05-13 18:42:25 UTC Comment hidden (obsolete)
Comment 11 Brendan Zagaeski (Xamarin Support) 2017-05-17 04:47:37 UTC
Created attachment 22218 [details]
Test case, minimal

Correction to Comment 10: Xamarin.Android 7.3 is already included in the Xamarin 15.2 release [1], and that release is currently available for both Mac and Windows and both Visual Studio 2015 and Visual Studio 2017.  Xamarin.Android 7.3 successfully uses its bundled version of ProGuard for the test case attached to this comment.  I will accordingly mark Comment 10 as obsolete.

[1] https://releases.xamarin.com/stable-release-15-2/




## Verification status: verified fixed in the Xamarin 15.2 Release

GOOD: XamarinVS 4.5.0.443 (c871575), Xamarin.Android 7.3.0.13 (448f54f) "15.2 Release" [1]
BAD:  XamarinVS 4.4.0.34  (3f99c5a), Xamarin.Android 7.2.0.7  (b16fb82) "15.1 Release" [2]


[1] https://releases.xamarin.com/stable-release-15-2/
[2] https://releases.xamarin.com/stable-release-15-1/




## Steps followed to test


1. Ensure "Tools > Options > Xamarin > Android Settings > Java Development Kit Location" is set to Java JDK 8 (1.8).


2. Ensure the Android SDK location set under "Tools > Options > Xamarin > Android Settings > Android SDK Location" does _not_ included any spaces.  This is necessary to avoid Bug 32861 (for ProGuard) and Bug 33052 (for multidex).  Both of those bugs are relevant as of Xamarin.Android 7.3.0.13.  For my tests I used the following location:

C:\android-sdk


3. Build both of the projects in the attached test case in the Release configuration in Visual Studio.  (The test projects are just new blank template apps with the ProGuard and multidex settings enabled.)




## GOOD results with Xamarin.Android 7.3

Both projects build successfully.




## BAD results with Xamarin.Android 7.2



### Excerpt from the diagnostic build output for the multidex test

> C:\android-sdk\build-tools\25.0.2\\mainDexClasses.bat --output obj\Release\multidex.keep "'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v7.0\mono.android.jar';'C:\Program Files (x86)\MSBuild\Xamarin\Android\android-support-multidex.jar';'obj\Release\android\bin\classes'"  (TaskId:230)
> CREATEMULTIDEXMAINDEXCLASSLIST : error : Can't read [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v7.0\mono.android.jar] (Can't process class [android/app/ActivityTracker.class] (Unsupported class version number [52.0] (maximum 51.0, Java 1.7)))


### Excerpt from the diagnostic build output for the ProGuard test

> ProGuard, version 4.7 (TaskId:229)
>   Reading input... (TaskId:229)
>   Reading program jar [C:\source\MinimalProguardTest\MinimalProguardTest\obj\Release\proguard\__proguard_input__.jar] (TaskId:229)
>   Reading program jar [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v7.0\mono.android.jar] (TaskId:229)
>   java.io.IOException: Can't read [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v7.0\mono.android.jar] (Can't process class [android/app/ActivityTracker.class] (Unsupported class version number [52.0] (maximum 51.0, Java 1.7))) (TaskId:229)



## Additional environment info (brief)

Java JDK 8u121 (1.8.0_121), 64-bit

Android SDK Tools 25.2.5
Android SDK Platform-tools 25.0.3
Android SDK Build-tools 25.0.2

Android 7.0 (API 24) SDK Platform Rev. 2

Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01586

Windows 10 (64-bit) version 1607 (OS Build 14393.1198)
US English locale, US Eastern time zone
Comment 12 softlion 2017-05-17 06:08:19 UTC
Hi Brendan,
note that in the case i originally reported (marked duplicated with this one), i already updated the proguard version manually (by replacing the version in the android sdk), i already have a folder without space for the android sdk, and i do not have the same error as the one you are describing (unsupported class version number [52.0]), error that is fixed by replacing proguard with the latest version.

Please have a look before marking it as duplicate or fixed.
https://bugzilla.xamarin.com/show_bug.cgi?id=55268
Comment 13 Brendan Zagaeski (Xamarin Support) 2017-05-17 16:35:04 UTC
Thanks for the heads-up.  It looks like that bug report Bug 55268 is currently in the reopened status (thanks for adjusting that back in April too), so it will be eligible for further investigation by default.  And indeed this bug report Bug 44187 can be considered to be focused only on the "unsupported class version number" error.

So for the purposes of this precise bug report Bug 44187, I will mark this bug as verified based on Comment 11, and further investigation related to ProGuard and multidex will proceed on the other bugs.  Thanks!

Note You need to log in before you can comment on or make changes to this bug.