1

I am trying to configure restrictions in my Application but I am getting following error

Error:(8, 30) String types not allowed (at 'description' with value 'Public Albums of this username will be fetched'). Error:Execution failed for task ':app:processDebugResources'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\athakur\Softwares\adt-bundle-windows-x86_64-20140702\sdk\build-tools\22.0.1\aapt.exe'' finished with non-zero exit value 1

My app_restriction.xml is as follows -

<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android" >

    <restriction
        android:key="google_username"
        android:title="Google Username"
        android:restrictionType="string"
        android:description="Public Albums of this username will be fetched"
        android:defaultValue="opensourceforgeeks" />

</restrictions>

If I remove description it works fine. I have used same syntax as specified on android dev page i.e

<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android" >

  <restriction
    android:key="downloadOnCellular"
    android:title="App is allowed to download data via cellular"
    android:restrictionType="bool"
    android:description="If 'false', app can only download data via Wi-Fi"
    android:defaultValue="true" />

</restrictions>

Not sure what I am missing. Any help is appreciated.

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289

2 Answers2

2

The description value for a Restriction element must be a String Resource, as documented here. Extracting the hardcoded text will therefore fix the build.

fractalwrench
  • 4,028
  • 7
  • 33
  • 49
  • By that logic it also says `android:title="string resource"` but as you see I am using plane String and not String resource. – Aniket Thakur Sep 25 '15 at 11:11
  • The title attribute allows both: https://developer.android.com/reference/android/R.styleable.html#RestrictionEntry_title – fractalwrench Sep 25 '15 at 11:17
  • 1
    Well they should update the [main documentation](https://developer.android.com/training/enterprise/app-restrictions.html#define_restrictions) then. Not every developer goes and sees specs of every small API argument. – Aniket Thakur Sep 25 '15 at 11:22
1

As @fractalwrench correctly pointed out description attribute can only point to a resource [ this documentation example is misleading. Plain text is not allowed ].

public static final int RestrictionEntry_description

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol description. Constant Value: 0 (0x00000000)

Documentation

Following worked for me

<restriction
    android:key="google_username"
    android:title="Google Username"
    android:restrictionType="string"
    android:description="@string/rest_uname_desc"
    android:defaultValue="opensourceforgeeks" />

with

<string name="rest_uname_desc">Public Albums of this username will be fetched</string>

in string.xml

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289