Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

R8 enabled gives build error: Compilation can't be completed because some library classes ar

SMobileSMobile NLUniversity ✭✭
edited December 2019 in Xamarin.Android

Currently we are trying to change the Multi-dex from dx to D8 but unfortunately we are getting a build error after doing this.

The build error we get is:

R8 : warning : Missing class: com.samsung.android.fingerprint.FingerprintManager$EnrollFinishListener
R8 : warning : Missing class: com.samsung.android.fingerprint.FingerprintIdentifyDialog$FingerprintListener
R8 : warning : Missing class: android.arch.paging.PositionalDataSource
R8 : warning : Missing class: com.samsung.android.fingerprint.IFingerprintClient$Stub
R8 : error : Compilation can't be completed because some library classes are missing.
104 Warning(s)
1 Error(s)

Time Elapsed 00:01:21.69

========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

Because of this error I though there was something wrong with one of the libraries we are using (https://github.com/smstuebe/xamarin-fingerprint) but when I create a new Android project and only add this nuget package to the project and enable D8, I don't get the above build error.

So my question is, what could be the reason for this build error? I tried to change several settings in .csproj but none of them worked.

Note: for dx we had to add these two lines in the csproj:

<DxExtraArguments>--force-jumbo </DxExtraArguments>
<AndroidMultiDexClassListExtraArgs>--disable-annotation-resolution-workaround</AndroidMultiDexClassListExtraArgs>

Without these two lines we get the following error while building with Multi-dex (Dx)
com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded

So maybe we need a D8 equivalent for these two lines of code?

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited December 2019

    To enable the new behavior, we need to introduce the property in csproj file.

    • $(AndroidDexTool) - supports dx or r8
    <Project>
        <PropertyGroup>
            <AndroidEnableMultiDex>True</AndroidEnableMultiDex>
            <!--New properties-->
            <AndroidDexTool>r8</AndroidDexTool>
        </PropertyGroup>
    </Project>
    

    Detailed explanation of Android’s R8 dexer:
    https://devblogs.microsoft.com/xamarin/androids-d8-dexer-and-r8-shrinker/
    https://github.com/xamarin/xamarin-android/blob/master/Documentation/guides/D8andR8.md#so-how-do-developers-use-it-what-are-sensible-msbuild-property-defaults

  • SMobileSMobile NLUniversity ✭✭

    That is what I did but that results in the build error I described.

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited December 2019

    Try the following steps:
    1.Add the two setting in csproj file:

    <AndroidDexTool>r8</AndroidDexTool>
    <AndroidEnableMultiDex>true</AndroidEnableMultiDex>
    

    2.Add library in AndroidManifest.xml:

    <uses-library android:name="org.apache.http.legacy" android:required="false" />
    

    3.Install nuget packages to add references to the missing class.

    Check the link:
    https://github.com/xamarin/xamarin-android/issues/2693#issuecomment-514698561

  • SMobileSMobile NLUniversity ✭✭
    edited December 2019

    Thanks for you response @Jarvan

    I am doing exactly what you described but the error doesn't disappear.

    Build error:

    R8 : warning : Missing class: com.samsung.android.fingerprint.FingerprintManager$EnrollFinishListener
    R8 : warning : Missing class: com.samsung.android.fingerprint.FingerprintIdentifyDialog$FingerprintListener
    R8 : warning : Missing class: android.arch.paging.PositionalDataSource
    R8 : warning : Missing class: com.samsung.android.fingerprint.IFingerprintClient$Stub
    R8 : error : Compilation can't be completed because some library classes are missing.
    105 Warning(s)
    1 Error(s)

    Time Elapsed 00:01:13.58
    ========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    I thought maybe it has something to do with the Plugin.Fingerprint nuget package since the missing class contains fingerprint in the package name. So what I did was creating a new empty Xamarin.Android project and added this nuget package as reference and after that I enabled the D8 Multidex in the csproj.
    The result of this was that it worked. So it seems nothing to do with the Plugin.Fingerprint nuget package.

    The packages we are using in our project are:

      <package id="CClarke.Plugin.Calendars" version="1.0.14" targetFramework="monoandroid90" />
      <package id="Com.Airbnb.Android.Lottie" version="3.0.3" targetFramework="monoandroid90" />
      <package id="FlexboxLayoutXamarinBindingAndroid" version="1.0.2" targetFramework="monoandroid80" />
      <package id="FubarCoder.RestSharp.Portable.Core" version="4.0.8" targetFramework="monoandroid70" />
      <package id="FubarCoder.RestSharp.Portable.HttpClient" version="4.0.8" targetFramework="monoandroid70" />
      <package id="Glide.Xamarin" version="4.1.1" targetFramework="monoandroid81" />
      <package id="Microsoft.AppCenter" version="2.6.4" targetFramework="monoandroid90" />
      <package id="Microsoft.AppCenter.Analytics" version="2.6.4" targetFramework="monoandroid90" />
      <package id="Microsoft.AppCenter.Crashes" version="2.6.4" targetFramework="monoandroid90" />
      <package id="Microsoft.AppCenter.Distribute" version="2.6.4" targetFramework="monoandroid90" />
      <package id="Microsoft.NETCore.Platforms" version="2.2.1" targetFramework="monoandroid90" />
      <package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="monoandroid90" />
      <package id="MimeMapping" version="1.0.1.26" targetFramework="monoandroid90" />
      <package id="modernhttpclient-updated" version="3.3.4" targetFramework="monoandroid90" />
      <package id="MvvmCross" version="6.3.1" targetFramework="monoandroid90" />
      <package id="MvvmCross.Droid.Support.Core.UI" version="6.3.1" targetFramework="monoandroid90" />
      <package id="MvvmCross.Droid.Support.Design" version="6.3.1" targetFramework="monoandroid90" />
      <package id="MvvmCross.Droid.Support.Fragment" version="6.3.1" targetFramework="monoandroid90" />
      <package id="MvvmCross.Droid.Support.V7.AppCompat" version="6.3.1" targetFramework="monoandroid90" />
      <package id="MvvmCross.Droid.Support.V7.RecyclerView" version="6.3.1" targetFramework="monoandroid90" />
      <package id="MvvmCross.Plugin.Color" version="6.3.1" targetFramework="monoandroid90" />
      <package id="MvvmCross.Plugin.File" version="6.3.1" targetFramework="monoandroid90" />
      <package id="MvvmCross.Plugin.Json" version="6.3.1" targetFramework="monoandroid90" />
      <package id="MvvmCross.Plugin.Messenger" version="6.3.1" targetFramework="monoandroid90" />
      <package id="MvvmCross.Plugin.PhoneCall" version="6.3.1" targetFramework="monoandroid90" />
      <package id="MvvmCross.Plugin.Visibility" version="6.3.1" targetFramework="monoandroid90" />
      <package id="MvvmCross.Plugin.WebBrowser" version="6.3.1" targetFramework="monoandroid90" />
      <package id="NETStandard.Library" version="2.0.3" targetFramework="monoandroid90" />
      <package id="Newtonsoft.Json" version="12.0.3" targetFramework="monoandroid90" />
      <package id="PInvoke.BCrypt" version="0.5.184" targetFramework="monoandroid90" />
      <package id="PInvoke.Kernel32" version="0.5.184" targetFramework="monoandroid90" />
      <package id="PInvoke.NCrypt" version="0.5.184" targetFramework="monoandroid90" />
      <package id="PInvoke.Windows.Core" version="0.5.184" targetFramework="monoandroid90" />
      <package id="Plugin.CurrentActivity" version="2.1.0.4" targetFramework="monoandroid81" />
      <package id="Plugin.Fingerprint" version="1.4.9" targetFramework="monoandroid90" />
      <package id="Plugin.MediaManager" version="0.4.8-beta" targetFramework="monoandroid81" />
      <package id="Plugin.Permissions" version="3.0.0.12" targetFramework="monoandroid90" />
      <package id="Plugin.PushNotification" version="3.0.8" targetFramework="monoandroid90" />
      <package id="Polly" version="7.2.0" targetFramework="monoandroid90" />
      <package id="Refractored.Controls.CircleImageView" version="1.0.1" targetFramework="monoandroid71" />
      <package id="app.components" version="2.0.74" targetFramework="monoandroid90" />
      <package id="SharpRetry" version="1.0.0" targetFramework="monoandroid90" />
      <package id="SQLiteNetExtensions" version="2.1.0" targetFramework="monoandroid90" />
      <package id="SQLiteNetExtensions.Async" version="2.1.0" targetFramework="monoandroid90" />
      <package id="sqlite-net-pcl" version="1.6.292" targetFramework="monoandroid90" />
      <package id="sqlite-net-sqlcipher" version="1.6.292" targetFramework="monoandroid90" />
      <package id="SQLitePCLRaw.bundle_green" version="1.1.13" targetFramework="monoandroid90" />
      <package id="SQLitePCLRaw.bundle_sqlcipher" version="1.1.13" targetFramework="monoandroid90" />
      <package id="SQLitePCLRaw.core" version="1.1.13" targetFramework="monoandroid90" />
      <package id="SQLitePCLRaw.lib.e_sqlite3.android" version="1.1.13" targetFramework="monoandroid90" />
      <package id="SQLitePCLRaw.lib.sqlcipher.android" version="1.1.13" targetFramework="monoandroid90" />
      <package id="SQLitePCLRaw.provider.e_sqlite3.android" version="1.1.13" targetFramework="monoandroid90" />
      <package id="SQLitePCLRaw.provider.sqlcipher.android" version="1.1.13" targetFramework="monoandroid90" />
      <package id="Square.OkHttp3" version="3.8.1" targetFramework="monoandroid90" />
      <package id="Square.OkIO" version="1.15.0" targetFramework="monoandroid90" />
      <package id="System.Collections.Immutable" version="1.7.0" targetFramework="monoandroid90" />
      <package id="System.ComponentModel.Annotations" version="4.7.0" targetFramework="monoandroid90" />
      <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="monoandroid90" />
      <package id="Validation" version="2.4.22" targetFramework="monoandroid90" />
      <package id="Xam.Plugin.Media" version="4.0.1.5" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Arch.Core.Common" version="1.1.1.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Arch.Core.Runtime" version="1.1.1.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Arch.Lifecycle.Common" version="1.1.1.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Arch.Lifecycle.Extensions" version="1.1.1.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Arch.Lifecycle.LiveData" version="1.1.1.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Arch.Lifecycle.LiveData.Core" version="1.1.1.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Arch.Lifecycle.Runtime" version="1.1.1.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Arch.Lifecycle.ViewModel" version="1.1.1.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Arch.Persistence.Db" version="1.1.1.1" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Arch.Persistence.Db.Framework" version="1.1.1.1" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Arch.Persistence.Room.Common" version="1.1.1.1" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Arch.Persistence.Room.Runtime" version="1.1.1.1" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Arch.Work.Runtime" version="1.0.0" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Maps.Utils" version="0.5.1-beta2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.Annotations" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.AsyncLayoutInflater" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.Collections" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.Compat" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.CoordinaterLayout" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.Core.UI" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.Core.Utils" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.CursorAdapter" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.CustomTabs" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.CustomView" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.Design" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.DocumentFile" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.DrawerLayout" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.Fragment" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.Interpolator" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.Loader" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.LocalBroadcastManager" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.Media.Compat" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.Print" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.SlidingPaneLayout" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.SwipeRefreshLayout" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.Transition" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.v4" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.v7.AppCompat" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.v7.CardView" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.v7.RecyclerView" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.Vector.Drawable" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.VersionedParcelable" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.Android.Support.ViewPager" version="28.0.0.3" targetFramework="monoandroid90" />
      <package id="Xamarin.AndroidSwipeLayout" version="1.2.0.2" targetFramework="monoandroid80" />
      <package id="Xamarin.Build.Download" version="0.4.11" targetFramework="monoandroid90" />
      <package id="Xamarin.Essentials" version="1.3.1" targetFramework="monoandroid90" />
      <package id="Xamarin.Firebase.Analytics" version="71.1606.0" targetFramework="monoandroid90" />
      <package id="Xamarin.Firebase.Analytics.Impl" version="71.1624.0" targetFramework="monoandroid90" />
      <package id="Xamarin.Firebase.Common" version="71.1610.0" targetFramework="monoandroid90" />
      <package id="Xamarin.Firebase.Iid" version="71.1710.0" targetFramework="monoandroid90" />
      <package id="Xamarin.Firebase.Iid.Interop" version="71.1601.0" targetFramework="monoandroid90" />
      <package id="Xamarin.Firebase.Measurement.Connector" version="71.1701.0" targetFramework="monoandroid90" />
      <package id="Xamarin.Firebase.Messaging" version="71.1740.0" targetFramework="monoandroid90" />
      <package id="Xamarin.Google.AutoValue.Annotations" version="1.6.5" targetFramework="monoandroid90" />
      <package id="Xamarin.Google.Guava.ListenableFuture" version="1.0.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.Ads.Base" version="71.1712.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.Ads.Identifier" version="71.1600.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.Analytics" version="71.1608.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.Analytics.Impl" version="71.1608.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.Base" version="71.1610.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.Basement" version="71.1620.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.Gass" version="71.1712.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.Gcm" version="71.1600.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.Iid" version="71.1600.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.Maps" version="71.1600.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.Measurement.Api" version="71.1604.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.Measurement.Base" version="71.1605.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.Stats" version="71.1601.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.TagManager.V4.Impl" version="71.1608.0" targetFramework="monoandroid90" />
      <package id="Xamarin.GooglePlayServices.Tasks" version="71.1601.0" targetFramework="monoandroid90" />
      <package id="Xamarin.Plugin.FilePicker" version="2.1.34" targetFramework="monoandroid90" />
      <package id="Xamarin.ShortcutBadger" version="1.1.21" targetFramework="monoandroid81" />
    
  • JarvanJarvan Member, Xamarin Team Xamurai
    edited December 2019

    The result of this was that it worked. So it seems nothing to do with the Plugin.Fingerprint nuget package.

    Have you tried to delete the files in obj and bin folders to rebuild the project?

  • SMobileSMobile NLUniversity ✭✭

    Yes I did. Does not help.

  • hanchhanch Member ✭✭

    Hey @StefanMobile , Have you solved it?
    Facing the same issues with an other nuget (Branch SDK)
    Tried all the steps you tried but getting the same problems... Is it just an immature VS integration?

  • SMobileSMobile NLUniversity ✭✭

    @hanch , no unfortunately I haven't found a solution yet.

  • IanVinkIanVink CAInsider, University ✭✭✭

    I am getting the exact same issue

  • IanVinkIanVink CAInsider, University ✭✭✭
    edited March 17

    I found a work around @StefanMobile @hauchr @Jarvan . It's about the multi-dex and the aapt2 and the Dex compiler.

    I kept playing with the settings randomly until I hit this:

    See image

  • JorgeRamirezJorgeRamirez CAUniversity ✭✭

    The setting options @IanVink suggested worked for me! Thanks a lot!

  • CarlosSantos.2644CarlosSantos.2644 USMember ✭✭

    @IanVink said:
    I found a work around @StefanMobile @hauchr @Jarvan . It's about the multi-dex and the aapt2 and the Dex compiler.

    I kept playing with the settings randomly until I hit this:

    See image

    worked for me, but now appears that when i run on android device.

  • guilloagguilloag Member ✭✭

    Same here after updating VS2019 to the last version 16.5.0.
    The proposed workaround is working and I'm getting a proper build after change those options, but I have another error when I try to run the app on my phone:

    (It's not my first round with xamarin, and I hate every time this happens[frequently], what a loss of productivity it is)

  • ClintonRocksmithClintonRocksmith AUMember, University, Developer Group Leader ✭✭

    We also get this problem

  • JajaHarrisJajaHarris USBeta, University ✭✭

    Updated to VS for Mac version 8.5 and Android app won't build now. Reference to Java.Interop is missing. Thanks for any help!

    https://stackoverflow.com/questions/60841324/java-interop-missing-after-upgrading-to-vs-for-mac-8-5

  • JajaHarrisJajaHarris USBeta, University ✭✭
    edited March 25

    Was able to add reference to Java.Interop.dll by browsing to the file using path below. However I continue to get exact same build error as @guilloag . Were you ever able to figure out a solution? Thanks!

    ‎⁨Macintosh HD⁩ ▸ ⁨Library⁩ ▸ ⁨Frameworks⁩ ▸ ⁨Xamarin.Android.framework⁩ ▸ ⁨Versions⁩ ▸ ⁨9.0.0-20⁩ ▸ ⁨lib⁩ ▸ ⁨xamarin.android⁩ ▸ ⁨xbuild-frameworks⁩ ▸ ⁨MonoAndroid⁩ ▸ ⁨v1.0⁩

  • ClintonRocksmithClintonRocksmith AUMember, University, Developer Group Leader ✭✭

    We "kinda" got it working, but it's a bit of work.

    We upgraded the solution to AndroidX.

    Then we took that .csproj file and pulled in all our files and then slowly and methodically added each nuget package as it was needed.

    We made sure that our csproj file didn't contain any of these:-

    We also got rid of our linker.xml
    and the AndroidEvnironment file for mono settings
    We use Aapt2 to true
    Multidex is off

    Anyone else do anything?

  • IanVinkIanVink CAInsider, University ✭✭✭

    Try setting your project back to the current recommended defaults. For example, remove all of the following properties from the .csproj file via Notepad:

    AndroidEnableMultiDex
    AndroidDexGenerator
    AndroidLinkTool
    AndroidDexTool

    This will let Xamarin.Android pick the current latest default values.

  • ClintonRocksmithClintonRocksmith AUMember, University, Developer Group Leader ✭✭

    Wow, thank you Ian! That worked!

  • IanJonesIanJones AUUniversity ✭✭

    Worked for me to - much appreciated!

  • IanVinkIanVink CAInsider, University ✭✭✭

    open the csproj file for android and remove the element I metnioned above, then save teh file. VS 2019 will reload the defaults for an android project
    '

  • JajaHarrisJajaHarris USBeta, University ✭✭

    Just in case it helps anyone else, I followed the settings from another forum post (similar to recommendations on this post). Only worked for me though when I set Dex Compiler to d8 instead of dx.

  • NinineaNininea USUniversity ✭✭✭

    Hi there, above mentioned changes fixes build issue, but now I'm not able to install .apk file in my device (android 10). here is an error

    Mono.AndroidTools.InstallFailedException: Failure [INSTALL_FAILED_INVALID_APK: Scanning Failed.: Package /data/app/com.chronos.droid-co9o1SDUmsM7V2_RYHwgjA==/base.apk code is missing]
    
Sign In or Register to comment.