We recently upgraded our xamarin.android project to support android 7.0 and the VSTS build broken with below error, on our local build we can fix the error by upgrade to latest version of proguard( https://sourceforge.net/projects/proguard/files/proguard/), how can we get this fixed with VSTS?
2017-01-04T07:07:36.9634026Z ##[error]CREATEMULTIDEXMAINDEXCLASSLIST(0,0): 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)))
Are you using our hosted build image?
Have you tried with a private agent (azure) where you can control the toolsets? I think 7.0 is in the process of getting on the image.
Android 7 support is available on the hosted build VMs now. But you need to use JDK 8 explicitly in your build process as Xamarin requires JDK 8 but by default Xamarin will use JDK 6 if installed on the build server. Please try setting the JDK version on Xamarin Android task to 8 and see if this helps.

@bryanmacfarlane Yes hosted agent used.
@madhurig the JDK 8 option was already set and we tried both x86 and x64 options, all same results, here the build summary link if you need: https://boundlss.visualstudio.com/Boundlss/_build/index?buildId=635&_a=summary&tab=details
@jamesatgithub: It looks like the proguard version is not being updated with Android SDK and has to be installed separately: http://stackoverflow.com/questions/39514518/xamarin-android-proguard-unsupported-class-version-number-52-0.
We don't have ProGuard 5 on the hosted build VMs, so you are seeing this error. We will update in the next rollout, I will post a timeline for the availability here once we have it.
Thanks,
Madhuri
The Xamarin bug resulting in this error is fixed for Cycle 9 release but is not in the stable channel yet. Replacing ProGuard version in the Android SDK location is a workaround suggested by Xamarin team but we don't want to do that on the hosted build VMs since they are shared machines and we don't know if there will be side-effects of the workaround for native Android users.
We will upgrade to Cycle 9 on hosted build VMs which has the fix once it is stable. Till then the alternate will be to use your own build server.
Thanks,
Madhuri
Have the build VMs been upgraded to Cycle 9? If not, when is that happening?
Cycle 9 is not available in the Stable channel yet, it is in Beta: https://releases.xamarin.com/release-candidate-cycle-9-rc6-refresh/. We will update the Hosted build VMs to Cycle 9 after it is available in the Stable channel.
Thanks,
Madhuri
Hello :)
Any update on this? It's been some days since the Cycle 9 was released and I'm still getting the error
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)))
@GiusepeCasagrande : What Java version are you targeting? Please update your build task to use Java8 and see if helps.
Hi @madhurig,
Just checked, I'm already using JDK8

@GiusepeCasagrande : This was marked as fixed in Cycle 9: https://github.com/xamarin/xamarin-android/pull/267, so it should have worked. I will follow up .
@madhurig I'll give it a few more tries, maybe I'm making something wrong here. But please, let me know if you find something else about it.
And thanks for your help so far :)
Hello, I am experiencing the same issue as Guisepe.
I have both MultiDex and ProGuard enabled. I tried targeting API 24 and API 25, but I am getting the same issue. I spent the day trying various workaround, but without luck on hosted VSTS machines, although it's building fine on my local machine.
I followed advice to add Proguard folder to my source control and set custom ProGuardJarPath and the ProGuardToolPath. I did that in proguard.cfg (BuildAction is set to ProguardConfiguration like expained in here):
ProGuardJarPath = ..\..\..\Shared\tools\proguard\lib\proguard.jar
ProGuardToolPath = ..\..\..\Shared\tools\proguard\
I am not sure if proguard.cfg is the right place for this lines, but it didn't fix the issue.
I set up my local environment following this blog post. My guess is that hosted machines have something different.

@GiusepeCasagrande : My xamarin android project with ProGuard enabled builds without errors on the hosted build VMs. Can you share your debug build logs for further investigation? You can upload here or email me: madhurig at microsoft dot com.
My build definition settings look like this:

Thanks,
Madhuri
@markolazic88: I checked the blog you linked to. The hosted build VMs don't have all the android build tools versions that the blog lists. We have an update with those in the pipeline but I can't be sure if it will fix your problem since I can't repro it.
If you continue to have the issue after our next update, please open a new issue with your build logs.
@madhurig Thank you for the info. Could you please share the date when those tools are going to be updated? That info is important for us, as we are still blocked, and we would have to create private build machine if the update is not going to happen any time soon.
Adding @thechrisjohnson for timeline on the update.
@madhurig Hi, I'm experiencing this issue too, I'm targeting Android 7.0 and building with android 7.0, when I build in VSTS, I get the error:
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)))
However, in my build configuration, I have selected Java 1.8:

On my local machine, I fixed this by upgrading to Proguard 5.3, as the others have mentioned above. I note that you said the same was going to happen on VSTS hosts, but now it seems that it has been removed from the milestone, can you suggest when/if this will happen? This is a major dealbreaker for moving into VSTS :(
@AviateX14: Can you please try the "VS 2017" agent and see if this issue is resolved there?
@madhurig:This raises a new issue. The build has proguard enabled, proguard will not work with spaces in the path to it's directory (see the following post on the Xamarin forums on my local machine I've set up a symlink to correct this, however in VSTS using the Hosted VS 2017 agent, there is no link, and as such, I get this error:
"C:\a\1\s\HarnessInspections.Android\HarnessInspections.Android.csproj" (PackageForAndroid target) (1) ->
(_CompileToDalvikWithDx target) ->
PROGUARD : error : C:\Program Files (Access is denied) [C:\a\1\s\HarnessInspections.Android\HarnessInspections.Android.csproj]
103 Warning(s)
1 Error(s)
Time Elapsed 00:01:10.05
PROGUARD(0,0): Error : C:\Program Files (Access is denied)
PROGUARD : error : C:\Program Files (Access is denied) [C:\a\1\s\HarnessInspections.Android\HarnessInspections.Android.csproj]
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
Disabling Proguard stops the build because there ends up being too many methods defined, so this isn't really an options as I don't want to use multi-dex or have massive APK's.
Note: my build works perfectly fine in Mobile Center.
@AviateX14: MobileCenter builds are run on Mac, so these issues don't apply there. Thanks for the details, we will investigate and provide a solution.
@madhurig thanks, I look forward to your response.
I'm facing the same issue as @AviateX14 . Despite setting MSBuild parameters /p:ProGuardToolPath=C:\a\1\s\{projectdir}\proguard\ /p:ProGuardJarPath=C:\a\1\s\{projectdir}\proguard\lib\proguard.jar /p:EnableProguard=true it errors with "Error : C:\Program Files (Access is denied)" ... maybe because it uses proguard config files in the default android sdk proguard folder (which is under program files)
I tried passing /p:ProGuardConfigurationFiles="proguard\proguard-android.txt;obj\Release\proguard\proguard_xamarin.cfg;obj\Release\proguard\proguard_project_references.cfg;obj\Release\proguard\proguard_project_primary.cfg;proguard.cfg" which didn't work either - it still used the standard files
We are following up on the 2 Xamarin bugs with the Xamarin team:
We don't want to apply workarounds for these bugs since they might impact native Android builds. Till we figure out the right solution here, the option will be to setup your own build server and apply the workarounds for Xamarin Android ProGuard builds.
Thanks,
Madhuri
While we are continuing to work with Xamarin team on the bugs, I have a workaround that can be applied to build on the Hosted and Hosted VS 2017 VM pools.
Download latest proguard from: https://sourceforge.net/projects/proguard/files/proguard/5.3/ and commit/push to your repository.
In the build definition use "Extract Files" to unzip to a location without spaces, I set it to $(build.sourcesdirectory)

If using "Hosted VS 2017" pool, a symlink needs to be created for the Android SDK location so the path does not have spaces. This is not required for "Hosted" pool. Create a batch script and commit to your repo with this command: _mklink /J C:\AndroidSDK "C:\Program Files (x86)\Androidandroid-sdk"_

If you have MultiDex enabled, Use "Copy Files" task to copy the extracted latest proguard to AndroidSDK directory. Make sure you check the "Overwrite" option in "Advanced" section.

In the Xamarin Android task "MSBuild Options > Additional Arguments", set
(Hosted pool)
/p:ProguardToolPath=$(build.sourcesdirectory)\proguard5.3.3\

(Hosted VS 2017 pool)
/p:AndroidSdkDirectory=C:\AndroidSDK /p:ProguardToolPath=$(build.sourcesdirectory)\proguard5.3.3\
Thanks,
Madhuri
Step 3: " Create a batch script"? Does the batch script contain the command
mklink /J C:\AndroidSDK "C:\Program Files (x86)\Androidandroid-sdk" ?
What should I call the batch script? x.bat? what invokes the x.bat script?
ok i found a build task to execute the batch script.
Progress! Now the build fails with a different error. I checked we are using JDK 8.
Any suggestions on this one?
CREATEMULTIDEXMAINDEXCLASSLIST : error : Can't read [C:\Program Files (x86)\Microsoft Visual Studio2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v7.1\mono.android.jar] (Can't process class [android/app/ActivityTracker.class] (Unsupported class version number [52.0] (maximum 51.0, Java 1.7))) [d:a1\s\Ageas.*.App.Droid\Ageas.*.App.Droid.csproj]
@jonathan305: It looks like if multidex is enabled, the /p:ProGuardToolPath is not being used. Looks like replacing the ProGuard version in the AndroidSDK folder is the only way to get this working. I was able to workaround that as well but it is a crazy set of workarounds :(. I updated the workarounds post above, I will communicate back to the Xamarin team.
@madhurig: I've tried the workaround you said.



But i have this error : ##[error]C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2037,3): Error MSB6006: "java.exe" exited with code 1
What i have done in my Android project is to enabled multidex and proguard.
Any news about these Xamarin bugs that this post is talking ?
@smedel: The Xamarin bug fixes are going to be available in the next update of Xamarin as per the update from the Xamarin team. The progress can be tracked on bugzilla too.
Can you share the full log or email it to me at madhurig at microsoft.com?
@madhurig i just sent you an email.
@madhurig Can you please update us on the status of this bug?
@ramyzbeidy: One of the issues (outdated proguard) is addressed in a newer version of Xamarin but the other one (issue with spaces in the path to AndroidSDK) will be included in a future release. Please try posted workaround if you wish to use the Hosted Build VMs. The alternate is to setup your own build server.
Thanks,
Madhuri
Hi,
I have setup my build agent on a Mac. I have an Android project with Multidex and proguard enabled.
I have installed JDK 8 and updated proguard to the latest version. Unforunately now I am getting an out of memory errror. I have the Java Heap Size set to 1GB in my Android csproj file.
The error:
error XA5213: java.lang.OutOfMemoryError. Consider increasing the value of $(JavaMaximumHeapSize). Java ran out of memory while executing 'java -Xmx1G -jar
Here is my configuration:

Any help would be greatly appreciated.
Based on this thread (https://forums.xamarin.com/discussion/2132/java-heap-space-outofmemoryerror-when-binding-a-big-jar), you might have to change the setting in the .csproj in multiple places for different configurations/platforms.
Please try passing /p:JavaMaximumHeapSize=1G in "Msbuild > Additional Arguments" and see if it helps.
Thanks,
Madhuri
Thanks for the help. In the end I had to increase the Heap Size to 2G to get it working. Strange since it was building on other machines with 1G and I have never had to go higher than that.
It took a while but at least its finally building. Summary of what was done in case anyone has a similar scenario:
To Build on Mac VSTS Agent:
To Build on Visual Studio Windows machine:
Hiya,
I'm currently experiencing the same issue, we are unable to build on both Mac in The Cloud Agents and also hosted VSTS agents.
We've had to revert to running jenkins internally as a build server for the Android portion of our Xamarin project.
Is this likely to be fixed soon?
We are experiencing the same problem using VSTS Hosted or Hosted 2017, any ETA on a fix?
@smedel did you ever get this working? I'm now getting the same error as you
2017-08-28T16:02:29.4246673Z ##[error]C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2037,3): Error MSB6006: "java.exe" exited with code 1.
Hosted with ProGuard and Multi-Dex on
1GB Java Heap Size
Any help would be appreciated.
Thanks in advance,
Stephen
The VMs on Hosted VS2017 queue have been updated with latest Xamarin version which has the fix for the original issue on this thread - Xamarin build fail with ProGuard + multidex when there are spaces in the AndroidSDK folder. So we are closing this issue.
In my offline conversation with @smedel, we found that removing spaces in output paths helped him resolve the issue as well.
I am closing this issue since the original issue is resolved and the thread is getting too long. Please create a new issue if you have other problems.
@madhurig thanks for the update, awesome timing !! The project now builds if I just have just multidex on, which is fine for our requirements.
FYI, if I have ProGuard + multidex on I get:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1929,3): Error MSB6006: "java.exe" exited with code 1.
Process 'msbuild.exe' exited with code '1'.
Thanks again for all your help. Awesome! 馃憤
@madhurig same here as @YARG
@ramyzbeidy @YARG: Seems like you are seeing another issue. Please open a new issue with details. If you can attach the logs from your build or email them to me (madhurig at microsoft.com), I can investigate.
Thanks,
Madhuri
Most helpful comment
While we are continuing to work with Xamarin team on the bugs, I have a workaround that can be applied to build on the Hosted and Hosted VS 2017 VM pools.
Download latest proguard from: https://sourceforge.net/projects/proguard/files/proguard/5.3/ and commit/push to your repository.
In the build definition use "Extract Files" to unzip to a location without spaces, I set it to $(build.sourcesdirectory)

If using "Hosted VS 2017" pool, a symlink needs to be created for the Android SDK location so the path does not have spaces. This is not required for "Hosted" pool. Create a batch script and commit to your repo with this command: _mklink /J C:\AndroidSDK "C:\Program Files (x86)\Androidandroid-sdk"_

If you have MultiDex enabled, Use "Copy Files" task to copy the extracted latest proguard to AndroidSDK directory. Make sure you check the "Overwrite" option in "Advanced" section.

In the Xamarin Android task "MSBuild Options > Additional Arguments", set

(Hosted pool)
/p:ProguardToolPath=$(build.sourcesdirectory)\proguard5.3.3\
(Hosted VS 2017 pool)
/p:AndroidSdkDirectory=C:\AndroidSDK /p:ProguardToolPath=$(build.sourcesdirectory)\proguard5.3.3\
Thanks,
Madhuri