Explore AirWatch SDK for Android using Android Studio
This section will give an overview of the Android SDK for Android and walkthrough the process of building the sample project provided in Android Studio.
1. Whitelisting the Signing Key in AirWatch
The AirWatch SDK for Android offers feature enhancements for apps deployed as Internal apps as well as Public Apps deployed via Play Store. However, for the SDK function calls to work, you must ensure your application signing key is whitelisted with the AirWatch environment. Depending upon the mode of app deployment, the process changes slightly.
1.1. Internal Apps
For applications which are uploaded locally for internal distribution (either during production or testing), the following steps are taken to establish trust:
- Sign the APK file with Android Studio Keystore. If you use the Debug Keystore from Android Studio, you can whitelist the app for debugging from the local IDE. However, if you use Release Keystore, the app is not eligible for debugging.
- Upload the signed APK file to AirWatch Admin Console.
- The AirWatch Admin Console extracts the application's public signing key.
- The AirWatch Admin Console whitelists the application's public signing key with the AirWatch Agent.
- When the application is launched, it calls AirWatch SDK for initial configuration.
- The AirWatch Agent validates the signing key by comparing it to the one uploaded in the AirWatch Admin Console.
1.2. Public Apps
The automatic key whitelisting feature is currently only supported with Internal Apps. However, the trust for the Public Apps using AirWatch SDK can be established by manually whitelisting the public signing key. If the app developer shares the signing key then AirWatch can follow steps similar to the Internal apps flow for whitelisting.
2. Integrate AirWatch SDK for Android into the Sample App
In this section, we will setup the Android SDK Sample app to use AirWatch Android SDK. We will use Android Studio as Integrated Development Environment (IDE) to include the SDK libraries into the sample app project. After that, we will build, sign, and export the APK to upload into the AirWatch admin console.
2.1. Launch Android Studio
From the Task bar, click on the Android Studio icon to launch it.
NOTE - Android Studio may take several seconds to launch, please be patient while it opens.
2.2. Open the Sample App Project from Recent Projects
Click Open an existing Android Studio Project.
2.3. Open the Sample App Project
- From the windows, select C:\Users\holuser\Documents\HOL\Android SDK.
- Select Android SDK 16.02.
- Select sample code.
- Select airwath-sdk-test-app.
NOTE - Android Studio can auto-detect the Android Project files and will put Android Studio icon before for easier identification and access.
- Click OK.
2.4. Open the libs folder of the project and validate the required SDK libs
- Select the View Project from the drop down if it is not already selected.
- Expand the root airwatch-sdk-test-app.
- Right click on the folder libs.
- Select the option Show in Explorer.
2.5. Open the libs folder in the File Explorer
Double-click the libs folder.
2.6. Validate the Necessary Library Files Exist
- Validate that you have AirWatchSDK-16.02 Jar file, AWFramework 16.02.aar and gson-2.4 jar file included in the libs folder. You will see a lot of other libraries but these three are the primary libraries that are used for this lab.
NOTE - If you do not see these libraries in the libs folder, then you can add those from the SDK package. These files are located in \Documents\HOL\Android SDK\Android SDK v16.02\libs\AWFramework and ClientSDK folder. The following step demonstrates how to add the gson library to the project libs folder.
2.7. Add the gson library to the project libs folder
For any SDK app, the developer needs to add the related libraries to the libs folder of the project, otherwise the project might not build correctly. To limit the scope of this lab, most of the files are already added in the correct folder for you. In this section, we are going to add the gson library as an example.
For troubleshooting any build errors, we should always check if the required libraries are added or not as the first troubleshooting step.
NOTE - Perform this step ONLY if you don't see gson library in your project's libs folder. Follow similar steps for AirWatchSDK jar file and/or AWFramework aar file in case they are missing in the libs folder.
- From the taskbar at the bottom of the Desktop, click on the icon to launch File Explorer.
- In the new Window, navigate to Documents\HOL\Android SDK\Android SDK v16.02\libs\ClientSDK.
- Right Click on gson-2.4 executable JAR file.
- Click on Copy.
- In another Window for libs folder (if you closed it, then reopen from Android Studio as described in the step above), Right Click on click on Paste to add the gson library. Close or minimize the Explorer window.
2.8. Build the Sample App Project
To limit the scope of this lab, all the coding has already been implemented in the project. We have also verified that the project has the required libraries and added the gson library. Now it is ready to be built.
Back to the Android Studio window,
- Select the root airwatch-sdk-test-app.
- From the toolbar, select Build.
- Select the option Build > Rebuild Project. This will start the build.
- Select the perspective Gradle Console From the bottom right.
- Scroll to the bottom of the Gradle Console.
- The build time may vary depending on the VM configuration but after some time (approximately 2 minutes), you should see the status as BUILD SUCCESSFUL.
2.9. Generate Signed APK
- Select the root airwatch-sdk-test-app (if not done already).
- From the toolbar, select Build.
- Select the option Generate Signed APK...
2.10. Enter Master Password for keychain
For this lab, keychain and keychain alias is already setup for you and is encrypted with a Master Password. When prompted,
- Enter the password as "VMware1!".
- Click on OK.
- Keep all the defaults and click on Next.
NOTE - The keychain is located at C:/Users/holuser/Documents/HOL/Android SDK/awks.jks and alias is auto-populated when you make the selection.
2.11. Select APK Destination Folder
For easier access, we are going to save the application on the Desktop.
- Click on the Browse icon.
- Click on the Desktop icon to select the destination folder as Desktop.
- Click on OK to continue.
2.12. Select Build Type
- Select the Build Type as release.
NOTE - If we select the build type as debug, it will allow us to run the app in the debug mode by connecting the device to the Computer and troubleshoot via Android Studio debugger. However, to limit the scope of this lab, we are going to sign the app with the release key.
- Check the V1 (Jar Signature) checkbox.
- Click Finish to start the process. Depending on machine resources, it will take anywhere from 2 to 3 minutes to complete the APK generation process.
While we are waiting to generated the signed APK, let us go ahead and create the SDK profile which we will assign to our sample app while uploading it to the AirWatch Console.