android: D8 fails during Xamarin Android build with latest Xamarin.GooglePlayServices libraries

Steps to Reproduce

  1. Upgrade existing project from Xamarin.GooglePlayServices 71.x to the latest (currently 117.x and 118.x)
  2. Build
  3. Observe build error: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.D8.targets(79,5): error MSB6006: "java.exe" exited with code 1.

From a more detailed build log:

3>Using "D8" task from assembly "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Build.Tasks.dll".
3>Task "D8"
3>    processing ClassesZip, JavaLibrariesToEmbed...
3>  C:\Program Files\Android\Jdk\microsoft_dist_openjdk_1.8.0.25\bin\java.exe -Xmx1G -classpath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\r8.jar" com.android.tools.r8.D8 --debug --min-api 21 --output obj\Debug\110\android\bin\ --lib "C:\Program Files (x86)\Android\android-sdk\platforms\android-30\android.jar" --lib "C:\Program Files (x86)\Android\android-sdk\platforms\android-30\optional\org.apache.http.legacy.jar" obj\Debug\110\android\bin\classes.zip "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v11.0\mono.android.jar" "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\java_runtime_fastdev.jar" C:\Users\mfeingol\.nuget\packages\xamarin.androidx.annotation\1.2.0-alpha01\buildTransitive\monoandroid90\..\..\jar\androidx.annotation.annotation.jar C:\Users\mfeingol\.nuget\packages\xamarin.androidx.collection\1.1.0.5\buildTransitive\monoandroid90\..\..\jar\androidx.collection.collection.jar C:\Users\mfeingol\.nuget\packages\xamarin.androidx.lifecycle.common\2.3.0.2-alpha03\buildTransitive\monoandroid90\..\..\jar\androidx.lifecycle.lifecycle-common.jar C:\Users\mfeingol\.nuget\packages\xamarin.androidx.arch.core.common\2.1.0.6\buildTransitive\monoandroid90\..\..\jar\androidx.arch.core.core-common.jar obj\Debug\110\androidx\jl\beec42b2-4563-4f64-b3f9-7275054c29fe.jar obj\Debug\110\lp\10\jl\bin\classes.jar obj\Debug\110\lp\100\jl\classes.jar obj\Debug\110\lp\101\jl\classes.jar obj\Debug\110\lp\102\jl\classes.jar obj\Debug\110\lp\103\jl\classes.jar obj\Debug\110\lp\104\jl\classes.jar obj\Debug\110\lp\105\jl\classes.jar obj\Debug\110\lp\106\jl\classes.jar obj\Debug\110\lp\107\jl\classes.jar obj\Debug\110\lp\108\jl\classes.jar obj\Debug\110\lp\109\jl\classes.jar obj\Debug\110\lp\110\jl\classes.jar obj\Debug\110\lp\111\jl\classes.jar obj\Debug\110\lp\112\jl\classes.jar obj\Debug\110\lp\113\jl\classes.jar obj\Debug\110\lp\114\jl\classes.jar obj\Debug\110\lp\115\jl\classes.jar obj\Debug\110\lp\116\jl\classes.jar obj\Debug\110\lp\117\jl\classes.jar obj\Debug\110\lp\118\jl\classes.jar obj\Debug\110\lp\119\jl\classes.jar obj\Debug\110\lp\120\jl\classes.jar obj\Debug\110\lp\121\jl\classes.jar obj\Debug\110\lp\122\jl\classes.jar obj\Debug\110\lp\123\jl\classes.jar obj\Debug\110\lp\124\jl\classes.jar obj\Debug\110\lp\125\jl\classes.jar obj\Debug\110\lp\126\jl\classes.jar obj\Debug\110\lp\127\jl\classes.jar obj\Debug\110\lp\128\jl\classes.jar obj\Debug\110\lp\129\jl\classes.jar obj\Debug\110\lp\130\jl\classes.jar obj\Debug\110\lp\131\jl\classes.jar obj\Debug\110\lp\132\jl\classes.jar obj\Debug\110\lp\133\jl\classes.jar obj\Debug\110\lp\135\jl\classes.jar obj\Debug\110\lp\136\jl\classes.jar obj\Debug\110\lp\137\jl\classes.jar obj\Debug\110\lp\138\jl\classes.jar obj\Debug\110\lp\139\jl\classes.jar obj\Debug\110\lp\140\jl\classes.jar obj\Debug\110\lp\141\jl\classes.jar obj\Debug\110\lp\142\jl\classes.jar obj\Debug\110\lp\143\jl\classes.jar obj\Debug\110\lp\144\jl\classes.jar obj\Debug\110\lp\145\jl\classes.jar obj\Debug\110\lp\146\jl\classes.jar obj\Debug\110\lp\147\jl\classes.jar obj\Debug\110\lp\148\jl\classes.jar obj\Debug\110\lp\26\jl\bin\classes.jar obj\Debug\110\lp\4\jl\formsviewgroup.jar obj\Debug\110\lp\7\jl\bin\classes.jar obj\Debug\110\lp\72\jl\bin\classes.jar obj\Debug\110\lp\73\jl\bin\classes.jar obj\Debug\110\lp\74\jl\bin\classes.jar obj\Debug\110\lp\75\jl\bin\classes.jar obj\Debug\110\lp\76\jl\bin\classes.jar obj\Debug\110\lp\81\jl\auto-value-annotations.jar obj\Debug\110\lp\85\jl\bin\classes.jar obj\Debug\110\lp\9\jl\bin\classes.jar obj\Debug\110\lp\92\jl\bin\classes.jar obj\Debug\110\lp\96\jl\bin\classes.jar obj\Debug\110\lp\98\jl\classes.jar obj\Debug\110\lp\99\jl\classes.jar 
3>  Error in obj\Debug\110\lp\140\jl\classes.jar:com/google/android/gms/internal/measurement/zzfe$zza.class:
3>  Type com.google.android.gms.internal.measurement.zzfe$zza is defined multiple times: obj\Debug\110\lp\140\jl\classes.jar:com/google/android/gms/internal/measurement/zzfe$zza.class, obj\Debug\110\lp\72\jl\bin\classes.jar:com/google/android/gms/internal/measurement/zzfe$zza.class
3>  Compilation failed
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.D8.targets(79,5): error MSB6006: "java.exe" exited with code 1.
3>Done executing task "D8" -- FAILED.
3>Done building target "_CompileToDalvik" in project "Sideroads.Android.csproj" -- FAILED.

Expected Behavior

Successful compilation.

Actual Behavior

Failed compilation.

Version Information

VS 2019 16.7.6

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 17 (5 by maintainers)

Most upvoted comments

Thanks for the lists of packages! Using those sets of packages, I was able to reproduce the issue locally and identify the problem.

Candidate steps to fix for mfeingol

After updating the Xamarin.GooglePlayServices and Xamarin.Firebase packages to the latest versions, uninstall the Xamarin.Firebase.Analytics.Impl package. This package is no longer needed by any of the other dependencies in the project, and it causes the conflict.

Candidate steps to fix for hvaughan3

Uninstall the Xamarin.Firebase.Measurement.Connector.Impl package. This package is no longer needed by any of the other packages in the project, and it depends on the Xamarin.Firebase.Analytics.Impl package that causes the conflict.

Explanation

Google moved the location of com.google.android.gms.internal.measurement, leading to conflicts. com.google.android.gms.internal.measurement.zzu is defined in both Xamarin.Firebase.Analytics.Impl version 116.3.0 (the old location) and Xamarin.GooglePlayServices.Measurement.Base version 117.4.1 (the new location).

Xamarin.GooglePlayServices.Measurement.Base is the correct up-to-date new location for the API, so all references to the old Xamarin.Firebase.Analytics.Impl package need to be removed to avoid conflicts.

Excellent. Glad that worked!

How could we have figured this out ourselves?

Good question. One bit of cleanup that can help avoid some similar complications in the future is to take advantage of how PackageReference automatically brings in dependencies. For example, in this case, projects could have used just a PackageReference for just Xamarin.Firebase.Analytics all along, with no explicit PackageReference for Xamarin.Firebase.Analytics.Impl. For the old versions, the NuGet package restore process would automatically add the Xamarin.Firebase.Analytics.Impl dependency, and for the new versions it would automatically omit it.

The tricky thing is that I haven’t heard of an easy way to find redundant package references. It sounds like maybe ReSharper has a related feature.

Even if all the package references are minimized to a non-redundant set, I think there might be cases where the problem could still happen, so I’ll write down a manual investigation strategy too.

Manual investigation approach

Example error message:

Type com.google.android.gms.internal.measurement.zzu is defined multiple times: obj\Release\110\lp\1
40\jl\classes.jar:com/google/android/gms/internal/measurement/zzu.class, obj\Release\110\lp\157\jl\c
lasses.jar:com/google/android/gms/internal/measurement/zzu.class

The steps I followed were roughly:

  1. Extract the *.properties files from obj\Release\110\lp\140\jl\classes.jar and obj\Release\110\lp\157\jl\classes.jar to figure out which two NuGet packages cause the conflict.

    play-services-measurement-base.properties:

    version=17.4.1
    client=play-services-measurement-base
    play-services-measurement-base_client=17.4.1
    

    firebase-analytics-impl.properties:

    version=16.3.0
    client=firebase-analytics-impl
    firebase-analytics-impl_client=16.3.0
    
  2. Start to suspect that firebase-analytics-impl might be the problem because it is version 16.3.0 while the Xamarin.Firebase.Analytics NuGet package is version 17.4.1.

  3. Look up an old version of Xamarin.Firebase.Analytics on NuGet to check the dependencies:

    _https://www.nuget.org/packages/Xamarin.Firebase.Analytics/71.1630.4_:

    Xamarin.Build.Download (>= 0.7.0)
    Xamarin.Firebase.Analytics.Impl (>= 71.1630.4)
    Xamarin.Firebase.Common (>= 71.1610.4)
    Xamarin.GooglePlayServices.Basement (>= 71.1620.4)
    Xamarin.GooglePlayServices.Measurement.Api (>= 71.1630.4)
    Xamarin.GooglePlayServices.Measurement.Base (>= 71.1630.4)
    Xamarin.GooglePlayServices.Stats (>= 71.1601.4)
    

    And compare to the new version of Xamarin.Firebase.Analytics:

    _https://www.nuget.org/packages/Xamarin.Firebase.Analytics/117.4.1_:

    Xamarin.Build.Download (>= 0.10.0)
    Xamarin.GooglePlayServices.Measurement (>= 117.4.1)
    Xamarin.GooglePlayServices.Measurement.Api (>= 117.4.1)
    Xamarin.GooglePlayServices.Measurement.Sdk (>= 117.4.1)
    

I’ll also raise this scenario with the team as a potential area where the Xamarin.Android build process might be able to make at least step 1 a bit easier.

@gioggio79, thanks for the information! That’s the slightly different problem reported in xamarin/GooglePlayServicesComponents#379.

There’s a slightly tricky way to work around it by adding a customized PackageReference for Xamarin.Google.Guava that sets ExcludeAssets="all": xamarin/GooglePlayServicesComponents#379 (comment). Hopefully that’ll work in your case too!

Many thanks for you fast reply. In my case simply adding the Xamarin.Google.Guava v28.2.0 fix my export problem. Now i didn’t find class “com.google.common.io.BaseEncoding”, but it’s another story.

@brendanzagaeski: confirmed my candidate steps work, thanks.

How could we have figured this out ourselves?

@brendanzagaeski Yep same here, that fixed it. Thanks so much for your help and apologies for hijacking the issue.

Similar issue reported in Google Play Services repo: https://github.com/xamarin/GooglePlayServicesComponents/issues/379