diff --git a/.github/workflows/android.yaml b/.github/workflows/android.yaml index 0c1a6409f32158..d025d9c1a53f94 100644 --- a/.github/workflows/android.yaml +++ b/.github/workflows/android.yaml @@ -28,11 +28,12 @@ jobs: env: BUILD_TYPE: android_${{ matrix.type }} + TARGET_CPU: ${{ matrix.type }} runs-on: ubuntu-latest container: - image: connectedhomeip/chip-build-android:0.4.12 + image: connectedhomeip/chip-build-android:0.4.13 volumes: - "/tmp/log_output:/tmp/test_logs" @@ -43,10 +44,11 @@ jobs: submodules: true - name: Bootstrap run: scripts/build/gn_bootstrap.sh - - name: Setup Build + - name: Build libs run: | - GN_ARGS="is_clang=true target_os=\"android\" target_cpu=\"${{ matrix.type }}\" android_ndk_root=\"/opt/android/android-ndk-r21b\" android_sdk_root=\"/opt/android/sdk\"" - scripts/build/gn_gen.sh --args="$GN_ARGS" - - name: Run Build + ./scripts/examples/android_app.sh + - name: Build App run: | - scripts/build/gn_build.sh + yes | "$ANDROID_HOME"/tools/bin/sdkmanager --licenses + cd src/android/CHIPTool + ./gradlew build diff --git a/scripts/examples/android_app.sh b/scripts/examples/android_app.sh new file mode 100755 index 00000000000000..5bac64fbdf4dc0 --- /dev/null +++ b/scripts/examples/android_app.sh @@ -0,0 +1,47 @@ +#!/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 -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 + +# Build shared CHIP libs +source scripts/activate.sh +gn gen out/"android_$TARGET_CPU" --args="target_os=\"android\" target_cpu=\"$TARGET_CPU\" android_ndk_root=\"$ANDROID_NDK_HOME\" android_sdk_root=\"$ANDROID_HOME\"" +ninja -C out/"android_$TARGET_CPU" src/setup_payload/java src/controller/java + +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/src/main/jniLibs + +# Build ot-commissioner libs +git submodule update --init --recursive third_party/ot-commissioner/repo +TARGET_CPU=arm64 ./third_party/ot-commissioner/build-android-libs.sh diff --git a/src/android/CHIPTool/README.md b/src/android/CHIPTool/README.md index 88296862b06a37..7646d8adf4b6dc 100644 --- a/src/android/CHIPTool/README.md +++ b/src/android/CHIPTool/README.md @@ -14,11 +14,9 @@ Pre-conditions: Have Android SDK & NDK downloaded to your machine. Set the \$ANDROID_NDK_HOME environment variable to point to the NDK package is downloaded. -Make sure that JAVA_HOME is set to the correct path. +ABIs and corresponding values for `TARGET_CPU` -ABIs and corresponding values for `target_cpu` - -| ABI | target_cpu | +| ABI | TARGET_CPU | | ----------- | ---------- | | armeabi-v7a | arm | | arm64-v8a | arm64 | @@ -29,33 +27,11 @@ ABIs and corresponding values for `target_cpu` 2. In commandline / Terminal, 'cd' into the top CHIP directory and run - ```shell - source scripts/activate.sh - gn gen out/android_arm64 --args="target_os=\"android\" target_cpu=\"arm64\" android_ndk_root=\"${ANDROID_NDK_HOME}\" android_sdk_root=\"${ANDROID_HOME}\"" - ninja -C out/android_arm64 src/setup_payload/java src/controller/java - ``` - - See table above for other values of `target_cpu`. - -3. You should see the generated SetupPayloadParser.jar under - `out/android_arm64/lib` and libSetupPayloadParser.so under - `out/android_arm64/lib/jni/arm64-v8a` in the output directory. - -4. Copy the .jar and .so files into the Android project: - -```shell -rsync -a out/android_arm64/lib/*.jar src/android/CHIPTool/app/libs -rsync -a out/android_arm64/lib/jni/* src/android/CHIPTool/app/src/main/jniLibs -``` - -5. Build OT Commissioner - ```shell sudo apt-get install -y swig # "brew install swig" for macOS. - - git submodule update --init --recursive third_party/ot-commissioner/repo - ABI=arm64-v8a API=21 ./third_party/ot-commissioner/build-android-libs.sh - ## JAR and .so libraries will be copy to target directories. + TARGET_CPU=arm64 ./scripts/examples/android_app.sh ``` -6. 'Gradle sync' the Android project and run. + See table above for other values of `TARGET_CPU`. + +3. 'Gradle sync' the Android project and run. diff --git a/third_party/ot-commissioner/build-android-libs.sh b/third_party/ot-commissioner/build-android-libs.sh index ee28246367fde3..4ab251083fc9f3 100755 --- a/third_party/ot-commissioner/build-android-libs.sh +++ b/third_party/ot-commissioner/build-android-libs.sh @@ -4,14 +4,35 @@ readonly CUR_DIR="$(dirname "$(realpath -s "$0")")" set -e +case "$TARGET_CPU" in + arm) + TARGET_ABI="armeabi-v7a" + ;; + arm64) + TARGET_ABI="arm64-v8a" + ;; + x86) + TARGET_ABI="x86" + ;; + x64) + TARGET_ABI="x86-64" + ;; + *) + echo "invalid TARGET_CPU value: $TARGET_CPU" + exit 1 + ;; +esac + +readonly BUILD_DIR=".build_$TARGET_CPU" + cd "$CUR_DIR" -mkdir -p build && cd build +mkdir -p "$BUILD_DIR" && cd "$BUILD_DIR" cmake -GNinja \ -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME"/build/cmake/android.toolchain.cmake \ - -DANDROID_ABI="$ABI" \ + -DANDROID_ABI="$TARGET_ABI" \ -DANDROID_ARM_NEON=ON \ - -DANDROID_NATIVE_API_LEVEL="$API" \ + -DANDROID_NATIVE_API_LEVEL=24 \ -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_CXX_STANDARD=11 \ -DCMAKE_CXX_STANDARD_REQUIRED=ON \ @@ -26,17 +47,17 @@ cmake -GNinja \ ninja cd ../ -rm -rf libs && mkdir -p libs +rm -rf "$BUILD_DIR"/libs && mkdir -p "$BUILD_DIR"/libs ## Create JAR library -javac -source 8 -target 8 build/src/java/io/openthread/commissioner/*.java +javac -source 8 -target 8 "$BUILD_DIR"/src/java/io/openthread/commissioner/*.java -cd build/src/java -find ./io/openthread/commissioner -name "*.class" | xargs jar cvf ../../../libs/libotcommissioner.jar +cd "$BUILD_DIR"/src/java +find ./io/openthread/commissioner -name "*.class" | xargs jar cvf ../../libs/libotcommissioner.jar cd ../../../ ## Copy shared native libraries -cp ./build/src/java/libcommissioner-java.so libs +rsync -a "$BUILD_DIR"/src/java/libcommissioner-java.so "$BUILD_DIR"/libs -cp libs/libotcommissioner.jar ../../src/android/CHIPTool/app/libs -cp libs/*.so ../../src/android/CHIPTool/app/src/main/jniLibs/"$ABI" +rsync -a "$BUILD_DIR"/libs/libotcommissioner.jar ../../src/android/CHIPTool/app/libs +rsync -a "$BUILD_DIR"/libs/*.so ../../src/android/CHIPTool/app/src/main/jniLibs/"$TARGET_ABI"