From d350f76f85f913aa2e6ec5a14c3722520deb5706 Mon Sep 17 00:00:00 2001 From: Austin Hsieh Date: Tue, 21 Sep 2021 13:07:42 -0700 Subject: [PATCH] Test Java build rules --- .github/workflows/android.yaml | 6 +- BUILD.gn | 3 + build/chip/java/tests/BUILD.gn | 65 ++++++++++++++++ build/chip/java/tests/IncludedInChildJar.java | 3 + .../java/tests/IncludedInChildSources.java | 3 + .../java/tests/IncludedInChildSources2.java | 5 ++ .../tests/IncludedInGrandchildSources.java | 3 + build/chip/java/tests/IncludedInJar.java | 5 ++ build/chip/java/tests/IncludedInSources.java | 9 +++ build/chip/java/tests/empty_build_config.json | 8 ++ .../child_library_2_expected.json | 12 +++ .../child_library_expected.json | 8 ++ .../child_prebuilt_expected.json | 8 ++ .../grandchild_library_expected.json | 8 ++ .../java_library_expected.json | 18 +++++ .../java_prebuilt_expected.json | 12 +++ .../chip/java/tests/generate_jars_for_test.py | 47 ++++++++++++ build/chip/java/tests/test.py | 74 +++++++++++++++++++ scripts/build/builders/android.py | 25 +++++-- .../build/expected_all_platform_commands.txt | 36 ++++++++- src/android/CHIPTool/app/build.gradle | 6 -- src/controller/java/BUILD.gn | 6 ++ 22 files changed, 351 insertions(+), 19 deletions(-) create mode 100644 build/chip/java/tests/BUILD.gn create mode 100644 build/chip/java/tests/IncludedInChildJar.java create mode 100644 build/chip/java/tests/IncludedInChildSources.java create mode 100644 build/chip/java/tests/IncludedInChildSources2.java create mode 100644 build/chip/java/tests/IncludedInGrandchildSources.java create mode 100644 build/chip/java/tests/IncludedInJar.java create mode 100644 build/chip/java/tests/IncludedInSources.java create mode 100644 build/chip/java/tests/empty_build_config.json create mode 100644 build/chip/java/tests/expected_output/child_library_2_expected.json create mode 100644 build/chip/java/tests/expected_output/child_library_expected.json create mode 100644 build/chip/java/tests/expected_output/child_prebuilt_expected.json create mode 100644 build/chip/java/tests/expected_output/grandchild_library_expected.json create mode 100644 build/chip/java/tests/expected_output/java_library_expected.json create mode 100644 build/chip/java/tests/expected_output/java_prebuilt_expected.json create mode 100644 build/chip/java/tests/generate_jars_for_test.py create mode 100755 build/chip/java/tests/test.py diff --git a/.github/workflows/android.yaml b/.github/workflows/android.yaml index b001733aee104e..0b1658163807a3 100644 --- a/.github/workflows/android.yaml +++ b/.github/workflows/android.yaml @@ -54,7 +54,11 @@ jobs: path: | .environment/gn_out/.ninja_log .environment/pigweed-venv/*.log - - name: Build android examples + - name: Build Android examples run: | ./scripts/run_in_build_env.sh \ "./scripts/build/build_examples.py --no-log-timestamps --platform android build" + - name: Run Android build rule tests + run: | + ./scripts/run_in_build_env.sh \ + "ninja -C out/android-arm64-chip_tool build/chip/java/tests:java_build_test.tests" diff --git a/BUILD.gn b/BUILD.gn index ec7eae35dd2a35..9103cb691ed36e 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -92,6 +92,9 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") { if (chip_build_tests) { deps += [ "//src:tests" ] + if (current_os == "android") { + deps += [ "${chip_root}/build/chip/java/tests:java_build_test" ] + } } if (chip_with_lwip) { diff --git a/build/chip/java/tests/BUILD.gn b/build/chip/java/tests/BUILD.gn new file mode 100644 index 00000000000000..e98cb1f8a9cdd6 --- /dev/null +++ b/build/chip/java/tests/BUILD.gn @@ -0,0 +1,65 @@ +# Copyright (c) 2021 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. + +import("//build_overrides/chip.gni") +import("//build_overrides/pigweed.gni") +import("$dir_pw_build/python.gni") +import("${chip_root}/build/chip/java/rules.gni") + +pw_python_script("java_build_test") { + inputs = [ + "expected_output/child_library_2_expected.json", + "expected_output/grandchild_library_expected.json", + "expected_output/child_library_expected.json", + "expected_output/java_library_expected.json", + "expected_output/child_prebuilt_expected.json", + "expected_output/java_prebuilt_expected.json", + ] + other_deps = [ ":java_library" ] + tests = [ "test.py" ] +} + +java_library("java_library") { + sources = [ + "IncludedInSources.java", + ] + deps = [ + ":child_library", + ":child_library_2", + ":java_prebuilt", + ] +} + +java_library("child_library") { + sources = [ "IncludedInChildSources.java" ] +} + +java_library("child_library_2") { + sources = [ "IncludedInChildSources2.java" ] + + deps = [ ":grandchild_library" ] +} + +java_library("grandchild_library") { + sources = [ "IncludedInGrandchildSources.java" ] +} + +java_prebuilt("java_prebuilt") { + jar_path = "/tmp/chip_java_build_test/prebuilt_jar.jar" + deps = [ ":child_prebuilt" ] +} + +java_prebuilt("child_prebuilt") { + jar_path = "/tmp/chip_java_build_test/child_jar.jar" +} diff --git a/build/chip/java/tests/IncludedInChildJar.java b/build/chip/java/tests/IncludedInChildJar.java new file mode 100644 index 00000000000000..b1b09c33414d59 --- /dev/null +++ b/build/chip/java/tests/IncludedInChildJar.java @@ -0,0 +1,3 @@ +package build.chip.java.tests; + +public class IncludedInChildJar {} diff --git a/build/chip/java/tests/IncludedInChildSources.java b/build/chip/java/tests/IncludedInChildSources.java new file mode 100644 index 00000000000000..a74febaaf01e8a --- /dev/null +++ b/build/chip/java/tests/IncludedInChildSources.java @@ -0,0 +1,3 @@ +package build.chip.java.tests; + +public class IncludedInChildSources {} diff --git a/build/chip/java/tests/IncludedInChildSources2.java b/build/chip/java/tests/IncludedInChildSources2.java new file mode 100644 index 00000000000000..e20676490f483d --- /dev/null +++ b/build/chip/java/tests/IncludedInChildSources2.java @@ -0,0 +1,5 @@ +package build.chip.java.tests; + +public class IncludedInChildSources2 { + IncludedInGrandchildSources includedInGrandchildSources; +} diff --git a/build/chip/java/tests/IncludedInGrandchildSources.java b/build/chip/java/tests/IncludedInGrandchildSources.java new file mode 100644 index 00000000000000..fb7005efa42a5f --- /dev/null +++ b/build/chip/java/tests/IncludedInGrandchildSources.java @@ -0,0 +1,3 @@ +package build.chip.java.tests; + +public class IncludedInGrandchildSources {} diff --git a/build/chip/java/tests/IncludedInJar.java b/build/chip/java/tests/IncludedInJar.java new file mode 100644 index 00000000000000..0d51eaa08e2a85 --- /dev/null +++ b/build/chip/java/tests/IncludedInJar.java @@ -0,0 +1,5 @@ +package build.chip.java.tests; + +public class IncludedInJar { + IncludedInChildJar includedInChildJar; +} diff --git a/build/chip/java/tests/IncludedInSources.java b/build/chip/java/tests/IncludedInSources.java new file mode 100644 index 00000000000000..890cf286da4301 --- /dev/null +++ b/build/chip/java/tests/IncludedInSources.java @@ -0,0 +1,9 @@ +package build.chip.java.tests; + +public class IncludedInSources { + IncludedInChildSources includedInChildSources; + IncludedInChildSources2 includedInChildSources2; + IncludedInGrandchildSources includedInGrandchildSources; + + IncludedInJar includedInJar; +} diff --git a/build/chip/java/tests/empty_build_config.json b/build/chip/java/tests/empty_build_config.json new file mode 100644 index 00000000000000..60d052b5814131 --- /dev/null +++ b/build/chip/java/tests/empty_build_config.json @@ -0,0 +1,8 @@ +{ + "deps_info": { + "name": "", + "jar_path": "", + "deps_configs": [], + "deps_jars": [] + } +} \ No newline at end of file diff --git a/build/chip/java/tests/expected_output/child_library_2_expected.json b/build/chip/java/tests/expected_output/child_library_2_expected.json new file mode 100644 index 00000000000000..826e8beeaf1870 --- /dev/null +++ b/build/chip/java/tests/expected_output/child_library_2_expected.json @@ -0,0 +1,12 @@ +{ + "deps_info": { + "name": "child_library_2.json", + "jar_path": "python/lib/build/chip/java/tests/child_library_2.jar", + "deps_configs": [ + "python/gen/build/chip/java/tests/grandchild_library.json" + ], + "deps_jars": [ + "python/lib/build/chip/java/tests/grandchild_library.jar" + ] + } +} \ No newline at end of file diff --git a/build/chip/java/tests/expected_output/child_library_expected.json b/build/chip/java/tests/expected_output/child_library_expected.json new file mode 100644 index 00000000000000..e708483b4b76f3 --- /dev/null +++ b/build/chip/java/tests/expected_output/child_library_expected.json @@ -0,0 +1,8 @@ +{ + "deps_info": { + "name": "child_library.json", + "jar_path": "python/lib/build/chip/java/tests/child_library.jar", + "deps_configs": [], + "deps_jars": [] + } +} \ No newline at end of file diff --git a/build/chip/java/tests/expected_output/child_prebuilt_expected.json b/build/chip/java/tests/expected_output/child_prebuilt_expected.json new file mode 100644 index 00000000000000..00a73c34e981ce --- /dev/null +++ b/build/chip/java/tests/expected_output/child_prebuilt_expected.json @@ -0,0 +1,8 @@ +{ + "deps_info": { + "name": "child_prebuilt.json", + "jar_path": "python/lib/build/chip/java/tests/child_jar.jar", + "deps_configs": [], + "deps_jars": [] + } +} \ No newline at end of file diff --git a/build/chip/java/tests/expected_output/grandchild_library_expected.json b/build/chip/java/tests/expected_output/grandchild_library_expected.json new file mode 100644 index 00000000000000..b50e4e2ee7d870 --- /dev/null +++ b/build/chip/java/tests/expected_output/grandchild_library_expected.json @@ -0,0 +1,8 @@ +{ + "deps_info": { + "name": "grandchild_library.json", + "jar_path": "python/lib/build/chip/java/tests/grandchild_library.jar", + "deps_configs": [], + "deps_jars": [] + } +} \ No newline at end of file diff --git a/build/chip/java/tests/expected_output/java_library_expected.json b/build/chip/java/tests/expected_output/java_library_expected.json new file mode 100644 index 00000000000000..8318f0160dc525 --- /dev/null +++ b/build/chip/java/tests/expected_output/java_library_expected.json @@ -0,0 +1,18 @@ +{ + "deps_info": { + "name": "java_library.json", + "jar_path": "python/lib/build/chip/java/tests/java_library.jar", + "deps_configs": [ + "python/gen/build/chip/java/tests/child_library.json", + "python/gen/build/chip/java/tests/child_library_2.json", + "python/gen/build/chip/java/tests/java_prebuilt.json" + ], + "deps_jars": [ + "python/lib/build/chip/java/tests/child_library.jar", + "python/lib/build/chip/java/tests/child_library_2.jar", + "python/lib/build/chip/java/tests/grandchild_library.jar", + "python/lib/build/chip/java/tests/prebuilt_jar.jar", + "python/lib/build/chip/java/tests/child_jar.jar" + ] + } +} \ No newline at end of file diff --git a/build/chip/java/tests/expected_output/java_prebuilt_expected.json b/build/chip/java/tests/expected_output/java_prebuilt_expected.json new file mode 100644 index 00000000000000..820a710aea61ff --- /dev/null +++ b/build/chip/java/tests/expected_output/java_prebuilt_expected.json @@ -0,0 +1,12 @@ +{ + "deps_info": { + "name": "java_prebuilt.json", + "jar_path": "python/lib/build/chip/java/tests/prebuilt_jar.jar", + "deps_configs": [ + "python/gen/build/chip/java/tests/child_prebuilt.json" + ], + "deps_jars": [ + "python/lib/build/chip/java/tests/child_jar.jar" + ] + } +} \ No newline at end of file diff --git a/build/chip/java/tests/generate_jars_for_test.py b/build/chip/java/tests/generate_jars_for_test.py new file mode 100644 index 00000000000000..ffe3b42b23c351 --- /dev/null +++ b/build/chip/java/tests/generate_jars_for_test.py @@ -0,0 +1,47 @@ +import os +import subprocess +import sys + +"""Generate JARs used to test the java_prebuilt rule.""" + +chip_root = os.getenv('PW_PROJECT_ROOT') +test_dir = chip_root + '/build/chip/java/tests' +tmp_dir = '/tmp/chip_java_build_test' + +def generateJar(source_file, output_name): + tmp_classes_dir = tmp_dir + '/classes' + os.makedirs(tmp_dir, exist_ok=True) + os.makedirs(tmp_dir + '/classes', exist_ok=True) + javac_runner_command = [ + 'python3', + chip_root + '/build/chip/java/javac_runner.py', + '--classdir', + tmp_classes_dir, + '--outfile', + tmp_dir + '/prebuilt_jar.classlist', + '--build-config', + test_dir + '/empty_build_config.json', + '--', + '-d', + tmp_classes_dir, + source_file, + ] + subprocess.check_call(javac_runner_command) + + jar_runner_command = [ + 'python3', + chip_root + '/build/chip/java/jar_runner.py', + 'cf', + tmp_dir + '/' + output_name, + '-C', + tmp_classes_dir, + '.', + ] + subprocess.check_call(jar_runner_command) + +def main(): + generateJar(test_dir + '/IncludedInJar.java', 'prebuilt_jar.jar') + generateJar(test_dir + '/IncludedInChildJar.java', 'child_jar.jar') + +if __name__ == '__main__': + sys.exit(main()) diff --git a/build/chip/java/tests/test.py b/build/chip/java/tests/test.py new file mode 100755 index 00000000000000..700f35e94f0aa4 --- /dev/null +++ b/build/chip/java/tests/test.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +# Copyright (c) 2021 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. + +""" +Test for GN Java build rules. This test should be executed using ninja, and +generate_jars_for_test.py should have been called before running this test. +""" + +import json +import os +from os import path +import subprocess +import unittest + +class JavaBuildTest(unittest.TestCase): + chip_root = os.getenv('PW_PROJECT_ROOT') + local_test_dir = '/build/chip/java/tests' + test_dir = chip_root + local_test_dir + + jars_dir = 'python/lib' + local_test_dir + configs_dir = 'python/gen' + local_test_dir + + tmp_dir = '/tmp/chip_java_build_test' + + # Target names in the BUILD.gn + targets_to_check = [ + 'java_library', + 'child_library', + 'child_library_2', + 'grandchild_library', + ] + prebuilt_targets_to_check = [ + 'java_prebuilt', + 'child_prebuilt' + ] + + def testExpectedJarsCreated(self): + jars_dir = JavaBuildTest.jars_dir + for target in JavaBuildTest.targets_to_check: + self.assertTrue(path.exists(jars_dir + '/' + target + '.jar')) + + # Prebuilt jars should have been copied to the output directory. + self.assertTrue(path.exists(jars_dir + '/prebuilt_jar.jar')) + self.assertTrue(path.exists(jars_dir + '/child_jar.jar')) + + def testBuildConfigMatchesExpected(self): + self.maxDiff = None + configs_dir = JavaBuildTest.configs_dir + expected_dir = JavaBuildTest.test_dir + '/expected_output' + + for target in (JavaBuildTest.targets_to_check + JavaBuildTest.prebuilt_targets_to_check): + with open(expected_dir + '/' + target + '_expected.json', 'r') as expected_config, open(configs_dir + '/' + target + '.json', 'r') as actual_config: + expected_json = json.load(expected_config)['deps_info'] + actual_json = json.load(actual_config)['deps_info'] + + self.assertEqual(expected_json['name'], actual_json['name']) + self.assertEqual(expected_json['jar_path'], actual_json['jar_path']) + self.assertCountEqual(expected_json['deps_configs'], actual_json['deps_configs']) + self.assertCountEqual(expected_json['deps_jars'], actual_json['deps_jars']) + +if __name__ == '__main__': + unittest.main() diff --git a/scripts/build/builders/android.py b/scripts/build/builders/android.py index 902970b45b7851..3d9b80d317053c 100644 --- a/scripts/build/builders/android.py +++ b/scripts/build/builders/android.py @@ -87,6 +87,10 @@ def validate_build_environment(self): % licenses) def generate(self): + self._Execute([ + 'python3', 'build/chip/java/tests/generate_jars_for_test.py' + ], title='Generating JARs for Java build rules test') + if not os.path.exists(self.output_dir): # NRF does a in-place update of SDK tools if not self._runner.dry_run: @@ -120,11 +124,6 @@ def _build(self): self._Execute(['ninja', '-C', self.output_dir], title='Building JNI ' + self.identifier) - # NOTE: the following IDE-specific build instructions are NOT used: - # - "rsync -a out/"android_$TARGET_CPU"/lib/*.jar src/android/CHIPTool/app/libs" - # => using the 'ninjaOutputDir' project property instead to take the jar files directly - # from the output - # JNILibs will be copied as long as they reside in src/main/jniLibs/ABI: # https://developer.android.com/studio/projects/gradle-external-native-builds#jniLibs # to avoid redefined in IDE mode, copy to another place and add that path in build.gradle @@ -133,6 +132,7 @@ def _build(self): # when using dry run. jnilibs_dir = os.path.join( self.root, 'src/android/CHIPTool/app/libs/jniLibs', self.board.AbiName()) + libs_dir = os.path.join(self.root, 'src/android/CHIPTool/app/libs') self._Execute(['mkdir', '-p', jnilibs_dir], title='Prepare Native libs ' + self.identifier) @@ -149,11 +149,18 @@ def _build(self): self._Execute(['cp', os.path.join(self.output_dir, 'lib', 'jni', self.board.AbiName( ), libName), os.path.join(jnilibs_dir, libName)]) + jars = { + 'CHIPController.jar': 'src/controller/java/CHIPController.jar', + 'SetupPayloadParser.jar': 'src/setup_payload/java/SetupPayloadParser.jar' + } + for jarName in jars.keys(): + self._Execute(['cp', os.path.join( + self.output_dir, 'lib', jars[jarName]), os.path.join(libs_dir, jarName)]) + # App compilation self._Execute([ '%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, 'assembleDebug' ], title='Building APP ' + self.identifier) @@ -161,9 +168,11 @@ def _build(self): def build_outputs(self): outputs = { 'CHIPController.jar': - os.path.join(self.output_dir, 'lib', 'CHIPController.jar'), + os.path.join(self.output_dir, 'lib', + 'src/controller/java/CHIPController.jar'), 'SetupPayloadParser.jar': - os.path.join(self.output_dir, 'lib', 'SetupPayloadParser.jar'), + os.path.join(self.output_dir, 'lib', + 'src/setup_payload/java/SetupPayloadParser.jar'), 'ChipTool-debug.apk': os.path.join(self.output_dir, 'outputs', 'apk', 'debug', 'app-debug.apk'), diff --git a/scripts/build/expected_all_platform_commands.txt b/scripts/build/expected_all_platform_commands.txt index 81f99f21b5832c..026bb08b8e4575 100644 --- a/scripts/build/expected_all_platform_commands.txt +++ b/scripts/build/expected_all_platform_commands.txt @@ -104,24 +104,36 @@ bash -c 'source "$ZEPHYR_BASE/zephyr-env.sh"; export GNUARMEMB_TOOLCHAIN_PATH="$PW_PIGWEED_CIPD_INSTALL_DIR"; west build --cmake-only -d {out}/nrf-nrf5340-pump_controller -b nrf5340dk_nrf5340_cpuapp {root}/examples/pump-controller-app/nrfconnect' +# Generating JARs for Java build rules test +python3 build/chip/java/tests/generate_jars_for_test.py + # Generating android-arm-chip_tool gn gen --check --fail-on-unused-args {out}/android-arm-chip_tool '--args=target_os="android" target_cpu="arm" 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 JARs for Java build rules test +python3 build/chip/java/tests/generate_jars_for_test.py + # Generating android-arm64-chip_tool gn gen --check --fail-on-unused-args {out}/android-arm64-chip_tool '--args=target_os="android" target_cpu="arm64" 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 JARs for Java build rules test +python3 build/chip/java/tests/generate_jars_for_test.py + # Generating android-x64-chip_tool gn gen --check --fail-on-unused-args {out}/android-x64-chip_tool '--args=target_os="android" target_cpu="x64" 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 JARs for Java build rules test +python3 build/chip/java/tests/generate_jars_for_test.py + # 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"' @@ -225,8 +237,12 @@ 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 +cp {out}/android-arm-chip_tool/lib/src/controller/java/CHIPController.jar {root}/src/android/CHIPTool/app/libs/CHIPController.jar + +cp {out}/android-arm-chip_tool/lib/src/setup_payload/java/SetupPayloadParser.jar {root}/src/android/CHIPTool/app/libs/SetupPayloadParser.jar + # 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 assembleDebug +{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PbuildDir={out}/android-arm-chip_tool assembleDebug # Building JNI android-arm64-chip_tool ninja -C {out}/android-arm64-chip_tool @@ -240,8 +256,12 @@ 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 +cp {out}/android-arm64-chip_tool/lib/src/controller/java/CHIPController.jar {root}/src/android/CHIPTool/app/libs/CHIPController.jar + +cp {out}/android-arm64-chip_tool/lib/src/setup_payload/java/SetupPayloadParser.jar {root}/src/android/CHIPTool/app/libs/SetupPayloadParser.jar + # 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 assembleDebug +{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PbuildDir={out}/android-arm64-chip_tool assembleDebug # Building JNI android-x64-chip_tool ninja -C {out}/android-x64-chip_tool @@ -255,8 +275,12 @@ 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 +cp {out}/android-x64-chip_tool/lib/src/controller/java/CHIPController.jar {root}/src/android/CHIPTool/app/libs/CHIPController.jar + +cp {out}/android-x64-chip_tool/lib/src/setup_payload/java/SetupPayloadParser.jar {root}/src/android/CHIPTool/app/libs/SetupPayloadParser.jar + # 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 assembleDebug +{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PbuildDir={out}/android-x64-chip_tool assembleDebug # Building JNI android-x86-chip_tool ninja -C {out}/android-x86-chip_tool @@ -270,8 +294,12 @@ cp {out}/android-x86-chip_tool/lib/jni/x86/libCHIPController.so {root}/src/andro cp {out}/android-x86-chip_tool/lib/jni/x86/libc++_shared.so {root}/src/android/CHIPTool/app/libs/jniLibs/x86/libc++_shared.so +cp {out}/android-x86-chip_tool/lib/src/controller/java/CHIPController.jar {root}/src/android/CHIPTool/app/libs/CHIPController.jar + +cp {out}/android-x86-chip_tool/lib/src/setup_payload/java/SetupPayloadParser.jar {root}/src/android/CHIPTool/app/libs/SetupPayloadParser.jar + # 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 +{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PbuildDir={out}/android-x86-chip_tool assembleDebug # Building infineon-p6board-lock ninja -C {out}/infineon-p6board-lock diff --git a/src/android/CHIPTool/app/build.gradle b/src/android/CHIPTool/app/build.gradle index a160748c7f105e..ee401987ae4600 100644 --- a/src/android/CHIPTool/app/build.gradle +++ b/src/android/CHIPTool/app/build.gradle @@ -80,12 +80,6 @@ dependencies { if (matterBuildSrcDir.isEmpty()) { // local in-source-tree copy of the dependencies. Useful for IDE compilation implementation fileTree(dir: "libs", include: ["*.jar", "*.so"]) - - // build time dependencies - if (project.hasProperty("chipSdkJarDir")) { - println "Compiling using custom sdk jar file directory: ${chipSdkJarDir}" - implementation fileTree(dir: "${chipSdkJarDir}", include: ["*.jar", "*.so"]) - } } else { implementation project(':chip-library') } diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index fc2fca12f78d60..a7e3f2d5a34e4b 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -60,6 +60,8 @@ shared_library("jni") { android_library("java") { output_name = "CHIPController.jar" + deps = [ ":android" ] + data_deps = [ ":jni", "${chip_root}/build/chip/java:shared_cpplib", @@ -86,3 +88,7 @@ android_library("java") { # TODO: add classpath support (we likely need to add something like # ..../platforms/android-21/android.jar to access BLE items) } + +java_prebuilt("android") { + jar_path = "${android_sdk_root}/platforms/android-21/android.jar" +} \ No newline at end of file