android: Xamarin Android Application fails to build and deploy on a multi dex project.
I decided to migrate the application to androidx using the migration tool. The migration process was successful. The only issue I am experiencing is to build the application on different configurations and also the application fails to deploy upon successful build process.
Steps to Reproduce
- If I set the up this property in the csproj file
<AndroidDexTool>r8</AndroidDexTool>The application is able to build successfully without any error where i have no idea if this is the right way to assign the dex tool since it has only d8 and dx dex compiler - If I set up the correct way d8/r8 in the csproj file
<AndroidEnableMultiDex>True</AndroidEnableMultiDex> <AndroidDexGenerator>d8</AndroidDexGenerator><AndroidLinkTool>r8</AndroidLinkTool>I get a R8 error stating that missing class - okhttp3.callback which I have no nugget library reference for the class in my project. - If I set up the default Dex tool before xamarin android 10.2
<AndroidEnableMultiDex>True</AndroidEnableMultiDex> <AndroidDexGenerator>d8</AndroidDexGenerator>I get a COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: androidx.browser.trusted
Expected Behavior
The application should build and debug without any issues.
Actual Behavior
Based on the steps reproduce above here is the following behaviours:
- From the first step for reproduce the application fails to deploy on both emulator and device.
- From the second step for reproduce the application fails to build successfully.
- From the third step for reproduce the application fails to build successfully
Version Information
Microsoft Visual Studio Enterprise 2019 Version 16.5.0 VisualStudio.16.Release/16.5.0+29911.84 Microsoft .NET Framework Version 4.8.03752
Xamarin 16.5.000.521 (d16-5@b3ea41e) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Designer 16.5.0.470 (remotes/origin/d16-5@681de3fd6) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin Templates 16.5.49 (0904f41) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.
Xamarin.Android SDK 10.2.0.100 (d16-5/988c811) Xamarin.Android Reference Assemblies and MSBuild support. Mono: c0c5c78 Java.Interop: xamarin/java.interop/d16-5@fc18c54 ProGuard: xamarin/proguard/master@905836d SQLite: xamarin/sqlite/3.28.0@46204c4 Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-5@9f4ed4b
Xamarin.iOS and Xamarin.Mac SDK 13.14.1.39 (30e8706) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
Error Log File for step 1
Sample log from the first step reproduced:
ADB0010: Deployment failed
Mono.AndroidTools.InstallFailedException: Failure [INSTALL_FAILED_INVALID_APK: Package couldn’t be installed in /data/app/com.moot_technologies.moot_Technologies-1: Package /data/app/com.moot_technologies.moot_Technologies-1/base.apk code is missing]
at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName) in E:\A_work\277\s\External\androidtools\Mono.AndroidTools\Internal\AdbOutputParsing.cs:line 341
at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass95_0.<InstallPackage>b__0(Task1 t) in E:\A\_work\277\s\External\androidtools\Mono.AndroidTools\AndroidDevice.cs:line 753 at System.Threading.Tasks.ContinuationTaskFromResultTask1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at AndroidDeviceExtensions.<PushAndInstallPackage>d__11.MoveNext() in E:\A_work\277\s\External\androidtools\Xamarin.AndroidTools\Devices\AndroidDeviceExtensions.cs:line 187
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at AndroidDeviceExtensions.<PushAndInstallPackage>d__11.MoveNext() in E:\A_work\277\s\External\androidtools\Xamarin.AndroidTools\Devices\AndroidDeviceExtensions.cs:line 203
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Xamarin.AndroidTools.AndroidDeploySession.<InstallPackage>d__112.MoveNext() in E:\A_work\277\s\External\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 433
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Xamarin.AndroidTools.AndroidDeploySession.<RunAsync>d__106.MoveNext() in E:\A_work\277\s\External\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 217
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Xamarin.AndroidTools.AndroidDeploySession.<RunLoggedAsync>d__104.MoveNext() in E:\A_work\277\s\External\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 119
ADB0010: Mono.AndroidTools.InstallFailedException: Failure [INSTALL_FAILED_INVALID_APK: Package couldn’t be installed in /data/app/com.moot_technologies.moot_Technologies-1: Package /data/app/com.moot_technologies.moot_Technologies-1/base.apk code is missing]
at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName) in E:\A_work\277\s\External\androidtools\Mono.AndroidTools\Internal\AdbOutputParsing.cs:line 341
at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass95_0.<InstallPackage>b__0(Task1 t) in E:\A\_work\277\s\External\androidtools\Mono.AndroidTools\AndroidDevice.cs:line 753 at System.Threading.Tasks.ContinuationTaskFromResultTask1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at AndroidDeviceExtensions.<PushAndInstallPackage>d__11.MoveNext() in E:\A_work\277\s\External\androidtools\Xamarin.AndroidTools\Devices\AndroidDeviceExtensions.cs:line 187
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at AndroidDeviceExtensions.<PushAndInstallPackage>d__11.MoveNext() in E:\A_work\277\s\External\androidtools\Xamarin.AndroidTools\Devices\AndroidDeviceExtensions.cs:line 203
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Xamarin.AndroidTools.AndroidDeploySession.<InstallPackage>d__112.MoveNext() in E:\A_work\277\s\External\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 433
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Xamarin.AndroidTools.AndroidDeploySession.<RunAsync>d__106.MoveNext() in E:\A_work\277\s\External\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 217
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Xamarin.AndroidTools.AndroidDeploySession.<RunLoggedAsync>d__104.MoveNext() in E:\A_work\277\s\External\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 119
Done building project “Moot Technologies.csproj” – FAILED.
Any solution to correct the above error will be apprecaited.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (6 by maintainers)
@brendanzagaeski thank you for your reply. Since my project has dex classes over 65K i removed the other properties as suggested in step 1 from the project file. I decided to go with step 2 but I still get the same error from R8 in the logs. This is the error that I am getting:
R8 : warning : Missing class: okhttp3.CallbackR8 : error : Compilation can't be completed because some library classes are missing.I attached the ms build diagnostic file. Output-Build Log with AndroidMultiDex enabled.txt
@EmilAlipiev, in case you’re still curious about about those questions, there’s no harm in setting
AndroidEnableMultiDextotruewhen using both D8 and R8, but if the minimum Android version is set to Android 5.0 Lollipop (API level 21) or higher, thenAndroidEnableMultiDexwon’t change any build behavior because the R8 tool itself automatically enables multidex in that case.That was an old incorrect property name that Visual Studio was setting in a couple versions back in 2017: https://xamarin.github.io/bugzilla-archives/56/56192/bug.html. That property can safely be removed from any projects where it is present.
@oriolnoya I attach the proguard file that I used to solve compilation issues. r8.txt The MSBuild will give any missing classes that is not included in the proguard when your application crash at startup. The missing classes that will be detected during build and runtime you add there class names or nuget packages if they have dependencies. Let me know if you are able to successfully build and run your project without any issues.
Thanks
Thanks for the report!
For (1), as you suspected,
<AndroidDexTool>r8</AndroidDexTool>is not valid. SettingAndroidDexToolto any value exceptd8ordxcauses the build to skip the DEX compilation phase completely, so no DEX files are created for the application, resulting in the “code is missing” error. I have submitted a separate issue about improving the error message for that scenario: https://github.com/xamarin/xamarin-android/issues/4439.For 2 and 3, note that the name
AndroidDexGeneratoris not used by Xamarin.Android. It won’t cause problems to set that property, but also won’t do anything.AndroidDexGeneratorwas mentioned on https://github.com/xamarin/xamarin-android/issues/2040, but the final property name that was implemented wasAndroidDexTool, as documented on https://docs.microsoft.com/xamarin/android/deploy-test/building-apps/build-process.Next steps
Try setting your project back to the current recommended defaults. For example, remove all of the following properties from the .csproj file:
AndroidEnableMultiDexAndroidDexGeneratorAndroidLinkToolAndroidDexToolThis will let Xamarin.Android pick the current latest default values.
If the build fails after step 1 because of the DEX 64K reference limit, you can set
AndroidEnableMultiDexback toTrue. The reason to try leaving it blank for step 1 is that Xamarin.Android 9.4 reduced the number of DEX references for common app scenarios, so multidex is often no longer needed.If step 1 or 2 fails for a different reason (other than the DEX 64K reference limit), please collect the diagnostic MSBuild output for the failing build:
Set Tools > Options > Project and Solutions [section] > Build and Run [subsection] > MSBuild project build output verbosity to Diagnostic.
Build the app again to get the error.
Open the View > Output window, and set Show output from to Build.
Make sure the Output window is selected, and then choose File > Save Output As to save the contents to a text file. Or copy and paste the build output into a text file.
Zip up and attach back the file on this item. Note that the diagnostic Build output does contain environment variables, such as the Windows user name, so if you prefer to attach it privately a few options are:
/query @brendanzagaeskicommand from within the Xamarin.Android Gitter channel, and we can coordinate on another way to send the file non-publicly.If step 1 or 2 succeeds but you wish to enable R8 for app size reasons, you can now enable it at this step. If the build now fails, then again, please collect and attach back the diagnostic MSBuild output.
Thanks!