Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

Integrating the Good Dynamics SDK for Android in Your Android Project

by BlackBerry Development Advisor on ‎04-15-2016 10:29 AM (871 Views)

Purpose

 

This document will walk you through adding the Good Dynamics SDK for Android to your project in Android Studio.  If you do not yet have the Good Dynamics SDK for Android installed, refer to Downloading and Installing the Good Dynamics SDK for Android.

 

Requirements

 

  • Android Studio
  • Good Dynamics SDK for Android

 

Procedure

 

It is recommended that you build your application after each section in this process.  This will allow you to confirm each step and will make debugging problems easier.

 

Create a Settings File

 

The settings.json file is created within your project.  It is used by the Good Dynamics (GD) Runtime to read configuration information about your application, such as the GD library mode, GD entitlement application ID and GD application version.

 

  1. If you already have an assets folder in your project, skip to step #5. If not, proceed to step 2.
  2. In Android Studio right click the top-level Application package and then select the following in the context menu that appears: New, Folder, Assets Folder. This opens a dialog whose title text mention activity customization, but is actually a confirmation for where to create “a source root for assets”.
  3. Leave the default options selected and click Finish. This creates the folder and returns you to the project window.
  4. Expand the package in which you just created the folder. The assets folder should appear under the package, as shown in the following screen shot.project.png
  5. Right click on the assets folder in the project window and select New, File in the context menu that appears. This opens the New File dialog.
  6. Enter settings.json as the file name and click OK. This creates an empty settings.json file and opens it in the Android Studio editor.
  7. Use one of the following examples to build your own settings.json file. Modify the examples to include your own GDApplicationID and GDApplicationVersion.

 

GDLibraryMode – Can be set to either GDEnterpriseSimulation or GDEnterprise.  Use GDEnterpriseSimulation if you do not have a Good Control server or are using an Android emulator.  Use GDEnterprise to test with a Good Control server and for production deployments.  A connection to the GD Network Operation Center is required for both options.

 

GDApplicationID – A unique identifier for your application.  Conventionally, this value is similar to the application’s package name.  No capital letters or spaces are allowed.  This value is also registered in the Good Control server.

 

GDApplicationVersion – This is a compatibility version for your GD enabled application.  It does not need to match your application version.  This should only be updated when compatibility related to Good integration changes, such as when you add or remove Good services in your application.  Needlessly updating this to match your application version will result in additional work for both you the developer and all administrators who have deployed your application.

 

Sample settings.json that uses Simulation Mode

 

 

{
  "GDLibraryMode": " GDEnterpriseSimulation"",
  "GDApplicationID": "com.blackberry.msohm.application",
  "GDApplicationVersion": "1.0.0.0"
}

 

Sample settings.json that uses Enterprise Mode

 

{
  "GDLibraryMode": "GDEnterprise",
  "GDApplicationID": "com.blackberry.msohm.application",
  "GDApplicationVersion": "1.0.0.0"
}

It is best practice to add the GD Application Version to the AndroidManifest.xml file as well as to the settings.json file. Add it in the <application> item, in a <meta-data> tag with attributes as shown:

 

 

<application
     android:allowBackup="true"
     android:icon="@drawable/ic_launcher"
     android:label="@string/app_name" >

     <meta-data
          android:name="GDApplicationVersion"
          android:value ="1.0.0.0" />

 

Linking the Good Dynamics Runtime Library

 

Start by linking the GD Runtime into the application. The GD Runtime will be added as a module. This requires change in several parts of the project.

 

Prepare

 

A preparation step is necessary before the module can be added.  Open the project in Android Studio and proceed as follows.

 

  1. Within Android Studio select File, Project Structure from the menu. This opens the Project Structure screen.
  2. Select Project in the navigation pane. This opens a page on which you can enter the Android Plugin Version, amongst some other settings.
  3. Set the following values for Good Dynamics SDK build 1256.

Gradle Version:  2.2.1

Android Plugin Repository: mavenCentral

For Android Studio 1.5.0 use: Android Plugin Version: 1.5.0

For Android Studio 2.0.0 use:  Android Plugin Version: 2.0.0

 

The page should appear as in the following screen capture image.project structure.png

  1. Click OK to save.

This completes the preparation for adding the GD Runtime module.

 

 

Add Module

 

Next you need to add the GD Runtime library to the project as a module.  There are a number of ways to add a module to an Android Studio project.

 

The instructions given here utilize the user interface to import the module and are intended to be easy and safe to follow. You can instead edit the project settings file, which will include the module in a different way. Instructions for editing the settings file directly can be found in Alternate Method for Including the Good Dynamics Runtime Library.

 

Open the project in Android Studio and proceed as follows.

 

  1. Select File, New, Import Module in the menu. This opens the New Module screen. There will be a text box for entry of the Source directory.
  2. Enter the directory of the main GD Runtime library for handheld applications in your installation. This will generally be a sub-directory of your Android home directory with the following path: sdk/extras/good/dynamics_sdk/libs/handheld/gd/

 

If you are uncertain, check that the directory you select contains AndroidManifest.xml, ant.properties, and contain bin/, libs/ and src/ sub-directories among others.

 

The Android home directory is by default located in the following directories

Windows:  C:\Users\[username]\AppData\Local\Android

Mac: /Users/[username]/Library/Android/sdk

 

You can enter the path as text, or click on the … button and navigate to it interactively.  When you have entered the source directory, a text box for Module name will appear on the New Module screen.

  1. You can accept the default value or set the module name, to :gdHandheld for example. A more descriptive name than the default might help clarify which module is which later on, in case you also add security to a wearable application in the same project. Click Finish when you have set the module name, or to accept the default. This returns you to the project window.

A copy of the GD Runtime module has now been added to the project. It should appear in the project window, as shown in the following screen shot.

 

project2.png

 

 

Add Dependency

 

Now that the module is part of the project it can be added as a dependency.

 

  1. In Android Studio select File, Project Structure in the menu. This opens the Project Structure screen.
  2. Select the Application module in the navigation pane. This opens a page with a number of tabs for configuration of the module. Select the Dependencies tab.
  3. Add a dependency on the GD Runtime library module. At the bottom or right side of the screen (depending on your Android Studio version), click the + button and then select Module dependency in the context menu that appears. The following screen capture image shows this selection in the user interface.

 add dependency.png

 

This opens the Choose Modules dialog.

 

  1. Select the GD module you imported in the previous instructions. This returns you to the Project Structure screen, with the Dependencies tab of the Application module open. The GD module should be listed as a dependency.
  2. Click OK to save the changes to the module configuration.

The GD Runtime is now linked to the handheld application and you are ready to start making code changes to your application to integrate with the GD Runtime.

 

Update Manifest

 

The launch activity of a GD application must conform to a number of restrictions, which may require changes to an application’s manifest file.

 

  1. Open the AndroidManifes.xml file for your application in Android Studio.
  2. Locate the opening tag of the declaration of the launch activity, which will be the one that has following elements.

 

 

 

<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

 

 

  1. Declare the activity as always retaining its task state, by inserting the following setting inside the opening tag.

 

android:alwaysRetainTaskState="true"

 

 

  1. Remove selection of single-task launch mode, if present, by deleting the following setting from the opening tag.

 

 

android:launchMode="singleTask"

 

 

This completes the steps required to add and configure the Good Dynamics library within your application.

Contributors
Users Online
Currently online: 15 members 2,412 guests
Please welcome our newest community members: