androidlintandroid-lintairwatch

Issue: Implementing app restrictions and Lint Errors in app_restrictions.xml


I am working on Android MDM and have the app_restrictions.xml file under /src/main/res/xml/ folder. The MDM I am using is not showing me the value of the restriction, not even the default value. All the steps mentioned in this link has been followed to set app restrictions: https://developer.android.com/training/enterprise/app-restrictions.html but i am getting Bundle[EMPTY_PARCEL]. below is the code

app_restrictions.xml

<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">
<restriction
android:key="MDMEmailKey"
android:title="Email"
android:restrictionType="string"
android:description="@string/email_address_mdm_description"
android:defaultValue="testtesttest@gmail.com" />
<restriction/>
</restrictions>

Also, the lint is showing me below errors, though I was able to suppress it in gradle through lint options, but just wondering if it is not the cause of the issue I am facing. Please let me know why I am getting these errors.

Executing task ':project_name:lintVitalRelease' (up-to-date check took 0.0 secs) due to:
  Task has not declared any outputs.
.../src/main/res/xml/app_restrictions.xml:8: Error: Missing required attribute android:key [ValidRestrictions]
    <restriction/>
    ~~~~~~~~~~~~~~
.../src/main/res/xml/app_restrictions.xml:8: Error: Missing required attribute android:restrictionType [ValidRestrictions]
    <restriction/>
    ~~~~~~~~~~~~~~
.../src/main/res/xml/app_restrictions.xml:8: Error: Missing required attribute android:title [ValidRestrictions]
    <restriction/>
    ~~~~~~~~~~~~~~

   Explanation for issues of type "ValidRestrictions":
   Ensures that an applications restrictions XML file is properly formed

   https://developer.android.com/reference/android/content/RestrictionsManager.html

3 errors, 0 warnings

Solution

  • RE: The lint errors You have an empty restriction element at line 8 <restriction/> Just remove it and the lint errors will go away.

    <?xml version="1.0" encoding="utf-8"?>
    <restrictions xmlns:android="http://schemas.android.com/apk/res/android">
    <restriction
    android:key="MDMEmailKey"
    android:title="Email"
    android:restrictionType="string"
    android:description="@string/email_address_mdm_description"
    android:defaultValue="testtesttest@gmail.com" />
    <restriction/> <!-- Error here -->
    </restrictions>