Setting a string in APL.xml file

Hello,

I am slowly trying to develop an android plugin and need some help about how you insert a variable into a string in the ___APL.xml file.

I am trying to add this permission

<uses-permission android:name="$S(PackageName).permission.C2D_MESSAGE"/> 

where $S(PackageName) is defined at the top as

<setStringFromProperty result="PackageName" ini="Engine" section="/Script/AndroidRuntimeSettings.AndroidRuntimeSettings" property="PackageName" default=""/>

can someone tell me the correct way i would get the variable to be replaced by the package name and not $S(PackageName).

Thanks

Hi gaz99,

Ok, a few things to look at here. Normally you’d use < addPermission /> for this, but it copies all the attributes exactly into a < use-permission /> tag if the name isn’t already in the manifest. Since you want a string replacement this won’t work, but there is another way to do this using element variables to make up the element.

The second issue is your way of getting the package name will work only if an exact package name is entered and doesn’t use the [PROJECT] replacement. We can work around this as well by reading the package attribute from the manifest instead. This needs to be in the < androidManifestUpdates /> section, not < init />.

<androidManifestUpdates>
  <setStringFromAttribute result="PackageName" tag="manifest" name="package" />
  <setElement result="mypermission" xml='<uses-permission android:name="$S(PackageName).permission.C2D_MESSAGE"/>' />
  <addElement tag="manifest" name="mypermission" />
</androidManifestUpdates>

Hi Chris,

I’ve tried your suggestion however when launching to a device i get this message in the output log

 Missing element variable 'manifest' in 'addElement tag="manifest" name="mypermission"' (skipping instruction)

I’ve looked at the message and the ‘manifest’ missing is a bug; it wrote the tag instead of the name in this case. The actual error is it didn’t find ‘mypermission’ as an element variable. This is due to the parse failing for a few reasons. The first issue is the < and > needed to be &lt; and &gt;. The second is with the android:name not having android defined in the element. There is a way around this by using the < addAttribute /> since I deal with the namespace there. I just tried this and it works:

		<setStringFromAttribute result="PackageName" tag="manifest" name="package"/>
		<setElement result="mypermission" xml="&lt;uses-permission/&gt;"/>
		<addAttribute tag="$mypermission" name="android:name" value="$S(PackageName).permission.C2D_MESSAGE"/>
		<addElement tag="manifest" name="mypermission"/>

This creates an empty element then adds the attribute to it, then adds it to the manifest.

Thanks for your help Chris all is working now :slight_smile: