xamarin.androidaapt2

aapt2 Removing resource * without required default value


When building a Xamarin.Android project it is written in the output window that aapt2 has removed resources due to a missing default value.

Xamarin.Android.Aapt2.targets(160,3): warning APT2000: warn: removing resource com.companyname.demo_app:drawable/parking_slot without required default value.

The removed resource is part of a Xamarin.Android binding project and is also included in the aar-file under drawables and in the R.txt.

Because it is only a log-statement in the build output, the project builds and the app can be started. But when using one part of the binding-project the following error will be thrown:

Java.Lang.NoSuchFieldError: 'No static field parking_slot of type l in class Lcom/company/sample/R$drawable; or its superclasses (declaration of 'com.company.sample.R$drawable' appears in /data/app/com.companyname.demo_app-Ab0cDefG==/base.apk)'

What does cause the removal of the resource and how can it be prevented?

Edit 1:

The missing resource parking_slot is not in the drawable folder but in drawable-xhdpi-v4 for example. To check this I renamed the aar to zip and extracted it.

I then copied parking_slot it to the drawable folder, zipped and renamed it to aar again. Building is now without the aapt2 warning. Yet the app crashes again with:

Java.Lang.NoClassDefFoundError: 'Failed resolution of: Lcom/company/sample/R$drawable;'

Solution

  • I tested the aar-file with a native non-Xamarin app and no issue came to my attention which brings me to the conclusion that something might be broken with the way the Xamarin app is build.

    Nevertheless the fix (or the workaround if you want) looks like this:

    1. Rename aar to zip and unzip.
    2. Search for the missing resource. In my case parking_slot
    3. Copy the missing resource into your app-project

    I think this works because of the way Androids fallback-system works.