Xamarin-android: D8-R8 fails with Missing class error without enough information

Created on 30 Jan 2019  路  3Comments  路  Source: xamarin/xamarin-android

I have enabled d8 and r8, disabled multidex and proguard. my configuration file can be seen here.
https://gist.github.com/EmilAlipiev/3ca3f0df6e054703d379250dd9237219

Project has definetly no reference mentioned classes in warnings below. I dont understand why do i get those warnings.

8>  R8 : warning : Missing class: com.amazon.device.messaging.ADMMessageReceiver
8>  R8 : warning : Missing class: com.amazon.device.messaging.ADMMessageHandlerBase
8>  R8 : warning : Missing class: com.amazon.device.iap.PurchasingListener
8>  R8 : warning : Missing class: org.apache.http.client.methods.HttpEntityEnclosingRequestBase

I dont even know if actually error mentioned in the log file related to those or some other classes

(Rebuild;BuiltProjectOutputGroup;BuiltProjectOutputGroupDependencies;DebugSymbolsProjectOutputGroup;DebugSymbolsProjectOutputGroupDependencies;DocumentationProjectOutputGroup;DocumentationProjectOutputGroupDependencies;SatelliteDllsProjectOutputGroup;SatelliteDllsProjectOutputGroupDependencies;SGenFilesOutputGroup;SGenFilesOutputGroupDependencies target) (1) ->
8>(_CompileToDalvikWithD8 target) -> 
8>  R8 : error : Compilation can't be completed because some library classes are missing.

see attached sample project
App1.zip

App+Library Build bug

Most helpful comment

org.apache.httpclient

Part of this error is solved by: https://github.com/xamarin/xamarin-android/pull/2736

After adding to AndroidManfest.xml:

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

Errors about org.apache.http go away: R8 : warning : Missing class: org.apache.http.client.methods.HttpEntityEnclosingRequestBase

It will be coming in a future VS 2019 release.

Amazon

First I downloaded the Amazon SDKs here: https://developer.amazon.com/sdk-download

I put these two jar files in the Android project:

  • amazon-device-messaging-1.0.1.jar
  • in-app-purchasing-2.0.76.jar

Then I added to my csproj:

<ItemGroup>
    <AndroidExternalJavaLibrary Include="amazon-device-messaging-1.0.1.jar" />
    <AndroidExternalJavaLibrary Include="in-app-purchasing-2.0.76.jar" />
</ItemGroup>

What this does is pass -libraryjar to proguard and -lib to r8. It allows these command-line tools to know about these libraries, but they won't get included in your final APK.

What can you do now? About the org.apache.httpclient thing?

You can find C:\Program Files (x86)\Android\android-sdk\platforms\android-28\optional\org.apache.http.legacy.jar. Include it in your Android project the same way as the Amazon stuff:

<AndroidExternalJavaLibrary Include="org.apache.http.legacy.jar" />

You will also need the AndroidManifest.xml changes. Here is a full project that worked for me with VS 2019 Preview 3: App1.zip

Hope this solves your issue!

All 3 comments

Problem seems to be with the onesignal nuget package referencing those namespaces and classes. please see the repro attached. it is still not clear for me why r8 returns warning or error for those. because i dont want to keep those classes and no where in my project, i access them.

org.apache.httpclient

Part of this error is solved by: https://github.com/xamarin/xamarin-android/pull/2736

After adding to AndroidManfest.xml:

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

Errors about org.apache.http go away: R8 : warning : Missing class: org.apache.http.client.methods.HttpEntityEnclosingRequestBase

It will be coming in a future VS 2019 release.

Amazon

First I downloaded the Amazon SDKs here: https://developer.amazon.com/sdk-download

I put these two jar files in the Android project:

  • amazon-device-messaging-1.0.1.jar
  • in-app-purchasing-2.0.76.jar

Then I added to my csproj:

<ItemGroup>
    <AndroidExternalJavaLibrary Include="amazon-device-messaging-1.0.1.jar" />
    <AndroidExternalJavaLibrary Include="in-app-purchasing-2.0.76.jar" />
</ItemGroup>

What this does is pass -libraryjar to proguard and -lib to r8. It allows these command-line tools to know about these libraries, but they won't get included in your final APK.

What can you do now? About the org.apache.httpclient thing?

You can find C:\Program Files (x86)\Android\android-sdk\platforms\android-28\optional\org.apache.http.legacy.jar. Include it in your Android project the same way as the Amazon stuff:

<AndroidExternalJavaLibrary Include="org.apache.http.legacy.jar" />

You will also need the AndroidManifest.xml changes. Here is a full project that worked for me with VS 2019 Preview 3: App1.zip

Hope this solves your issue!

Another quicker solution is to enable D8 as dex compiler, and R8 as code shrinker, and disable multidex in debug mode only.
All warnings will disappear as these missing classes are not used anyway, and will be optimized away by R8.

Was this page helpful?
0 / 5 - 0 ratings