diff --git a/examples/tv-casting-app/android/README.md b/examples/tv-casting-app/android/README.md index 87e7fa109b3e7a..3b3138a0e2c61c 100644 --- a/examples/tv-casting-app/android/README.md +++ b/examples/tv-casting-app/android/README.md @@ -72,6 +72,9 @@ the top Matter directory: ./scripts/build/build_examples.py --target android-arm64-tv-casting-app build ``` +(To build this app with no debugging hooks, use the +`android-arm64-tv-casting-app-no-debug` target) + See the table above for other values of `TARGET_CPU`. The debug Android package `app-debug.apk` will be generated at diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index 95e4d22d315d91..77859c27257b4e 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -18,7 +18,7 @@ from typing import Any, List, Optional from builders.ameba import AmebaApp, AmebaBoard, AmebaBuilder -from builders.android import AndroidApp, AndroidBoard, AndroidBuilder +from builders.android import AndroidApp, AndroidBoard, AndroidBuilder, AndroidProfile from builders.bouffalolab import BouffalolabApp, BouffalolabBoard, BouffalolabBuilder from builders.cc13x2x7_26x2x7 import cc13x2x7_26x2x7App, cc13x2x7_26x2x7Builder from builders.cc32xx import cc32xxApp, cc32xxBuilder @@ -297,6 +297,9 @@ def BuildAndroidTarget(): TargetPart('java-matter-controller', app=AndroidApp.JAVA_MATTER_CONTROLLER), ]) + # Modifiers + target.AppendModifier('no-debug', profile=AndroidProfile.RELEASE) + return target diff --git a/scripts/build/builders/android.py b/scripts/build/builders/android.py index 7a9d5fe77aae3e..f34f02087c03dc 100644 --- a/scripts/build/builders/android.py +++ b/scripts/build/builders/android.py @@ -86,6 +86,7 @@ def AppName(self): def AppGnArgs(self): gn_args = {} + if self == AndroidApp.TV_SERVER: gn_args["chip_config_network_layer_ble"] = False elif self == AndroidApp.TV_CASTING_APP: @@ -107,11 +108,31 @@ def Modules(self): return None +class AndroidProfile(Enum): + RELEASE = auto() + DEBUG = auto() + + @property + def ProfileName(self): + if self == AndroidProfile.RELEASE: + return 'release' + elif self == AndroidProfile.DEBUG: + return 'debug' + else: + raise Exception('Unknown profile type: %r' % self) + + class AndroidBuilder(Builder): - def __init__(self, root, runner, board: AndroidBoard, app: AndroidApp): + def __init__(self, + root, + runner, + board: AndroidBoard, + app: AndroidApp, + profile: AndroidProfile = AndroidProfile.DEBUG): super(AndroidBuilder, self).__init__(root, runner) self.board = board self.app = app + self.profile = profile def validate_build_environment(self): for k in ["ANDROID_NDK_HOME", "ANDROID_HOME"]: @@ -258,6 +279,7 @@ def gradlewBuildSrcAndroid(self): ) def gradlewBuildExampleAndroid(self): + # Example compilation if self.app.Modules(): for module in self.app.Modules(): @@ -311,6 +333,8 @@ def generate(self): gn_args["target_cpu"] = self.board.TargetCpuName() gn_args["android_ndk_root"] = os.environ["ANDROID_NDK_HOME"] gn_args["android_sdk_root"] = os.environ["ANDROID_HOME"] + if self.profile != AndroidProfile.DEBUG: + gn_args["is_debug"] = False gn_args.update(self.app.AppGnArgs()) args_str = "" @@ -368,6 +392,22 @@ def generate(self): app_dir = os.path.join(self.root, "examples/", self.app.AppName()) + def stripSymbols(self): + output_libs_dir = os.path.join( + self.output_dir, + "lib", + "jni", + self.board.AbiName()) + for lib in os.listdir(output_libs_dir): + if (lib.endswith(".so")): + self._Execute( + ["llvm-strip", + "-s", + os.path.join(output_libs_dir, lib) + ], + "Stripping symbols from " + lib + ) + def _build(self): if self.board.IsIde(): # App compilation IDE @@ -442,6 +482,9 @@ def _build(self): self.copyToExampleApp(jnilibs_dir, libs_dir, libs, jars) self.gradlewBuildExampleAndroid() + if (self.profile != AndroidProfile.DEBUG): + self.stripSymbols() + def build_outputs(self): if self.board.IsIde(): outputs = { @@ -465,15 +508,13 @@ def build_outputs(self): } else: outputs = { - self.app.AppName() - + "app-debug.apk": os.path.join( + self.app.AppName() + "app-debug.apk": os.path.join( self.output_dir, "outputs", "apk", "debug", "app-debug.apk" ) } else: outputs = { - self.app.AppName() - + "app-debug.apk": os.path.join( + self.app.AppName() + "app-debug.apk": os.path.join( self.output_dir, "outputs", "apk", "debug", "app-debug.apk" ), "CHIPController.jar": os.path.join( diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index 3c137d43294361..77a8a374038190 100644 --- a/scripts/build/testdata/all_targets_linux_x64.txt +++ b/scripts/build/testdata/all_targets_linux_x64.txt @@ -1,5 +1,5 @@ ameba-amebad-{all-clusters,all-clusters-minimal,light,light-switch,pigweed} -android-{arm,arm64,x86,x64,androidstudio-arm,androidstudio-arm64,androidstudio-x86,androidstudio-x64}-{chip-tool,chip-test,tv-server,tv-casting-app,java-matter-controller} +android-{arm,arm64,x86,x64,androidstudio-arm,androidstudio-arm64,androidstudio-x86,androidstudio-x64}-{chip-tool,chip-test,tv-server,tv-casting-app,java-matter-controller}[-no-debug] bouffalolab-{bl602-iot-matter-v1,bl602-iot-dvk-3s,bl602-night-light,xt-zb6-devkit,bl706-iot-dvk,bl706-night-light}-light[-shell][-115200][-rpc] cc13x2x7_26x2x7-{all-clusters,all-clusters-minimal,lock,pump,pump-controller,shell}[-ftd][-mtd] cc32xx-lock