Forum Xamarin Xamarin.Android

Order of Elements in axml in Xamarin Android leads to compilation error

gulshan_mandalgulshan_mandal Member
edited August 2018 in Xamarin.Android

I am getting compilation error in axml where I have referenced the item before declaring it.

This is happening both for Relative Layout and Constraint Layout

As far as I know, Android doesn't have any such constraints. Moreover, if I copy paste the same layout in Android studio it works fine. I am using Visual Studio for Mac.

Does anyone know a workaround of this issue in Xamarin.Android

The error is:

 error APT0000: No resource found that matches the given name (at 'layout_below' with value '@id/textView1').

Here is my layout code (i have removed the namespace as it doesn't allow me to submit the post):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minWidth="25px"
    android:minHeight="25px">
    <Button
        android:id="@+id/button1"
        android:text="Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/textView1" />
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Hello World" />
</RelativeLayout>

Best Answer

  • YorkGoYorkGo CNMember, Xamarin Team Xamurai
    Accepted Answer

    @gulshan_mandal Thanks for your report.

    There are two issues here.

    1. One of your files has the Build Action of Content instead of AndroidResource.

    2. There does not exist a resource of @id/textView1 because it is on the last element in the XML/AXML file. You can read the comment here about this further:

    https://stackoverflow.com/questions/51842519/order-of-elements-in-axml-in-xamarin-android-leads-to-compilation-error#comment90652095_51842519

    The reason why this works in Android Studio is that it uses aapt2 by default. If you were to disable this manually, you would run into the same issue:

    i.e. in gradle.properties set:

    android.enableAapt2=false
    

    We do however support aapt2 which you can enable in your project by adding the following in your .csproj:

    <AndroidUseAapt2>True</AndroidUseAapt2>
    

Answers

Sign In or Register to comment.