Customizing the Android APK File
You will want to make changes to the Android Application Package (APK) that is in WSO2 IoT Server to suit your business or Organization requirements. For example, you will want to white label the WSO2 Android agent. In such situations, you need to do the required changes and create a new APK file.
Prerequisites
Download and install Android Studio.
For more information, see installing Android Studio.
Replace the
android.jar
file that is in the<ANDROID_STUDIO>/<SDK location>/platforms/android-<CURRENT_API_LEVEL>
directory with theandroid.jar
file. You can get the newjar
file using one of the following options:Download the Android Open Source Project (AOSP) and build the source code to get the
jar
file for the required SDK level.Use a pre-built jar file from a third party developer. You can find it here.
Make sure to use the jar file that matches the
compileSdkVersion
of the WSO2 Android agent. Currently, thecompileSdkVersion
is 25.
Why is this needed?
The WSO2 Android agent requires access to hidden APIs (APIs that are available at runtime). Therefore, you need to replace the
anrdoid.jar
file as mentioned in this step.- WSO2 IoT Server supports API levels from 17 to 25. Therefore, install the Android API levels from 17 to 25 on Android Studio.
- Open Android Studio.
- Click SDK Manager.
- Click the SDK Platform tab and select the 17 and 25 API levels.
Example: - Click Apply.
Creating a new APK
Clone the cdmf-agent-android GIT repository. This will be referred to as
<ANDROID_AGENT_SOURCE_CODE>
.Step 1 - git clone https://github.com/wso2/cdmf-agent-android.git Step 2 - git checkout tags/<server_compatible_tag_name>
Check the WSO2 IoT Server and Agent Compatibility and find out what tag of this repo you need to checkout.
Example: WSO2 IoT Server 3.0.0 is compatible with the WSO2 Android agent 2.0.1. Therefore, the release tag will be v2.0.1.git checkout tags/v2.0.1
- Open the client folder that is in the
<ANDROID_AGENT_SOURCE_CODE>
via Android Studio. - Do the necessary changes you wish to make.
Example: You can perform the following modifications to theclient/client/build.gradle
file:- Update the value
http
ofthebuildConfigField “String”, SERVER_PROTOCOL”, “\http://\””
attributetohttps
if you wish to change the protocol to https. - Update the value
null
ofthebuildConfigField “String”, DEFAULT_HOST”, “null”
attribute to your hostname, e.g.,https://10.10.10.192:8243
for https andhttp://10.10.10.192:8280
forhttp.
- Update the value
The Android agent can't be built via the usual android developer SDK, as it requires access to developer restricted APIs. Therefore, you need to replace the existing
android.jar
file that is in the<SDK_LOCATION>/platforms/android-<COMPILE_SDK_VERSION>
directory with the explicitly builtandroid.jar
file that has access to the restricted APIs.
You can get the newjar
file using one of the following methods:Download the Android Open Source Project (AOSP) and build the source code to get the
jar
file for the required SDK level.- Use a pre-built jar file from a third party developer. You can find it here.
Build the project to create a new APK file that has all the changes you made.
- Rename the created
.apk
filetoandroid-agent.apk
. - Copy the renamed file and replace it instead of the existing
android-agent.apk
file that is in the<
directory.IoT_HOME>/core/repository/deployment/server/jaggeryapps/android-web-agent/app/pages/mdm.page.enrollments.android.download-agent/public/asset