Are you wondering: what’s this
If you’re working with Xamarin.Forms and Microsoft’s App Center and you need push notifications going for you on the mobile target platforms, chances are that you also need to add the App Center Push SDK’s to your project so that the Android version can receive push notification correctly.
But, as soon as I added the Push SDK’s as a Nuget, I got the following problem:[crayon-60797c8c67bc8439184271/]
The solution is to enable Multidex for your project as indicated in this App Center Github issue: https://github.com/Microsoft/AppCenter-SDK-DotNet/issues/249
You can do this by selecting the Android project and opening its properties, selecting Android Build > Enable Multi-Dex:
After setting this option to true for the Debug and Release configurations, I committed the code and tried to run the build in MS App Center
While I was happily building the Release configuration, it suddenly stopped and the build breaks for my Xamarin Forms android project with error “java.exe” exited with code 2
Cycling up through the logs I found the same Too many field references to fit in one dex file issue had arisen.
Luckily, this Xamarin Forum answer pointed me into the right direction: https://forums.xamarin.com/discussion/comment/273277/#Comment_273277
I opened the x.Droid project file by right-clicking it in Visual Studio for Mac and selecting Tools > Edit File:
As you can see in the image below, the key “AndroidEnableMultiDex” was set to “true” for the Debug Configuration.
Unfortunately, this wasn’t the case for the release configuration. It seems that Visual Studio (for Mac) has some kind of bug that prevents the IDE from saving the enabled Multi-Dex value in its properties interface in the project file correctly.
Solution? Copy the code…
and paste it into your Release configuration (often indicated by ‘Release|AAnyCPU’):
To my surprise, the AndroidEnableMultiDex was removed as soon as I saved it. And thus the
This made me think that I needed to include another configuration targeted at Release configuration, but with the same blank indicators as the generic Debug configuration.
I did just that and added the key AndroidEnableMultiDex to it. It was preserved this time (
As soon as you add in the extra configuration, App Center Build will pick up the setting as desired and will continue to build, even when you’ve integrated the whole bundle of packages from Firebase so you can receive and handle (App Center’s) Push Notifications.
Hope this helps others to prevent wasting hours to get their build going for them.