Bitrise not enabling multi dex

I have a single repository using Xamarin to build both iOS and Android apps. My builds recently started failing with the following error message:

/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: 100702; max is 65536.
You may try using --multi-dex option.

To fix this locally, I have enabled multi dex locally in Visual Studio. Changing the setting in the Visual Studio UI makes this change in our ActivityApp.Droid.csproj file:

<AndroidEnableMultiDex>True</AndroidEnableMultiDex>

However, my Bitrise builds are still failing with the same error. Why doesn’t setting True in our .Droid.csproj file get picked up by Bitrise at build time and how can I fix this?

It seems like Bitrise should be picking the MultiDex setting automatically, because changing the setting in the Visual Studio UI makes this change in the .Droid.csproj file:
True

Hey!

What version do you use? Because xamarin had this issue not a long ago:

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

Is it possible that your xamarin version is <=4.5.0 ?

1 Like

Thanks for your reply. I am using Xamarin 4.5.0.486 (fec6f88) and Visual Studio Professional 2017 Version 15.2 (26430.16) with .NET Framework Version 4.7.02046

I tried the fix in the post you referenced - I set both of these flags in our android.csproj file:

<AndroidEnableMultiDex>true</AndroidEnableMultiDex>
<AndroidEnableMultipleDex>true</AndroidEnableMultipleDex>

to no avail. The build fails at the same point in the workflow (Xamarin Archive step) with the message:

Target _CompileToDalvikWithDx:
	Created directory "obj/Release/proguard"
	Tool /usr/bin/java execution started with arguments: -jar /Users/vagrant/Library/Developer/Xamarin/android-sdk-macosx/build-tools/25.0.2//lib/dx.jar --no-strict --dex --output=obj/Release/android/bin obj/Release/android/bin/classes /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v7.1/mono.android.jar obj/Release/__library_projects__/Bolts.AppLinks/library_project_imports/bin/classes.jar obj/Release/__library_projects__/Bolts.Tasks/library_project_imports/bolts-tasks.jar obj/Release/__library_projects__/GlideAssembly/library_project_imports/glide-3.7.0.jar obj/Release/__library_projects__/Square.OkHttp/library_project_imports/okhttp.jar obj/Release/__library_projects__/Square.OkIO/library_project_imports/okio.jar obj/Release/__library_projects__/Square.Picasso/library_project_imports/picasso-2.5.2.jar obj/Release/__library_projects__/XFrame.Braintree.BrowserSwitch.Droid/library_project_imports/bin/classes.jar obj/Release/__library_projects__/XFrame.Braintree.Card.Form.Droid/library_project_imports/bin/classes.jar obj/Release/__library_projects__/XFrame.Braintree.Core.Droid/library_project_imports/bin/classes.jar obj/Release/__library_projects__/XFrame.Braintree.Droid/library_project_imports/bin/classes.jar obj/Release/__library_projects__/XFrame.Braintree.DropIn.Droid/library_project_imports/bin/classes.jar obj/Release/__library_projects__/XFrame.PayPalOneTouch/library_project_imports/bin/classes.jar obj/Release/__library_projects__/Xamarin.Android.Support.Animated.Vector.Drawable/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Android.Support.Compat/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Android.Support.Core.UI/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Android.Support.Core.Utils/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Android.Support.CustomTabs/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Android.Support.Design/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Android.Support.Fragment/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Android.Support.Media.Compat/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Android.Support.Transition/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Android.Support.Vector.Drawable/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Android.Support.v4/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Android.Support.v7.AppCompat/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Android.Support.v7.RecyclerView/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Facebook/library_project_imports/bin/classes.jar obj/Release/__library_projects__/Xamarin.Firebase.Common/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Firebase.Iid/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.Firebase.Messaging/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.GooglePlayServices.Base/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.GooglePlayServices.Basement/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.GooglePlayServices.Identity/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.GooglePlayServices.Maps/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.GooglePlayServices.Tasks/library_project_imports/classes.jar obj/Release/__library_projects__/Xamarin.GooglePlayServices.Wallet/library_project_imports/classes.jar /Users/vagrant/.local/share/Xamarin/Xamarin.Android.Support.v7.CardView/23.4.0.0/embedded/classes.jar 
	trouble writing output: Too many field references: 100734; max is 65536.
	You may try using --multi-dex option.

It’s not clear whether Bitrise is recognizing the flags I’ve set or not. Any ideas what is going on?

With help from @tamaspapik, fixed the issue - I needed to set the multi-dex flag for all targets (debug/release/all cpus/x-86).

2 Likes

Thanks for reporting it here @clee46! :blush:

1 Like