'XML not found in android module

I am configuring my android application for on demand delivery. The app uses Device Administrator API which I am trying to break down in separate module. Now the application have app module and admin module

Device Administrator requires a xml file which list the admin polices that app would like to use. When this xml file is moved to admin module (admin/res/xml/device_admin_policies.xml) android studio generates following android resource linking error

ERROR:...\app\build\intermediates\packaged_manifests\debug\AndroidManifest.xml:376: AAPT: error: resource xml/device_admin_policies (aka com.app.package:xml/device_admin_policies) not found.

Do note that the error is coming in merged manifest generate at compile time. If I move back this file to app module it works.

I am experimenting something with Device Admin API and for that I need this xml file to be in admin module. I am not sure if its possible to point it somehow to get the file from admin module.

Admin Module Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:dist="http://schemas.android.com/apk/distribution"
    package="com.app.package.ad">

    <dist:module
        dist:instant="false"
        dist:title="@string/title_lock">
        <dist:delivery>
            <dist:install-time />
        </dist:delivery>

        <dist:fusing dist:include="false" />
    </dist:module>

    <application android:hasCode="true">
        <activity
            android:name=".MainActivity"
            android:exported="false" />

        <activity android:name=".AdminPermissionActivity" />

        <receiver
            android:name=".admin.DeviceAdministrator"
            android:permission="android.permission.BIND_DEVICE_ADMIN"
            android:exported="false">
            <meta-data
                android:name="android.app.device_admin"
                android:resource="@xml/device_admin_policies" />

            <intent-filter>
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
                <action android:name="android.app.action.DEVICE_ADMIN_DISABLED" />
                <action android:name="android.app.action.ACTION_PASSWORD_FAILED" />
                <action android:name="android.app.action.ACTION_PASSWORD_SUCCEED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

xml file (device_admin_policies.xml)

<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-policies>
        <force-lock />
        <disable-keyguard-features />
        <watch-login />
    </uses-policies>
</device-admin>


Solution 1:[1]

When AAPT complains that it cannot find a XML resource file, this is a given fact.
The file would be expected at: src/main/res/xml/device_admin_policies.xml.

Packaging base module resources into a dynamic feature module won't work ...
it's only possible to reference base module resources in a dynamic feature module.

Solution 2:[2]

Eliminating View Lookups

The most basic thing we get with data binding is the elimination of findViewById. To enable this to work for a layout file, first we need to change the layout file by making the outer tag instead of whatever ViewGroup you use (note that the XML namespaces should also be moved):

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context=".MainActivity">

    <TextView
            android:id="@+id/tvLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

</RelativeLayout>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Umesh Thapa