Implementing managed configurations in NativeScript - android

I am developing a NativeScript app for android and wish to implement managed configurations as described here: https://developer.android.com/work/managed-configurations.html.
I have tried adding app_restrictions.xml to the App_Resources/Android/values folder but I get the following build error:
Execution failed for task ':mergeF0F1DebugResources'.
Error: Unsupported type 'restriction'
This is the content of app_restrictions.xml:
<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">
<restriction
android:key="downloadOnCellular"
android:restrictionType="bool"
android:defaultValue="true" />
</restrictions>
Does NativeScript support adding restrictions like this? If so, how do I add the restriction resource file. If not, is there some other way to implement managed configurations?
EDIT: Solved by pkanev in the comments. The restrictions file must be placed in App_Resources/Android/xml.

Per the official Android documentation - https://developer.android.com/work/managed-configurations.html
the restrictions configuration needs to be placed in res/xml dir, which corresponds to app/App_Resources/Android/xml in a NativeScript Android app.

Related

attribute android:shortcutLongLabel not found

Trying to test my android shortcuts but I keep getting an error stating that attribute android:shortcutLongLabel not found, and this continues with shorcutShortLabel, shortcutID, etc. Shouldn't make a difference but I am writing the app in kotlin, and am using compileSdkVersion 29.
Trying to add app shortcuts to my project. So I created the shortcuts.xml file and added it to res/xml/shortcuts.xml. I've made sure everything in Gradle was up to date, and have followed Google's documentation down to the dot on adding shortcuts in your app. I assume there is something wrong with either my Gradle or manifest.xml but I don't know what. Also when I hit F2 it says no errors found on this file.
<?xml version="1.0" encoding=utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut android:enable="true"
android:shortcutID="xxxx"
android:icon="#drawable/xxxxx"
android:shortcutShortLabel="#string/xxxx"
android:shortcutLongLabel="#string/xxxxx">
<intent android:action="android.intent.action.VIEW"
android:targetPackage="com.example.test"
android:targetClass="com.example.test.TestIntent/>
</shortcut>
Every time the following happens when I build my project:
AAPT: error: attribute android:shortcutLongLabel not found. AAPT:
error: attribute android:shortcutShortLabel not found. AAPT: error:
attribute android:shortcutID not found.

String resource not accessable in manifest during building process

To avoid my API keys from getting committed on source control (git) I have made an XML resource file called api_keys.xml under the values directory. This file is listed under .gitignore.
I access these string resources the usual way by using #string/.. or .getString(R.string...). This approach works everywhere but in the manifest.xml file.
I have fabric set-up and in the manifest file this is how I try to pass the key -
<meta-data
android:name="io.fabric.ApiKey"
android:value="#string/FABRIC_API_KEY" />
But, when I try to build the APK I get the following error -
Error:Execution failed for task ':app:fabricGenerateResourcesDebug'.
Crashlytics Developer Tools error.
This error goes away if I replace #string/FABRIC_API_KEY with the actual key.
Is there a way I can fix this? Or any other approach I can use to prevent my API keys form getting published on the source control.

"fate of the processing instruction" error in google_maps_api.xml [duplicate]

This question already has answers here:
Error: The processing instruction target matching "[xX][mM][lL]" is not allowed
(10 answers)
Closed last month.
I am new to this forum and in general in android development. I wish to help solve a problem that I have when running the app. The app I'm developing now is based on an activity of google maps. I've done all steps as creating credentials in google api developers and copy the key to xml and manifest. When I run the app I get this error:
Error: (2, 10) Error: The fate of the processing instruction that matches" [xX] [mM] [lL] "is not allowed. App: mergeDebugResources FAILED
What I'm trying for now is just to run the app and show me the google maps
This is google_maps_api.xml:
<resources><string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">AIzaSyDtbq2HdPj5VpKCCvhj1vbuUaA1HIAz8Gg</string>
<?xml version="1.0" encoding="utf-8" ?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.google.android.gms.maps.MapFragment"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/></resources>
I also faced the same problem in one of my android projects.
in my case, it is coming from the AndroidManifest.xml. because I added
<?xml version="1.0" encoding="utf-8"?>
in the starting of the file
this line should not be there in the file . and I resolve it by removing the
line.
In your case also you have the line in the AndroidManifest.xml file. So remove it. I think it will solve your problem.

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
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>

android studio Execution failed for task ':app:mergeDebugResources'

I decompiled an app using an online tool (www.decompileandroid.com) then, after I downloaded the zipped source code (assets + java code), I extracted it in a folder and finally I imported the folder in android studio (File>New>Import Project).
Then, without editing any file, I tried to run the project but I got this error:
Error: Found item ###/ITEM-NAME more than one time
Error:Execution failed for task ':app:mergeDebugResources'. > C:\Users\Fabrizio\AndroidStudioProjects\com.hwlogos.ytstars\app\src\main\res\values\public.xml: Error: Found item ###/ITEM.NAME more than one time
I searched the web for hours but I can't find any useful answer...
Please help!
PS: I tried also with other applications but I always get the same error...
UPDATE:
Now I tried to decompile a simple app i created with android studio and when I reimported it in android studio I got the same error.
it seems there are two resources with the same name, one declared as string and the other as id.
Here's a part of my public.xml, which i never wrote when I made my application!!!
<public type="string" name="action_settings" id="0x7f070006" />
<public type="id" name="action_settings" id="0x7f09000a" />
Create a new xml ids.xml in values with all the id values which are to be constant.
<resources>
<item type="id" name="index_row_search" />
</resources>
I think its better if you copy the resource ids to public.xml from the R.java, the first time to avoid errors like entry index is larger than available symbols and also to keep the type of resource to be consistent.
visit here for more help How to add id to public.xml?

Categories

Resources