1

I have a Xamarin Forms solution that builds successfully for all projects while targeting debug mode.

When I switch to target Release I can successfully build the iOS project but am unable to build the Android one.

I have been able to narrow this down to whether "linking" is enabled or disabled. When linking is set to none I can build in release. As soon as I try a release build with linking to set to "sdk assemblies only" the build frezzes i.e. no error just hangs requiring that i kill the MSBUILD in the task manager.

This has been tried on a number of versions of Visual Studio on different machines. Xamarin Forms version: 4.4 Target Android version: 9.0

How can I get this to build in release with linking enabled?

Thanks

psycho
  • 1,539
  • 4
  • 20
  • 36
  • > When I switch to target Release I can successfully build the iOS project but am unable to build the Android one. whats error for android? – Blu Feb 11 '20 at 13:38
  • No error at all. Just freezes and cannot use visual studio again until I kill MSBUILD in my task manager – psycho Feb 11 '20 at 13:45
  • Its strange, without any error cant suggest you any trick. And even everything looks fine – Blu Feb 11 '20 at 14:45

2 Answers2

2

Normally you should see linking errors, but I had similar problem when building in release mode for Android with firebase. You should check in your Android project properties if linking is targeting Sdk Assemblies only. If this one is ok, try to set linking assemblies in debug mode, and run application. If you got linking errors in output window note them down. Your next step now is to setup additional configuration file for proguard. Add proguard.cfg file to your Android project and make sure to set Build Action as ProguardConfiguration. Configure proguard to keep classes that are giving linking errors.

Example proguard configuration that fixes common linking errors:

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep class org.apache.http.** { *; }
-keep class org.apache.** { *; }
-dontwarn org.apache.**
-dontwarn org.apache.http.**
-dontwarn org.apache.commons.**
-keep class android.support.v7.widget.** { *; }
-dontwarn android.support.v7.widget.**
-keep class android.support.v4.widget.Space { *; }
-dontwarn android.support.v4.widget.Space
-dontwarn com.google.android.gms.**
-keep class com.google.android.gms.** { *; }
Adlorem
  • 1,457
  • 1
  • 11
  • 10
2

This seems to be a similar problem to:

Xamarin Android build just hangs when linker is enabled

The solution there was to remove explicit support for nullable reference types (enable) in the project file.

Its possible to remove this support in your own project files, but if a referenced 3rd party library has it you may be out of luck. Update such libraries to their latest version and if that still does not help the only option is to disable linking.

The problem is an incompatibility with the android linker and the above nullable reference support in some cases in the latest visual studio. This will be fixed in an upcoming release of visual studio and is already available in preview. If its an option to you to use the preview version of VS 2019 then this will also work.

  • Thanks Craig that was the issue. a VLC nuget package was causing the issue with the linker. After updating it to its latest version of the VLC nuget package the problem was resolved – psycho Feb 12 '20 at 12:00