MATTER chip-tool android APK is a very useful tool for commission, control the MATTER network by smart phone. Vendor can add various features into the APK.
It supports build by Android Studio and command line. The official build steps can be found here: https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/android_building.md
But the official guide does not cover how to build in a non-GUI linux distribution (without Android Studio installed). This article describes how to build under Ubuntu server.
Install SDK command line from: https://developer.android.com/studio, And follow the steps: https://developer.android.com/tools/sdkmanager to install.
Install the Android-26 SDK and 23 NDK:
$./sdkmanager "platforms;android-26" "ndk;23.2.8568313"
Export env
$export ANDROID_HOME=<SDK path>
$export ANDROID_NDK_HOME=<SDK path>/ndk/23.2.8568313/
$curl -s https://get.sdkman.io | bash
$sdk install kotlin 1.8.0
$whereis kotlin
$export PATH=$PATH:<patch of bin of kotlin>
$ cat ~/.gradle/gradle.properties
# Set the socket timeout to 5 minutes (good for proxies)
org.gradle.internal.http.socketTimeout=300000
# the number of retries (initial included) (default 3)
org.gradle.internal.repository.max.retries=10
# the initial time before retrying, in milliseconds (default 125)
org.gradle.internal.repository.initial.backoff=500
systemProp.http.proxyHost=apac.nics.nxp.com
systemProp.http.proxyPort=8080
systemProp.http.nonProxyHosts=localhost|*.nxp.com
systemProp.https.proxyHost=apac.nics.nxp.com
systemProp.https.proxyPort=8080
systemProp.https.nonProxyHosts=localhost|*.nxp.com
Configure proxy for download packages during build
export FTP_PROXY="http://apac.nics.nxp.com:8080"
export HTTPS_PROXY="http://apac.nics.nxp.com:8080"
export HTTP_PROXY="http://apac.nics.nxp.com:8080"
export NO_PROXY="localhost,*.nxp.com"
export ftp_proxy="http://apac.nics.nxp.com:8080"
export http_proxy="http://apac.nics.nxp.com:8080"
export https_proxy="http://apac.nics.nxp.com:8080"
export no_proxy="localhost,*.nxp.com"
This step can be skipped if using OpenJDK16.
Otherwise if you're using OpenJDK 17 (Java 61), you have to upgrade the gradle from 7.1.1 to 7.3, and add java.io open to ALL-UNNAMED:
diff --git a/examples/android/CHIPTool/gradle.properties b/examples/android/CHIPTool/gradle.properties
index 71f72db8c8..5bce4b4528 100644
--- a/examples/android/CHIPTool/gradle.properties
+++ b/examples/android/CHIPTool/gradle.properties
@@ -6,7 +6,8 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
-org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+#org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+org.gradle.jvmargs=-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 --add-opens=java.base/java.io=ALL-UNNAMED
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
diff --git a/examples/android/CHIPTool/gradle/wrapper/gradle-wrapper.properties b/examples/android/CHIPTool/gradle/wrapper/gradle-wrapper.properties
index 05679dc3c1..e750102e09 100644
--- a/examples/android/CHIPTool/gradle/wrapper/gradle-wrapper.properties
+++ b/examples/android/CHIPTool/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Clone all the modules from github:
$git clone --single-branch --recurse-submodules https://github.com/project-chip/connectedhomeip.git
Enviroment setup:
$source scripts/bootstrap.sh
Build:
./scripts/build/build_examples.py --target android-arm64-chip-tool build
Install built apk into phone:
$adb install out/android-arm64-chip-tool/outputs/apk/debug/app-debug.apk