diff --git a/.github/.wordlist.txt b/.github/.wordlist.txt
index 97b715f3120a81..bff885e01281ac 100644
--- a/.github/.wordlist.txt
+++ b/.github/.wordlist.txt
@@ -430,6 +430,7 @@ ini
init
inlined
instantiation
+installDebug
integrations
IntelliSense
InteractionModelVersion
@@ -519,6 +520,7 @@ ManualPairingCode
ManualTest
ManufacturingDate
masterkey
+matterBuildSrcDir
matterc
matterd
MatterLock
diff --git a/docs/guides/android_chiptool_building.md b/docs/guides/android_chiptool_building.md
index e1be9a2148a3d9..c3908644371bd9 100644
--- a/docs/guides/android_chiptool_building.md
+++ b/docs/guides/android_chiptool_building.md
@@ -16,7 +16,9 @@ CHIPTool offers the following features:
- [Source files](#source)
- [Requirements for building](#requirements)
- [ABIs and TARGET_CPU](#abi)
-- [Building Android CHIPTool](#building)
+- [Preparing for build](#preparing)
+- [Building Android CHIPTool from scripts](#building-scripts)
+- [Building Android CHIPTool from Android Studio](#building-studio)
@@ -54,11 +56,11 @@ architecture:
-
+
-## Building Android CHIPTool
+## Preparing for build
-Complete the following steps to build CHIPTool:
+Complete the following steps to prepare the CHIP build:
1. Check out the CHIP repository.
@@ -68,18 +70,57 @@ Complete the following steps to build CHIPTool:
source scripts/bootstrap.sh
```
-3. In the command line, run the following command from the top CHIP directory:
+3. Choose how you want to build the Android CHIPTool. There are two ways: from
+ script, or from source within Android Studio.
+
+
+
+## Building Android CHIPTool from scripts
+
+This is the simplest option. In the command line, run the following command from
+the top CHIP directory:
+
+```shell
+./scripts/build/build_examples.py --platform android --board arm64 build
+```
+
+See the table above for other values of `TARGET_CPU`.
+
+The debug Android package `app-debug.apk` will be generated at
+`out/android-$TARGET_CPU-chip_tool/outputs/apk/debug/`, and can be installed
+with
+
+```shell
+adb install out/android-$TARGET_CPU-chip_tool/outputs/apk/debug/app-debug.apk
+```
+
+You can use Android Studio to edit the Android CHIPTool app itself, but you will
+not be able to edit CHIP Android code from `src/controller/java`, or other CHIP
+C++ code within Android Studio.
+
+
+
+## Building Android CHIPTool from Android Studio
+
+This option allows Android Studio to build the core CHIP code from source, which
+allows us to directly edit core CHIP code in-IDE.
+
+1. In the command line, run the following command from the top CHIP directory:
```shell
- TARGET_CPU=arm64 ./scripts/examples/android_app.sh
+ TARGET_CPU=arm64 ./scripts/examples/android_app_ide.sh
```
See the table above for other values of `TARGET_CPU`.
-4. Open the project in Android Studio and run **Sync Project with Gradle
+2. Modify the `matterBuildSrcDir` variable in
+ [src/android/CHIPTool/build.gradle](https://github.com/project-chip/connectedhomeip/blob/master/src/android/CHIPTool/build.gradle)
+ to point to the appropriate output directory (e.g. `out/android_arm64`).
+
+3. Open the project in Android Studio and run **Sync Project with Gradle
Files**.
-5. Use one of the following options to build an Android package:
+4. Use one of the following options to build an Android package:
- Click **Make Project** in Android Studio.
- Run the following command in the command line:
@@ -90,4 +131,14 @@ Complete the following steps to build CHIPTool:
```
The debug Android package `app-debug.apk` will be generated at
-`src/android/CHIPTool/app/build/outputs/apk/debug/`.
+`src/android/CHIPTool/app/build/outputs/apk/debug/`, and can be installed with
+
+```shell
+adb install src/android/CHIPTool/app/build/outputs/apk/debug/app-debug.apk
+```
+
+or
+
+```shell
+(cd src/android/CHIPTool && ./gradlew installDebug)
+```
diff --git a/scripts/build/build/factory.py b/scripts/build/build/factory.py
index 9e7f65da5d56b1..456336535bcd85 100644
--- a/scripts/build/build/factory.py
+++ b/scripts/build/build/factory.py
@@ -145,6 +145,7 @@ def Create(self, runner, __board_key: Board, __app_key: Application,
_MATCHERS[Platform.ANDROID].AcceptBoard(Board.ARM, board=AndroidBoard.ARM)
_MATCHERS[Platform.ANDROID].AcceptBoard(Board.ARM64, board=AndroidBoard.ARM64)
_MATCHERS[Platform.ANDROID].AcceptBoard(Board.X64, board=AndroidBoard.X64)
+_MATCHERS[Platform.ANDROID].AcceptBoard(Board.X86, board=AndroidBoard.X86)
_MATCHERS[Platform.ANDROID].AcceptApplication(Application.CHIP_TOOL)
_MATCHERS[Platform.INFINEON].AcceptApplication(
diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py
index 272f4efb477268..7338cacfd132e9 100644
--- a/scripts/build/build/targets.py
+++ b/scripts/build/build/targets.py
@@ -66,6 +66,7 @@ class Board(IntEnum):
ARM = auto()
ARM64 = auto()
X64 = auto()
+ X86 = auto()
# Infineon board
P6BOARD = auto()
diff --git a/scripts/build/builders/android.py b/scripts/build/builders/android.py
index 79612ffd4d5417..902970b45b7851 100644
--- a/scripts/build/builders/android.py
+++ b/scripts/build/builders/android.py
@@ -24,6 +24,7 @@ class AndroidBoard(Enum):
ARM = auto()
ARM64 = auto()
X64 = auto()
+ X86 = auto()
def TargetCpuName(self):
if self == AndroidBoard.ARM:
@@ -32,6 +33,8 @@ def TargetCpuName(self):
return 'arm64'
elif self == AndroidBoard.X64:
return 'x64'
+ elif self == AndroidBoard.X86:
+ return 'x86'
else:
raise Exception('Unknown board type: %r' % self)
@@ -42,6 +45,8 @@ def AbiName(self):
return 'arm64-v8a'
elif self == AndroidBoard.X64:
return 'x86_64'
+ elif self == AndroidBoard.X86:
+ return 'x86'
else:
raise Exception('Unknown board type: %r' % self)
@@ -149,7 +154,7 @@ def _build(self):
'%s/src/android/CHIPTool/gradlew' % self.root, '-p',
'%s/src/android/CHIPTool' % self.root,
'-PchipSdkJarDir=%s' % os.path.join(self.output_dir, 'lib'),
- '-PbuildDir=%s' % self.output_dir, 'build'
+ '-PbuildDir=%s' % self.output_dir, 'assembleDebug'
],
title='Building APP ' + self.identifier)
@@ -162,9 +167,6 @@ def build_outputs(self):
'ChipTool-debug.apk':
os.path.join(self.output_dir, 'outputs', 'apk', 'debug',
'app-debug.apk'),
- 'ChipTool-release-unsigned.apk':
- os.path.join(self.output_dir, 'outputs', 'apk', 'release',
- 'app-release-unsigned.apk'),
'jni/%s/libSetupPayloadParser.so' % self.board.AbiName():
os.path.join(self.output_dir, 'lib', 'jni',
diff --git a/scripts/build/expected_all_platform_commands.txt b/scripts/build/expected_all_platform_commands.txt
index a4c0c61879d899..81f99f21b5832c 100644
--- a/scripts/build/expected_all_platform_commands.txt
+++ b/scripts/build/expected_all_platform_commands.txt
@@ -122,6 +122,12 @@ gn gen --check --fail-on-unused-args {out}/android-x64-chip_tool '--args=target_
# Accepting NDK licenses
bash -c 'yes | TEST_ANDROID_HOME/tools/bin/sdkmanager --licenses >/dev/null'
+# Generating android-x86-chip_tool
+gn gen --check --fail-on-unused-args {out}/android-x86-chip_tool '--args=target_os="android" target_cpu="x86" android_ndk_root="TEST_ANDROID_NDK_HOME" android_sdk_root="TEST_ANDROID_HOME" chip_use_clusters_for_ip_commissioning="true"'
+
+# Accepting NDK licenses
+bash -c 'yes | TEST_ANDROID_HOME/tools/bin/sdkmanager --licenses >/dev/null'
+
# Generating infineon-p6board-lock
gn gen --check --fail-on-unused-args --root={root}/examples/lock-app/p6 '--args=p6_board="CY8CKIT-062S2-43012"' {out}/infineon-p6board-lock
@@ -220,7 +226,7 @@ cp {out}/android-arm-chip_tool/lib/jni/armeabi-v7a/libCHIPController.so {root}/s
cp {out}/android-arm-chip_tool/lib/jni/armeabi-v7a/libc++_shared.so {root}/src/android/CHIPTool/app/libs/jniLibs/armeabi-v7a/libc++_shared.so
# Building APP android-arm-chip_tool
-{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PchipSdkJarDir={out}/android-arm-chip_tool/lib -PbuildDir={out}/android-arm-chip_tool build
+{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PchipSdkJarDir={out}/android-arm-chip_tool/lib -PbuildDir={out}/android-arm-chip_tool assembleDebug
# Building JNI android-arm64-chip_tool
ninja -C {out}/android-arm64-chip_tool
@@ -235,7 +241,7 @@ cp {out}/android-arm64-chip_tool/lib/jni/arm64-v8a/libCHIPController.so {root}/s
cp {out}/android-arm64-chip_tool/lib/jni/arm64-v8a/libc++_shared.so {root}/src/android/CHIPTool/app/libs/jniLibs/arm64-v8a/libc++_shared.so
# Building APP android-arm64-chip_tool
-{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PchipSdkJarDir={out}/android-arm64-chip_tool/lib -PbuildDir={out}/android-arm64-chip_tool build
+{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PchipSdkJarDir={out}/android-arm64-chip_tool/lib -PbuildDir={out}/android-arm64-chip_tool assembleDebug
# Building JNI android-x64-chip_tool
ninja -C {out}/android-x64-chip_tool
@@ -250,7 +256,22 @@ cp {out}/android-x64-chip_tool/lib/jni/x86_64/libCHIPController.so {root}/src/an
cp {out}/android-x64-chip_tool/lib/jni/x86_64/libc++_shared.so {root}/src/android/CHIPTool/app/libs/jniLibs/x86_64/libc++_shared.so
# Building APP android-x64-chip_tool
-{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PchipSdkJarDir={out}/android-x64-chip_tool/lib -PbuildDir={out}/android-x64-chip_tool build
+{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PchipSdkJarDir={out}/android-x64-chip_tool/lib -PbuildDir={out}/android-x64-chip_tool assembleDebug
+
+# Building JNI android-x86-chip_tool
+ninja -C {out}/android-x86-chip_tool
+
+# Prepare Native libs android-x86-chip_tool
+mkdir -p {root}/src/android/CHIPTool/app/libs/jniLibs/x86
+
+cp {out}/android-x86-chip_tool/lib/jni/x86/libSetupPayloadParser.so {root}/src/android/CHIPTool/app/libs/jniLibs/x86/libSetupPayloadParser.so
+
+cp {out}/android-x86-chip_tool/lib/jni/x86/libCHIPController.so {root}/src/android/CHIPTool/app/libs/jniLibs/x86/libCHIPController.so
+
+cp {out}/android-x86-chip_tool/lib/jni/x86/libc++_shared.so {root}/src/android/CHIPTool/app/libs/jniLibs/x86/libc++_shared.so
+
+# Building APP android-x86-chip_tool
+{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PchipSdkJarDir={out}/android-x86-chip_tool/lib -PbuildDir={out}/android-x86-chip_tool assembleDebug
# Building infineon-p6board-lock
ninja -C {out}/infineon-p6board-lock
diff --git a/scripts/examples/android_app.sh b/scripts/examples/android_app.sh
deleted file mode 100755
index 87939d067fd672..00000000000000
--- a/scripts/examples/android_app.sh
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/usr/bin/env bash
-
-#
-# Copyright (c) 2020 Project CHIP Authors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-set -e
-set -x
-env
-
-if [ -z "$ANDROID_HOME" ]; then
- echo "ANDROID_HOME not set!"
- exit 1
-fi
-
-if [ -z "$ANDROID_NDK_HOME" ]; then
- echo "ANDROID_NDK_HOME not set!"
- exit 1
-fi
-
-if [ -z "$TARGET_CPU" ]; then
- echo "TARGET_CPU not set! Candidates: arm, arm64, x86 and x64."
- exit 1
-fi
-
-source scripts/activate.sh
-if [ -z "$USE_IDE" ] || [ "$USE_IDE" -eq '0' ]; then
- # Build shared CHIP libs
- echo "build scripts"
- gn gen --check --fail-on-unused-args out/"android_$TARGET_CPU" --args="target_os=\"android\" target_cpu=\"$TARGET_CPU\" android_ndk_root=\"$ANDROID_NDK_HOME\" android_sdk_root=\"$ANDROID_HOME\" chip_use_clusters_for_ip_commissioning=\"true\""
- ninja -C out/"android_$TARGET_CPU" src/setup_payload/java src/controller/java default
-
- rsync -a out/"android_$TARGET_CPU"/lib/*.jar src/android/CHIPTool/app/libs
- rsync -a out/"android_$TARGET_CPU"/lib/jni/* src/android/CHIPTool/app/libs/jniLibs
-else
- # Build Cmake for Android Stduio
- echo "build ide"
- gn gen --check --fail-on-unused-args out/"android_$TARGET_CPU" --args="target_os=\"android\" target_cpu=\"$TARGET_CPU\" android_ndk_root=\"$ANDROID_NDK_HOME\" android_sdk_root=\"$ANDROID_HOME\" chip_use_clusters_for_ip_commissioning=\"true\"" --ide=json --json-ide-script=//scripts/examples/gn_to_cmakelists.py
-fi
diff --git a/scripts/examples/android_app_ide.sh b/scripts/examples/android_app_ide.sh
new file mode 100755
index 00000000000000..4018a7ef51bf92
--- /dev/null
+++ b/scripts/examples/android_app_ide.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+#
+# Copyright (c) 2020 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+set -e
+set -x
+env
+
+if [ -z "$ANDROID_HOME" ]; then
+ echo "ANDROID_HOME not set!"
+ exit 1
+fi
+
+if [ -z "$ANDROID_NDK_HOME" ]; then
+ echo "ANDROID_NDK_HOME not set!"
+ exit 1
+fi
+
+if [ -z "$TARGET_CPU" ]; then
+ echo "TARGET_CPU not set! Candidates: arm, arm64, x86 and x64."
+ exit 1
+fi
+
+source scripts/activate.sh
+# Build CMake for Android Studio
+echo "build ide"
+gn gen --check --fail-on-unused-args out/"android_$TARGET_CPU" --args="target_os=\"android\" target_cpu=\"$TARGET_CPU\" android_ndk_root=\"$ANDROID_NDK_HOME\" android_sdk_root=\"$ANDROID_HOME\" chip_use_clusters_for_ip_commissioning=\"true\"" --ide=json --json-ide-script=//scripts/examples/gn_to_cmakelists.py