3

I recently broke the Dalvik Limit (https://developer.android.com/studio/build/multidex.html) of 64K referencs as I started getting

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/ Xamarin.Android.Common.targets: Error: Tool exited with code: 2. Output: trouble writing output: Too many field references: 77369; max is 65536. You may try using --multi-dex option.

error after updating some nugets to MonoDroid 7.

When I turn on the MultiDex option in android settings and compile my project I get -

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Tool exited with code: 10. Output: Error: Can't read [/Library/Frameworks/Xamarin.Android.framework/Versions/7.0.1-3/lib/xbuild-frameworks/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))) (pjr.mob.android)

I can see BUGs relating to this -

https://bugzilla.xamarin.com/show_bug.cgi?id=44187

https://bugzilla.xamarin.com/show_bug.cgi?id=44013

https://bugzilla.xamarin.com/show_bug.cgi?id=33052

https://bugzilla.xamarin.com/show_bug.cgi?id=35491

It looks like I have to manually download and install ProGuard 5.X as detailed in these answers -

Xamarin.Android Proguard - Unsupported class version number 52.0

Xamarin Android ProGuard Enable

and overcome any issues that arise from this.

Yet, Xamarin Studio explicitly tells us in the (i) information box next to the proguard option is that it is not recommended to run proguard for a DEBUG build and that we should only run multidex after trying proguard first.

Will this mean we cannot debug effectively after enabling it? but I cannot DEBUG anyway (I cannot even run a release build even with the linker on which I thought might help) now without enabling it?

Is there some kind of Xamarin Support coming for this or do I need to look at somehow reducing the packages etc that we use (I am not sure I can do as most of it is Google Play Services related).

Any help is appreciated.

Other Info from Xamarin Studio Help > About

Java SDK: /usr java version "1.8.0_112" Java(TM) SE Runtime Environment (build 1.8.0_112-b16) Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)

Community
  • 1
  • 1
WickedW
  • 2,331
  • 4
  • 24
  • 54
  • Follow this thread please: [http://stackoverflow.com/questions/39514518/xamarin-android-proguard-unsupported-class-version-number-52-0/39514706#39514706](http://stackoverflow.com/questions/39514518/xamarin-android-proguard-unsupported-class-version-number-52-0/39514706#39514706) – Robin Bruneel Nov 08 '16 at 09:44

3 Answers3

5

Unsupported class version number [52.0] (maximum 51.0, Java 1.7)

1st) The error you got is from not having Java v8 installed and/or Xamarin configured to use it.

Ref: java Lang UnsupportedClassVersion Error in Xamarin Studio

2nd) MultiDex can be used without Proguard and is only needed on API-20 and below. Enabling Multi-Dex enables the Android SDK tools to create as many secondary sex file as needed.

3rd) If you are enabling Proguard, you should look at replacing the proguard.jar in your android-idk with the Facebook version as it is sooooo much faster ;-)

Ref: https://github.com/facebook/proguard

Or use the SourceForge-based one:

Ref: Xamarin.Android Proguard - Unsupported class version number 52.0

Community
  • 1
  • 1
SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • Thanks @sushihangover for your help, I did "install" Java V8 but your right, I did not check xamarin config if used the SDK (added Java version from help > about to the post), will review now. Can you possibly edit / comment on the DEBUG process when using Multi-dex / Proguard in Xamarin AND if we support API 16-24 can you explain further how we would use multidex in this scenario as you mention < 20, so not sure how this would fit in. Thanks. – WickedW Nov 03 '16 at 09:28
  • Thanks for the link to the fb repo. – tedi Apr 11 '17 at 10:12
2

To clarify where I got to with this for future readers -

a) The 52.0 Error was due to the fact that the included ProGuard version with Xamarin required updating to the latest version (even after I had upgraded my JDK to 1.8 as discussed) -

Xamarin.Android Proguard - Unsupported class version number 52.0

NOTE: AFAIIA: I could not run multi-dex without fixing the proguard error first.

b) Xamarin Studio unfortunately lets you TICK pro guard for debug builds but then in turn does NOT actually run ProGuard for debug builds, causing confusion if you are very new to using it + trying to work out how things hang together.

The xamarin docs tell you this on inspection, which might be the case for VS -

ProGuard is disabled by default. The Enable ProGuard option is available only when the project is set to Release mode. All ProGuard build actions are ignored unless Enable ProGuard is checked.

c) So, when hitting the MultiDex limit; in order to progress -

DEBUG - enable multiplex only, this should (when working, I am still working on it in XS) allow you to bypass the 64K error as expected AND debug will work as expected. You should leave your linker to No Linking as usual for debug builds.

RELEASE - enable ProGuard firstly to see if you can configure it to bring down your method count without requiring the overhead or multidex as it brings in the secondary methods at run-time. If you don't want to mess with Proguard config then as an intermediate step your multidex set-up from DEBUG should just work for your release when fully tested.

When any documentation states you should try ProGuard first and then multidex it means just for a RELEASE not for debug build.

UPDATE: I also had to go via Xamarin Support to get my Multi-dex to build, but as of https://releases.xamarin.com/stable-release-cycle-8-service-release-1/ this is now working fine. My Android project in XS had a custom application class and that was not being correctly inherited by the build tools from the required multidex class when ticking Multidex.

Community
  • 1
  • 1
WickedW
  • 2,331
  • 4
  • 24
  • 54
0

Under Xamarin Studio -> Preferences -> Projects -> SDK Locations -> Andorid was pointing to a directory that I was no longer using for the more recent SDK updates. Changed it to point to the correct SDK directory and build succeeded.