Add the Extension
The simplest way to install and manage your AIR native extensions and libraries is to use the AIR Package Manager (apm
). We highly recommend using apm
, as it will handle downloading all required dependencies and manage your application descriptor (Android manifest additions, iOS info additions etc).
However you can choose to install it manually, as you would have done in the past.
Install
- APM
- Manual
Note: All of the commands below should be run in a terminal / command prompt in the root directory of your application, generally the level above your source directory.
If you don't have an APM project setup, expand the guide below to setup an APM project before installing the extension.
Setup APM
Install APM
If you haven't installed apm
follow the install guide on airsdk.dev.
Setup an APM project
You will need an APM project for your application.
There are many ways to do this and for more options see the APM documentation. Here we will just initialise a new empty project:
apm init
Check your github token
We use github to secure our extensions so you must have created a github personal access token and configured apm
to use it.
To do this create a token using this guide from github and then set it in your apm config using:
apm config set github_token ghp_XXXXXXXXXXXXXXXXXXXXXXXXXXXX
If you don't do this correctly you may find the install will fail.
Install the extension
Install the extension by running:
apm install com.distriqt.AppGroupDefaults
This will download and install the extension, required assets, and all dependencies.
Once complete apm
will have created something like the following file structure:
.
|____ ane
| |____ com.distriqt.AppGroupDefaults.ane # AppGroupDefaults extension
| |____ [dependencies]
|____ apm_packages # cache directory - ignore
|____ project.apm # apm project file
Add the
ane
directory to your IDE. See the tutorials located here on adding an extension to your IDE.You will need to set the application group for iOS and Android in order that the application descriptor can be generated correctly for your application. Call the following to step through the configuration values for this extension:
apm project config set com.distriqt.AppGroupDefaults
We suggest you use the locations directly in your builds rather than copying the files elsewhere. The reason for this is if you ever go to update the extensions using apm
that these updates will be pulled into your build automatically.
The following guide is used to manually install the extension, download dependencies and update the application descriptor. We highly recommend installing extensions using apm
. Using apm
will automate the installation and automatically handle updates and dependencies along with greatly simplifying the application descriptor generation.
First step is always to add the extension to your development environment. Download the extension from the repository and then follow the tutorial located here to add the extension to your development environment.
Dependencies
Many of our extensions use some common libraries, for example, the Android Support libraries.
We have to separate these libraries into separate extensions in order to avoid multiple versions of the libraries being included in your application and causing packaging conflicts. This means that you need to include some additional extensions in your application along with the main extension file.
You will add these extensions as you do with any other extension, and you need to ensure it is packaged with your application.
Core ANE
The Core ANE is required by this ANE. You must include and package this extension in your application.
The Core ANE doesn't provide any functionality in itself but provides support libraries and frameworks used by our extensions. It also includes some centralised code for some common actions that can cause issues if they are implemented in each individual extension.
You can access this extension here: https://github.com/distriqt/ANE-Core.
Application Descriptor
- APM
- Manual
Updating your application descriptor will insert the required extensionID
's and generate the manifest and info additions for your application.
You update your application descriptor by running:
apm generate app-descriptor src/MyApp-app.xml
Change the path (src/MyApp-app.xml
) to point to your application descriptor.
This will modify your application descriptor replacing the manifest additions and info additions with the ones generated from apm
.
You should backup your application descriptor before running this command to ensure you don't lose any information.
If you need to insert custom data into these sections see the guides for Android and iOS
apm
does not support the legacy file provider method without some additional configuration. If you need to use this legacy method please contact our support and we will guide you through the usage.
Extension IDs
The following should be added to your extensions
node in your application descriptor to identify all the required ANEs in your application:
<extensions>
<extensionID>com.distriqt.AppGroupDefaults</extensionID>
<extensionID>com.distriqt.Core</extensionID>
</extensions>
iOS
Open your application descriptor (the xml file with your application configuration).
Update the iPhone node to be as below:
<iPhone>
<InfoAdditions><![CDATA[
<key>UIDeviceFamily</key>
<array>
<string>1</string>
</array>
<key>MinimumOSVersion</key>
<string>11.0</string>
]]></InfoAdditions>
<requestedDisplayResolution>high</requestedDisplayResolution>
<Entitlements>
<![CDATA[
<key>com.apple.security.application-groups</key>
<array>
<string>group.application.group.identifier</string>
</array>
]]>
</Entitlements>
</iPhone>
- Update the
group.application.group.identifier
with your App Group identifier you created during the iOS setup.
Android
There are two methods available on Android to share settings between applications.
- Provider Method - uses a content provider and broadcast receiver to share variables
- File Method - uses an encrypted file to share variables. Deprecated
Provider Method
The provider method requires that you add several additions to the manifest. This includes a content provider and a broadcast receiver, along with some permissions and settings.
This method requires that you sign all of the applications with the same certificate. This is required so that the settings are secured between your applications.
<!-- For the content provider and broadcast receiver method -->
<queries>
<intent>
<action android:name="[APPGROUP]" />
</intent>
</queries>
<application>
<meta-data android:name="app_group" android:value="[APPGROUP]" />
<meta-data android:name="app_authority" android:value="group.[APPID].provider" />
<meta-data android:name="app_authority_matcher" android:value="group\\.(?:[a-z,1-9]{1,}\\.)*provider" />
<provider
android:name="com.distriqt.extension.appgroupdefaults.provider.SharedProvider"
android:authorities="group.[APPID].provider"
android:exported="true" >
</provider>
<receiver
android:name="com.distriqt.extension.appgroupdefaults.provider.SharedContentChangedReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="[APPGROUP]"/>
</intent-filter>
</receiver>
</application>
You should replace [APPGROUP]
with your application group.
This must be done in the meta-data tag and in the receiver.
For example: group.com.distriqt.test
<meta-data android:name="app_group" android:value="group.com.distriqt.test" />
You also need to define an application authority, this must be different for
each of your applications but must be matchable using the matcher. We suggest using
the example above replacing [APPID]
with your application id, for example an app_authority
may be, group.com.distriqt.test.app1.provider
as below:
<meta-data android:name="app_authority" android:value="group.com.distriqt.test.app1.provider" />
You must place the application authority both in the meta-data tag and in the provider.
Queries
Since Android API v30, Google has limited the ability to discover other applications via use of the <queries>
tag in your manifest. You must specify the applications you wish to access in this area otherwise the application won't be able to discover other applications.
To do so you must add the following:
<queries>
<intent>
<action android:name="[APPGROUP]" />
</intent>
</queries>
Alternatively you can add the QUERY_ALL_PACKAGES
permission, however this is discouraged.
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
File Method
The File Method has been deprecated as it is no longer supported on the latest releases of Android. Android has limited file access between applications making this approach impossible. We suggest you use the content provider method and this documentation is left here only as reference for legacy users
The default is the provider method however if you wish to use the shared file method you
can specify the type in the setup
call:
AppGroupDefaults.service.setup(
"12345678",
"group.com.distriqt.test",
AppGroupDefaults.TYPE_FILE
);
AppGroupDefaults.Instance.Setup(
"12345678", // salt
"group.com.distriqt.test", // app group identifier
AppGroupDefaults.TYPE_FILE // Android type
);
This method writes to a public file with the content encrypted.
This requires read / write permissions to the external storage:
<android>
<manifestAdditions><![CDATA[
<manifest android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
]]></manifestAdditions>
</android>
With recent versions of Android you will need to request runtime permissions to access the storage.
With AIR you can use the Permissions ANE to request the permissions at runtime.
AIRPermissions.service.setPermissions( [
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.WRITE_EXTERNAL_STORAGE"
]);
if (!Permissions.service.hasAuthorisation())
Permissions.service.requestAuthorisation();Unity you can use the
UnityEngine.Android.Permission
helper class to request permissions.Unityif (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite)
|| !Permission.HasUserAuthorizedPermission(Permission.ExternalStorageRead))
{
Permission.RequestUserPermission(Permission.ExternalStorageWrite);
Permission.RequestUserPermission(Permission.ExternalStorageRead);
}
MultiDex Applications
This is enabled by default with the latest AIR builds (33.1.1.x and higher). You should no longer add the android.multidex
extension.
This information is for legacy developers only!
If you have a large application and are supporting Android 4.x then you will need to ensure you enable your application to correctly support MultiDex to allow the application to be broken up into smaller dex packages.
This is enabled by default with releases of AIR v25+, except in the Android 4.x case where you need to change the manifest additions for the application tag to match the following and use the MultiDexApplication
.
This will require the addition of the androidx.multidex
extension which contains the androidx.multidex.MultiDexApplication
implementation.
<manifest android:installLocation="auto">
<!-- PERMISSIONS -->
<application android:name="androidx.multidex.MultiDexApplication">
<!-- ACTIVITIES / RECEIVERS / SERVICES -->
</application>
</manifest>
Checking for Support
You can use the isSupported
flag to determine if this extension is supported on the current platform and device.
This allows you to react to whether the functionality is available on the device and provide an alternative solution if not.
if (AppGroupDefaults.isSupported)
{
// Functionality here
}