diff --git a/examples/tv-app/android/.gn b/examples/tv-app/android/.gn
new file mode 100644
index 00000000000000..5d1ce757507582
--- /dev/null
+++ b/examples/tv-app/android/.gn
@@ -0,0 +1,25 @@
+# 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.
+
+import("//build_overrides/build.gni")
+
+# The location of the build configuration file.
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
+
+# CHIP uses angle bracket includes.
+check_system_includes = true
+
+default_args = {
+ import("//args.gni")
+}
diff --git a/src/android/CHIPTVServer/.gitignore b/examples/tv-app/android/App/.gitignore
similarity index 100%
rename from src/android/CHIPTVServer/.gitignore
rename to examples/tv-app/android/App/.gitignore
diff --git a/src/android/CHIPTVServer/.idea/.gitignore b/examples/tv-app/android/App/.idea/.gitignore
similarity index 100%
rename from src/android/CHIPTVServer/.idea/.gitignore
rename to examples/tv-app/android/App/.idea/.gitignore
diff --git a/examples/tv-app/android/App/.idea/.name b/examples/tv-app/android/App/.idea/.name
new file mode 100644
index 00000000000000..55b67a119f278a
--- /dev/null
+++ b/examples/tv-app/android/App/.idea/.name
@@ -0,0 +1 @@
+CHIPTVServer
\ No newline at end of file
diff --git a/src/android/CHIPTVServer/.idea/compiler.xml b/examples/tv-app/android/App/.idea/compiler.xml
similarity index 100%
rename from src/android/CHIPTVServer/.idea/compiler.xml
rename to examples/tv-app/android/App/.idea/compiler.xml
diff --git a/src/android/CHIPTVServer/.idea/gradle.xml b/examples/tv-app/android/App/.idea/gradle.xml
similarity index 100%
rename from src/android/CHIPTVServer/.idea/gradle.xml
rename to examples/tv-app/android/App/.idea/gradle.xml
diff --git a/examples/tv-app/android/App/.idea/jarRepositories.xml b/examples/tv-app/android/App/.idea/jarRepositories.xml
new file mode 100644
index 00000000000000..0380d8d3dee94c
--- /dev/null
+++ b/examples/tv-app/android/App/.idea/jarRepositories.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/android/CHIPTVServer/.idea/misc.xml b/examples/tv-app/android/App/.idea/misc.xml
similarity index 100%
rename from src/android/CHIPTVServer/.idea/misc.xml
rename to examples/tv-app/android/App/.idea/misc.xml
diff --git a/src/android/CHIPTVServer/.idea/vcs.xml b/examples/tv-app/android/App/.idea/vcs.xml
similarity index 66%
rename from src/android/CHIPTVServer/.idea/vcs.xml
rename to examples/tv-app/android/App/.idea/vcs.xml
index c2365ab11f9ba6..4fce1d86b49521 100644
--- a/src/android/CHIPTVServer/.idea/vcs.xml
+++ b/examples/tv-app/android/App/.idea/vcs.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/src/android/CHIPTVServer/app/.gitignore b/examples/tv-app/android/App/app/.gitignore
similarity index 100%
rename from src/android/CHIPTVServer/app/.gitignore
rename to examples/tv-app/android/App/app/.gitignore
diff --git a/src/android/CHIPTVServer/app/build.gradle b/examples/tv-app/android/App/app/build.gradle
similarity index 80%
rename from src/android/CHIPTVServer/app/build.gradle
rename to examples/tv-app/android/App/app/build.gradle
index 9217e7226246ce..35b5cff38413e6 100644
--- a/src/android/CHIPTVServer/app/build.gradle
+++ b/examples/tv-app/android/App/app/build.gradle
@@ -31,16 +31,19 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}
-
sourceSets {
main {
jniLibs.srcDirs = ['libs/jniLibs']
+
+ // uncomment this code to debug
+// java.srcDirs = [
+// 'src/main/java',
+// '../../third_party/connectedhomeip/src/setup_payload/java/src',
+// '../../third_party/connectedhomeip/src/platform/android/java',
+// '../../java/src',
+// ]
}
}
-
-
-
-
}
dependencies {
diff --git a/src/android/CHIPTVServer/app/libs/README.md b/examples/tv-app/android/App/app/libs/README.md
similarity index 100%
rename from src/android/CHIPTVServer/app/libs/README.md
rename to examples/tv-app/android/App/app/libs/README.md
diff --git a/src/android/CHIPTVServer/app/libs/jniLibs/README.md b/examples/tv-app/android/App/app/libs/jniLibs/README.md
similarity index 100%
rename from src/android/CHIPTVServer/app/libs/jniLibs/README.md
rename to examples/tv-app/android/App/app/libs/jniLibs/README.md
diff --git a/src/android/CHIPTVServer/app/proguard-rules.pro b/examples/tv-app/android/App/app/proguard-rules.pro
similarity index 100%
rename from src/android/CHIPTVServer/app/proguard-rules.pro
rename to examples/tv-app/android/App/app/proguard-rules.pro
diff --git a/src/android/CHIPTVServer/app/src/androidTest/java/com/tcl/chip/chiptvserver/ExampleInstrumentedTest.java b/examples/tv-app/android/App/app/src/androidTest/java/com/tcl/chip/chiptvserver/ExampleInstrumentedTest.java
similarity index 100%
rename from src/android/CHIPTVServer/app/src/androidTest/java/com/tcl/chip/chiptvserver/ExampleInstrumentedTest.java
rename to examples/tv-app/android/App/app/src/androidTest/java/com/tcl/chip/chiptvserver/ExampleInstrumentedTest.java
diff --git a/src/android/CHIPTVServer/app/src/main/AndroidManifest.xml b/examples/tv-app/android/App/app/src/main/AndroidManifest.xml
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/AndroidManifest.xml
rename to examples/tv-app/android/App/app/src/main/AndroidManifest.xml
diff --git a/src/android/CHIPTVServer/app/src/main/java/com/tcl/chip/chiptvserver/MainActivity.java b/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/MainActivity.java
similarity index 97%
rename from src/android/CHIPTVServer/app/src/main/java/com/tcl/chip/chiptvserver/MainActivity.java
rename to examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/MainActivity.java
index 6fcde199cc60c0..7e0e8cc18a2abc 100644
--- a/src/android/CHIPTVServer/app/src/main/java/com/tcl/chip/chiptvserver/MainActivity.java
+++ b/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/MainActivity.java
@@ -15,6 +15,7 @@
import chip.setuppayload.DiscoveryCapability;
import chip.setuppayload.SetupPayload;
import chip.setuppayload.SetupPayloadParser;
+import com.tcl.tvapp.TvApp;
import java.util.HashSet;
public class MainActivity extends AppCompatActivity {
@@ -30,7 +31,7 @@ protected void onCreate(Bundle savedInstanceState) {
mQrCodeImg = findViewById(R.id.qrCodeImg);
mQrCodeTxt = findViewById(R.id.qrCodeTxt);
mManualPairingCodeTxt = findViewById(R.id.manualPairingCodeTxt);
- ChipAppServer chipAppServer = new ChipAppServer();
+ TvApp tvApp = new TvApp();
AndroidChipPlatform chipPlatform =
new AndroidChipPlatform(
new AndroidBleManager(),
@@ -63,6 +64,7 @@ protected void onCreate(Bundle savedInstanceState) {
e.printStackTrace();
}
+ ChipAppServer chipAppServer = new ChipAppServer();
chipAppServer.startApp();
}
}
diff --git a/src/android/CHIPTVServer/app/src/main/java/com/tcl/chip/chiptvserver/QRUtils.java b/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/QRUtils.java
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/java/com/tcl/chip/chiptvserver/QRUtils.java
rename to examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/QRUtils.java
diff --git a/src/android/CHIPTVServer/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/examples/tv-app/android/App/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
rename to examples/tv-app/android/App/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
diff --git a/src/android/CHIPTVServer/app/src/main/res/drawable/ic_launcher_background.xml b/examples/tv-app/android/App/app/src/main/res/drawable/ic_launcher_background.xml
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/drawable/ic_launcher_background.xml
rename to examples/tv-app/android/App/app/src/main/res/drawable/ic_launcher_background.xml
diff --git a/src/android/CHIPTVServer/app/src/main/res/layout/activity_main.xml b/examples/tv-app/android/App/app/src/main/res/layout/activity_main.xml
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/layout/activity_main.xml
rename to examples/tv-app/android/App/app/src/main/res/layout/activity_main.xml
diff --git a/src/android/CHIPTVServer/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/examples/tv-app/android/App/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
rename to examples/tv-app/android/App/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
diff --git a/src/android/CHIPTVServer/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/examples/tv-app/android/App/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
rename to examples/tv-app/android/App/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
diff --git a/src/android/CHIPTVServer/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/examples/tv-app/android/App/app/src/main/res/mipmap-hdpi/ic_launcher.webp
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/mipmap-hdpi/ic_launcher.webp
rename to examples/tv-app/android/App/app/src/main/res/mipmap-hdpi/ic_launcher.webp
diff --git a/src/android/CHIPTVServer/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/examples/tv-app/android/App/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
rename to examples/tv-app/android/App/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
diff --git a/src/android/CHIPTVServer/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/examples/tv-app/android/App/app/src/main/res/mipmap-mdpi/ic_launcher.webp
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/mipmap-mdpi/ic_launcher.webp
rename to examples/tv-app/android/App/app/src/main/res/mipmap-mdpi/ic_launcher.webp
diff --git a/src/android/CHIPTVServer/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/examples/tv-app/android/App/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
rename to examples/tv-app/android/App/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
diff --git a/src/android/CHIPTVServer/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/examples/tv-app/android/App/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
rename to examples/tv-app/android/App/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
diff --git a/src/android/CHIPTVServer/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/examples/tv-app/android/App/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
rename to examples/tv-app/android/App/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
diff --git a/src/android/CHIPTVServer/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/examples/tv-app/android/App/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
rename to examples/tv-app/android/App/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
diff --git a/src/android/CHIPTVServer/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/examples/tv-app/android/App/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
rename to examples/tv-app/android/App/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
diff --git a/src/android/CHIPTVServer/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/examples/tv-app/android/App/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
rename to examples/tv-app/android/App/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
diff --git a/src/android/CHIPTVServer/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/examples/tv-app/android/App/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
rename to examples/tv-app/android/App/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
diff --git a/src/android/CHIPTVServer/app/src/main/res/values-night/themes.xml b/examples/tv-app/android/App/app/src/main/res/values-night/themes.xml
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/values-night/themes.xml
rename to examples/tv-app/android/App/app/src/main/res/values-night/themes.xml
diff --git a/src/android/CHIPTVServer/app/src/main/res/values/colors.xml b/examples/tv-app/android/App/app/src/main/res/values/colors.xml
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/values/colors.xml
rename to examples/tv-app/android/App/app/src/main/res/values/colors.xml
diff --git a/src/android/CHIPTVServer/app/src/main/res/values/strings.xml b/examples/tv-app/android/App/app/src/main/res/values/strings.xml
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/values/strings.xml
rename to examples/tv-app/android/App/app/src/main/res/values/strings.xml
diff --git a/src/android/CHIPTVServer/app/src/main/res/values/themes.xml b/examples/tv-app/android/App/app/src/main/res/values/themes.xml
similarity index 100%
rename from src/android/CHIPTVServer/app/src/main/res/values/themes.xml
rename to examples/tv-app/android/App/app/src/main/res/values/themes.xml
diff --git a/src/android/CHIPTVServer/app/src/test/java/com/tcl/chip/chiptvslave/ExampleUnitTest.java b/examples/tv-app/android/App/app/src/test/java/com/tcl/chip/chiptvslave/ExampleUnitTest.java
similarity index 100%
rename from src/android/CHIPTVServer/app/src/test/java/com/tcl/chip/chiptvslave/ExampleUnitTest.java
rename to examples/tv-app/android/App/app/src/test/java/com/tcl/chip/chiptvslave/ExampleUnitTest.java
diff --git a/src/android/CHIPTVServer/build.gradle b/examples/tv-app/android/App/build.gradle
similarity index 100%
rename from src/android/CHIPTVServer/build.gradle
rename to examples/tv-app/android/App/build.gradle
diff --git a/src/android/CHIPTVServer/gradle.properties b/examples/tv-app/android/App/gradle.properties
similarity index 100%
rename from src/android/CHIPTVServer/gradle.properties
rename to examples/tv-app/android/App/gradle.properties
diff --git a/src/android/CHIPTVServer/gradle/wrapper/gradle-wrapper.jar b/examples/tv-app/android/App/gradle/wrapper/gradle-wrapper.jar
similarity index 100%
rename from src/android/CHIPTVServer/gradle/wrapper/gradle-wrapper.jar
rename to examples/tv-app/android/App/gradle/wrapper/gradle-wrapper.jar
diff --git a/src/android/CHIPTVServer/gradle/wrapper/gradle-wrapper.properties b/examples/tv-app/android/App/gradle/wrapper/gradle-wrapper.properties
similarity index 100%
rename from src/android/CHIPTVServer/gradle/wrapper/gradle-wrapper.properties
rename to examples/tv-app/android/App/gradle/wrapper/gradle-wrapper.properties
diff --git a/src/android/CHIPTVServer/gradlew b/examples/tv-app/android/App/gradlew
similarity index 100%
rename from src/android/CHIPTVServer/gradlew
rename to examples/tv-app/android/App/gradlew
diff --git a/src/android/CHIPTVServer/gradlew.bat b/examples/tv-app/android/App/gradlew.bat
similarity index 100%
rename from src/android/CHIPTVServer/gradlew.bat
rename to examples/tv-app/android/App/gradlew.bat
diff --git a/src/android/CHIPTVServer/settings.gradle b/examples/tv-app/android/App/settings.gradle
similarity index 100%
rename from src/android/CHIPTVServer/settings.gradle
rename to examples/tv-app/android/App/settings.gradle
diff --git a/examples/tv-app/android/BUILD.gn b/examples/tv-app/android/BUILD.gn
index d071cdc16769d8..ecb6b5964a0f95 100644
--- a/examples/tv-app/android/BUILD.gn
+++ b/examples/tv-app/android/BUILD.gn
@@ -15,10 +15,13 @@
import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
+import("${build_root}/config/android_abi.gni")
+import("${chip_root}/build/chip/java/rules.gni")
import("${chip_root}/build/chip/tools.gni")
-# Todo: copy from examples/tv-app/linux but later will be moved to jni and upto java workd
-source_set("android-tv-app") {
+shared_library("jni") {
+ output_name = "libTvApp"
+
sources = [
"${chip_root}/examples/tv-app/tv-common/include/CHIPProjectAppConfig.h",
"include/account-login/AccountLoginManager.cpp",
@@ -49,13 +52,55 @@ source_set("android-tv-app") {
"include/tv-channel/TvChannelManager.h",
"include/wake-on-lan/WakeOnLanManager.cpp",
"include/wake-on-lan/WakeOnLanManager.h",
+ "java/TVApp-JNI.cpp",
]
deps = [
"${chip_root}/examples/tv-app/tv-common",
+ "${chip_root}/src/app/server/java:jni",
"${chip_root}/src/lib",
"${chip_root}/third_party/inipp",
]
cflags = [ "-Wconversion" ]
+
+ output_dir = "${root_out_dir}/lib/jni/${android_abi}"
+
+ ldflags = [ "-Wl,--gc-sections" ]
+}
+
+android_library("java") {
+ output_name = "TvApp.jar"
+
+ deps = [
+ ":android",
+ "${chip_root}/third_party/android_deps:annotation",
+ ]
+
+ data_deps = [
+ ":jni",
+ "${chip_root}/build/chip/java:shared_cpplib",
+ ]
+
+ sources = [ "java/src/com/tcl/tvapp/TvApp.java" ]
+
+ javac_flags = [ "-Xlint:deprecation" ]
+
+ # 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"
+}
+
+group("default") {
+ deps = [
+ ":android",
+ ":java",
+ ":jni",
+ "${chip_root}/src/app/server/java",
+ "${chip_root}/src/platform/android:java",
+ "${chip_root}/src/setup_payload/java",
+ ]
}
diff --git a/examples/tv-app/android/args.gni b/examples/tv-app/android/args.gni
new file mode 100644
index 00000000000000..1c8eb57e4d1e09
--- /dev/null
+++ b/examples/tv-app/android/args.gni
@@ -0,0 +1,27 @@
+# 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.
+
+import("//build_overrides/chip.gni")
+
+import("${chip_root}/config/standalone/args.gni")
+
+chip_device_project_config_include = ""
+chip_project_config_include = ""
+chip_system_project_config_include = ""
+
+chip_project_config_include_dirs =
+ [ "${chip_root}/examples/tv-app/tv-common/include" ]
+chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ]
+
+chip_build_libshell = true
diff --git a/examples/tv-app/android/build_overrides b/examples/tv-app/android/build_overrides
new file mode 120000
index 00000000000000..e578e73312ebd1
--- /dev/null
+++ b/examples/tv-app/android/build_overrides
@@ -0,0 +1 @@
+../../build_overrides
\ No newline at end of file
diff --git a/examples/tv-app/android/java/TVApp-JNI.cpp b/examples/tv-app/android/java/TVApp-JNI.cpp
new file mode 100644
index 00000000000000..4f5d09b5445776
--- /dev/null
+++ b/examples/tv-app/android/java/TVApp-JNI.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * 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.
+ *
+ */
+
+/**
+ * @file
+ * Implementation of JNI bridge for Tv App on Android.
+ *
+ */
+#include
+#include
+#include
+#include
+
+jint JNI_OnLoad(JavaVM * jvm, void * reserved)
+{
+ return AndroidAppServerJNI_OnLoad(jvm, reserved);
+}
+
+void JNI_OnUnload(JavaVM * jvm, void * reserved)
+{
+ return AndroidAppServerJNI_OnUnload(jvm, reserved);
+}
diff --git a/examples/tv-app/android/java/src/com/tcl/tvapp/TvApp.java b/examples/tv-app/android/java/src/com/tcl/tvapp/TvApp.java
new file mode 100644
index 00000000000000..f4afa50734fcf4
--- /dev/null
+++ b/examples/tv-app/android/java/src/com/tcl/tvapp/TvApp.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * 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.
+ *
+ */
+package com.tcl.tvapp;
+
+public class TvApp {
+ public TvApp() {}
+
+ static {
+ System.loadLibrary("TvApp");
+ }
+}
diff --git a/examples/tv-app/android/third_party/connectedhomeip b/examples/tv-app/android/third_party/connectedhomeip
new file mode 120000
index 00000000000000..11a54ed360106c
--- /dev/null
+++ b/examples/tv-app/android/third_party/connectedhomeip
@@ -0,0 +1 @@
+../../../../
\ No newline at end of file
diff --git a/scripts/build/builders/android.py b/scripts/build/builders/android.py
index 68eabb29fc7b90..8619ebaf9a5eab 100644
--- a/scripts/build/builders/android.py
+++ b/scripts/build/builders/android.py
@@ -83,6 +83,12 @@ def AppGnArgs(self):
gn_args['chip_config_network_layer_ble'] = False
return gn_args
+ def ExampleName(self):
+ if self == AndroidApp.CHIP_TVServer:
+ return "tv-app"
+ else:
+ return None
+
class AndroidBuilder(Builder):
@@ -124,6 +130,92 @@ def validate_build_environment(self):
"'%s' is NOT writable by the current user (needed to accept licenses)"
% licenses)
+ def copyToSrcAndroid(self):
+ # 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
+
+ # We do NOT use python builtins for copy, so that the 'execution commands' are available
+ # when using dry run.
+ jnilibs_dir = os.path.join(
+ self.root, 'src/android/', self.app.AppName(), 'app/libs/jniLibs', self.board.AbiName())
+ libs_dir = os.path.join(
+ self.root, 'src/android/', self.app.AppName(), 'app/libs')
+ self._Execute(['mkdir', '-p', jnilibs_dir],
+ title='Prepare Native libs ' + self.identifier)
+
+ # TODO: Runtime dependencies should be computed by the build system rather than hardcoded
+ # GN supports getting these dependencies like:
+ # gn desc out/android-x64-chip_tool/ //src/controller/java runtime_deps
+ # gn desc out/android-x64-chip_tool/ //src/setup_payload/java runtime_deps
+ # However this assumes that the output folder has been populated, which will not be
+ # the case for `dry-run` executions. Hence this harcoding here.
+ #
+ # If we unify the JNI libraries, libc++_shared.so may not be needed anymore, which could
+ # be another path of resolving this inconsistency.
+ for libName in ['libSetupPayloadParser.so', 'libCHIPController.so', 'libc++_shared.so']:
+ 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',
+ 'AndroidPlatform.jar': 'src/platform/android/AndroidPlatform.jar',
+ }
+
+ for jarName in jars.keys():
+ self._Execute(['cp', os.path.join(
+ self.output_dir, 'lib', jars[jarName]), os.path.join(libs_dir, jarName)])
+
+ def copyToExampleAndroid(self):
+ jnilibs_dir = os.path.join(
+ self.root, 'examples', self.app.ExampleName(), 'android/App/app/libs/jniLibs', self.board.AbiName())
+ libs_dir = os.path.join(
+ self.root, 'examples', self.app.ExampleName(), 'android/App/app/libs')
+ self._Execute(['mkdir', '-p', jnilibs_dir],
+ title='Prepare Native libs ' + self.identifier)
+
+ for libName in ['libSetupPayloadParser.so', 'libc++_shared.so', 'libTvApp.so']:
+ self._Execute(['cp', os.path.join(self.output_dir, 'lib', 'jni', self.board.AbiName(
+ ), libName), os.path.join(jnilibs_dir, libName)])
+
+ jars = {
+ 'SetupPayloadParser.jar': 'third_party/connectedhomeip/src/setup_payload/java/SetupPayloadParser.jar',
+ 'AndroidPlatform.jar': 'third_party/connectedhomeip/src/platform/android/AndroidPlatform.jar',
+ 'CHIPAppServer.jar': 'third_party/connectedhomeip/src/app/server/java/CHIPAppServer.jar',
+ 'TvApp.jar': 'TvApp.jar',
+ }
+
+ for jarName in jars.keys():
+ self._Execute(['cp', os.path.join(
+ self.output_dir, 'lib', jars[jarName]), os.path.join(libs_dir, jarName)])
+
+ def gradlewBuildSrcAndroid(self):
+ # App compilation
+ self._Execute([
+ '%s/src/android/%s/gradlew' % (self.root,
+ self.app.AppName()), '-p',
+ '%s/src/android/%s' % (self.root,
+ self.app.AppName()),
+ '-PmatterBuildSrcDir=%s' % self.output_dir,
+ '-PmatterSdkSourceBuild=false',
+ '-PbuildDir=%s' % self.output_dir, 'assembleDebug'
+ ],
+ title='Building APP ' + self.identifier)
+
+ def gradlewBuildExampleAndroid(self):
+ # Example compilation
+ self._Execute([
+ '%s/examples/%s/android/App/gradlew' % (self.root,
+ self.app.ExampleName()), '-p',
+ '%s/examples/%s/android/App/' % (self.root,
+ self.app.ExampleName()),
+ '-PmatterBuildSrcDir=%s' % self.output_dir,
+ '-PmatterSdkSourceBuild=false',
+ '-PbuildDir=%s' % self.output_dir, 'assembleDebug'
+ ],
+ title='Building Example ' + self.identifier)
+
def generate(self):
self._Execute([
'python3', 'build/chip/java/tests/generate_jars_for_test.py'
@@ -159,6 +251,12 @@ def generate(self):
gn_gen = [
'gn', 'gen', '--check', '--fail-on-unused-args', self.output_dir, args,
]
+
+ exampleName = self.app.ExampleName()
+ if exampleName is not None:
+ gn_gen += ['--root=%s/examples/%s/android/' %
+ (self.root, exampleName)]
+
if self.board.IsIde():
gn_gen += ['--ide=json',
'--json-ide-script=//scripts/examples/gn_to_cmakelists.py']
@@ -202,57 +300,28 @@ def _build(self):
self._Execute(['ninja', '-C', self.output_dir],
title='Building JNI ' + self.identifier)
- # 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
-
- # We do NOT use python builtins for copy, so that the 'execution commands' are available
- # when using dry run.
- jnilibs_dir = os.path.join(
- self.root, 'src/android/', self.app.AppName(), 'app/libs/jniLibs', self.board.AbiName())
- libs_dir = os.path.join(
- self.root, 'src/android/', self.app.AppName(), 'app/libs')
- self._Execute(['mkdir', '-p', jnilibs_dir],
- title='Prepare Native libs ' + self.identifier)
-
- # TODO: Runtime dependencies should be computed by the build system rather than hardcoded
- # GN supports getting these dependencies like:
- # gn desc out/android-x64-chip_tool/ //src/controller/java runtime_deps
- # gn desc out/android-x64-chip_tool/ //src/setup_payload/java runtime_deps
- # However this assumes that the output folder has been populated, which will not be
- # the case for `dry-run` executions. Hence this harcoding here.
- #
- # If we unify the JNI libraries, libc++_shared.so may not be needed anymore, which could
- # be another path of resolving this inconsistency.
- for libName in ['libSetupPayloadParser.so', 'libCHIPController.so', 'libc++_shared.so', 'libCHIPAppServer.so']:
- 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',
- 'AndroidPlatform.jar': 'src/platform/android/AndroidPlatform.jar',
- 'CHIPAppServer.jar': 'src/app/server/java/CHIPAppServer.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/%s/gradlew' % (self.root,
- self.app.AppName()), '-p',
- '%s/src/android/%s' % (self.root,
- self.app.AppName()),
- '-PmatterBuildSrcDir=%s' % self.output_dir,
- '-PmatterSdkSourceBuild=false',
- '-PbuildDir=%s' % self.output_dir, 'assembleDebug'
- ],
- title='Building APP ' + self.identifier)
+ exampleName = self.app.ExampleName()
+ if exampleName is None:
+ self.copyToSrcAndroid()
+ self.gradlewBuildSrcAndroid()
+ else:
+ self.copyToExampleAndroid()
+ self.gradlewBuildExampleAndroid()
def build_outputs(self):
- if not self.board.IsIde():
+ if self.board.IsIde():
+ outputs = {
+ self.app.AppName() + '-debug.apk':
+ os.path.join(self.root, "src/android", self.app.AppName(),
+ 'app/build/outputs/apk/debug/app-debug.apk')
+ }
+ elif self.app.ExampleName() is not None:
+ outputs = {
+ 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.output_dir, 'outputs', 'apk', 'debug',
@@ -277,11 +346,5 @@ def build_outputs(self):
os.path.join(self.output_dir, 'lib', 'jni',
self.board.AbiName(), 'libc++_shared.so'),
}
- else:
- outputs = {
- self.app.AppName() + '-debug.apk':
- os.path.join(self.root, "src/android", self.app.AppName(),
- 'app/build/outputs/apk/debug/app-debug.apk')
- }
return outputs
diff --git a/scripts/build/testdata/build_all_except_host.txt b/scripts/build/testdata/build_all_except_host.txt
index 62857177faf18b..36c1866eda665b 100644
--- a/scripts/build/testdata/build_all_except_host.txt
+++ b/scripts/build/testdata/build_all_except_host.txt
@@ -95,7 +95,7 @@ python3 build/chip/java/tests/generate_jars_for_test.py
python3 third_party/android_deps/set_up_android_deps.py
# Generating android-arm64-chip-tvserver
-gn gen --check --fail-on-unused-args {out}/android-arm64-chip-tvserver '--args=target_os="android" target_cpu="arm64" android_ndk_root="TEST_ANDROID_NDK_HOME" android_sdk_root="TEST_ANDROID_HOME" chip_config_network_layer_ble=false '
+gn gen --check --fail-on-unused-args {out}/android-arm64-chip-tvserver '--args=target_os="android" target_cpu="arm64" android_ndk_root="TEST_ANDROID_NDK_HOME" android_sdk_root="TEST_ANDROID_HOME" chip_config_network_layer_ble=false ' --root={root}/examples/tv-app/android/
# Accepting NDK licenses @ tools
bash -c 'yes | TEST_ANDROID_HOME/tools/bin/sdkmanager --licenses >/dev/null'
@@ -462,16 +462,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/jni/armeabi-v7a/libCHIPAppServer.so {root}/src/android/CHIPTool/app/libs/jniLibs/armeabi-v7a/libCHIPAppServer.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
cp {out}/android-arm-chip-tool/lib/src/platform/android/AndroidPlatform.jar {root}/src/android/CHIPTool/app/libs/AndroidPlatform.jar
-cp {out}/android-arm-chip-tool/lib/src/app/server/java/CHIPAppServer.jar {root}/src/android/CHIPTool/app/libs/CHIPAppServer.jar
-
# Building APP android-arm-chip-tool
{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PmatterBuildSrcDir={out}/android-arm-chip-tool -PmatterSdkSourceBuild=false -PbuildDir={out}/android-arm-chip-tool assembleDebug
@@ -487,16 +483,12 @@ cp {out}/android-arm64-chip-test/lib/jni/arm64-v8a/libCHIPController.so {root}/s
cp {out}/android-arm64-chip-test/lib/jni/arm64-v8a/libc++_shared.so {root}/src/android/CHIPTest/app/libs/jniLibs/arm64-v8a/libc++_shared.so
-cp {out}/android-arm64-chip-test/lib/jni/arm64-v8a/libCHIPAppServer.so {root}/src/android/CHIPTest/app/libs/jniLibs/arm64-v8a/libCHIPAppServer.so
-
cp {out}/android-arm64-chip-test/lib/src/controller/java/CHIPController.jar {root}/src/android/CHIPTest/app/libs/CHIPController.jar
cp {out}/android-arm64-chip-test/lib/src/setup_payload/java/SetupPayloadParser.jar {root}/src/android/CHIPTest/app/libs/SetupPayloadParser.jar
cp {out}/android-arm64-chip-test/lib/src/platform/android/AndroidPlatform.jar {root}/src/android/CHIPTest/app/libs/AndroidPlatform.jar
-cp {out}/android-arm64-chip-test/lib/src/app/server/java/CHIPAppServer.jar {root}/src/android/CHIPTest/app/libs/CHIPAppServer.jar
-
# Building APP android-arm64-chip-test
{root}/src/android/CHIPTest/gradlew -p {root}/src/android/CHIPTest -PmatterBuildSrcDir={out}/android-arm64-chip-test -PmatterSdkSourceBuild=false -PbuildDir={out}/android-arm64-chip-test assembleDebug
@@ -512,16 +504,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/jni/arm64-v8a/libCHIPAppServer.so {root}/src/android/CHIPTool/app/libs/jniLibs/arm64-v8a/libCHIPAppServer.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
cp {out}/android-arm64-chip-tool/lib/src/platform/android/AndroidPlatform.jar {root}/src/android/CHIPTool/app/libs/AndroidPlatform.jar
-cp {out}/android-arm64-chip-tool/lib/src/app/server/java/CHIPAppServer.jar {root}/src/android/CHIPTool/app/libs/CHIPAppServer.jar
-
# Building APP android-arm64-chip-tool
{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PmatterBuildSrcDir={out}/android-arm64-chip-tool -PmatterSdkSourceBuild=false -PbuildDir={out}/android-arm64-chip-tool assembleDebug
@@ -529,26 +517,24 @@ cp {out}/android-arm64-chip-tool/lib/src/app/server/java/CHIPAppServer.jar {root
ninja -C {out}/android-arm64-chip-tvserver
# Prepare Native libs android-arm64-chip-tvserver
-mkdir -p {root}/src/android/CHIPTVServer/app/libs/jniLibs/arm64-v8a
+mkdir -p {root}/examples/tv-app/android/App/app/libs/jniLibs/arm64-v8a
-cp {out}/android-arm64-chip-tvserver/lib/jni/arm64-v8a/libSetupPayloadParser.so {root}/src/android/CHIPTVServer/app/libs/jniLibs/arm64-v8a/libSetupPayloadParser.so
+cp {out}/android-arm64-chip-tvserver/lib/jni/arm64-v8a/libSetupPayloadParser.so {root}/examples/tv-app/android/App/app/libs/jniLibs/arm64-v8a/libSetupPayloadParser.so
-cp {out}/android-arm64-chip-tvserver/lib/jni/arm64-v8a/libCHIPController.so {root}/src/android/CHIPTVServer/app/libs/jniLibs/arm64-v8a/libCHIPController.so
+cp {out}/android-arm64-chip-tvserver/lib/jni/arm64-v8a/libc++_shared.so {root}/examples/tv-app/android/App/app/libs/jniLibs/arm64-v8a/libc++_shared.so
-cp {out}/android-arm64-chip-tvserver/lib/jni/arm64-v8a/libc++_shared.so {root}/src/android/CHIPTVServer/app/libs/jniLibs/arm64-v8a/libc++_shared.so
+cp {out}/android-arm64-chip-tvserver/lib/jni/arm64-v8a/libTvApp.so {root}/examples/tv-app/android/App/app/libs/jniLibs/arm64-v8a/libTvApp.so
-cp {out}/android-arm64-chip-tvserver/lib/jni/arm64-v8a/libCHIPAppServer.so {root}/src/android/CHIPTVServer/app/libs/jniLibs/arm64-v8a/libCHIPAppServer.so
+cp {out}/android-arm64-chip-tvserver/lib/third_party/connectedhomeip/src/setup_payload/java/SetupPayloadParser.jar {root}/examples/tv-app/android/App/app/libs/SetupPayloadParser.jar
-cp {out}/android-arm64-chip-tvserver/lib/src/controller/java/CHIPController.jar {root}/src/android/CHIPTVServer/app/libs/CHIPController.jar
+cp {out}/android-arm64-chip-tvserver/lib/third_party/connectedhomeip/src/platform/android/AndroidPlatform.jar {root}/examples/tv-app/android/App/app/libs/AndroidPlatform.jar
-cp {out}/android-arm64-chip-tvserver/lib/src/setup_payload/java/SetupPayloadParser.jar {root}/src/android/CHIPTVServer/app/libs/SetupPayloadParser.jar
+cp {out}/android-arm64-chip-tvserver/lib/third_party/connectedhomeip/src/app/server/java/CHIPAppServer.jar {root}/examples/tv-app/android/App/app/libs/CHIPAppServer.jar
-cp {out}/android-arm64-chip-tvserver/lib/src/platform/android/AndroidPlatform.jar {root}/src/android/CHIPTVServer/app/libs/AndroidPlatform.jar
+cp {out}/android-arm64-chip-tvserver/lib/TvApp.jar {root}/examples/tv-app/android/App/app/libs/TvApp.jar
-cp {out}/android-arm64-chip-tvserver/lib/src/app/server/java/CHIPAppServer.jar {root}/src/android/CHIPTVServer/app/libs/CHIPAppServer.jar
-
-# Building APP android-arm64-chip-tvserver
-{root}/src/android/CHIPTVServer/gradlew -p {root}/src/android/CHIPTVServer -PmatterBuildSrcDir={out}/android-arm64-chip-tvserver -PmatterSdkSourceBuild=false -PbuildDir={out}/android-arm64-chip-tvserver assembleDebug
+# Building Example android-arm64-chip-tvserver
+{root}/examples/tv-app/android/App/gradlew -p {root}/examples/tv-app/android/App/ -PmatterBuildSrcDir={out}/android-arm64-chip-tvserver -PmatterSdkSourceBuild=false -PbuildDir={out}/android-arm64-chip-tvserver assembleDebug
# Building JNI android-x64-chip-tool
ninja -C {out}/android-x64-chip-tool
@@ -562,16 +548,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/jni/x86_64/libCHIPAppServer.so {root}/src/android/CHIPTool/app/libs/jniLibs/x86_64/libCHIPAppServer.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
cp {out}/android-x64-chip-tool/lib/src/platform/android/AndroidPlatform.jar {root}/src/android/CHIPTool/app/libs/AndroidPlatform.jar
-cp {out}/android-x64-chip-tool/lib/src/app/server/java/CHIPAppServer.jar {root}/src/android/CHIPTool/app/libs/CHIPAppServer.jar
-
# Building APP android-x64-chip-tool
{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PmatterBuildSrcDir={out}/android-x64-chip-tool -PmatterSdkSourceBuild=false -PbuildDir={out}/android-x64-chip-tool assembleDebug
@@ -587,16 +569,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/jni/x86/libCHIPAppServer.so {root}/src/android/CHIPTool/app/libs/jniLibs/x86/libCHIPAppServer.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
cp {out}/android-x86-chip-tool/lib/src/platform/android/AndroidPlatform.jar {root}/src/android/CHIPTool/app/libs/AndroidPlatform.jar
-cp {out}/android-x86-chip-tool/lib/src/app/server/java/CHIPAppServer.jar {root}/src/android/CHIPTool/app/libs/CHIPAppServer.jar
-
# Building APP android-x86-chip-tool
{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PmatterBuildSrcDir={out}/android-x86-chip-tool -PmatterSdkSourceBuild=false -PbuildDir={out}/android-x86-chip-tool assembleDebug
diff --git a/scripts/examples/gn_android_example.sh b/scripts/examples/gn_android_example.sh
new file mode 100755
index 00000000000000..cbf301ee06bb76
--- /dev/null
+++ b/scripts/examples/gn_android_example.sh
@@ -0,0 +1,81 @@
+#!/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
+
+# Build script for GN examples GitHub workflow.
+
+source "$(dirname "$0")/../../scripts/activate.sh"
+
+GN_ARGS=()
+
+EXAMPLE_DIR=$1
+shift
+OUTPUT_DIR=$1
+shift
+
+NINJA_ARGS=()
+for arg; do
+ case $arg in
+ -v)
+ NINJA_ARGS+=(-v)
+ ;;
+ *=*)
+ GN_ARGS+=("$arg")
+ ;;
+ *import*)
+ GN_ARGS+=("$arg")
+ ;;
+ *)
+ echo >&2 "invalid argument: $arg"
+ exit 2
+ ;;
+ esac
+done
+
+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
+
+# Set up JARs
+python3 "$(dirname "$0")"/../../build/chip/java/tests/generate_jars_for_test.py
+python3 "$(dirname "$0")"/../../third_party/android_deps/set_up_android_deps.py
+
+gn gen --check --fail-on-unused-args --root="$EXAMPLE_DIR" "$OUTPUT_DIR" --args="target_os=\"android\" target_cpu=\"$TARGET_CPU\" android_ndk_root=\"$ANDROID_NDK_HOME\" android_sdk_root=\"$ANDROID_HOME\" ${GN_ARGS[*]}"
+
+ninja -C "$OUTPUT_DIR" "${NINJA_ARGS[@]}"
+
+cp -rf "$OUTPUT_DIR/lib/jni/" "$EXAMPLE_DIR/App/app/libs/jniLibs/"
+cp -f "$OUTPUT_DIR/lib/third_party/connectedhomeip/src/platform/android/AndroidPlatform.jar" "$EXAMPLE_DIR/App/app/libs/"
+cp -f "$OUTPUT_DIR/lib/third_party/connectedhomeip/src/app/server/java/CHIPAppServer.jar" "$EXAMPLE_DIR/App/app/libs/"
+cp -f "$OUTPUT_DIR/lib/third_party/connectedhomeip/src/setup_payload/java/SetupPayloadParser.jar" "$EXAMPLE_DIR/App/app/libs/"
+cp -f "$OUTPUT_DIR/lib/TvApp.jar" "$EXAMPLE_DIR/App/app/libs/"
diff --git a/src/android/CHIPTVServer/.idea/runConfigurations.xml b/src/android/CHIPTVServer/.idea/runConfigurations.xml
deleted file mode 100644
index 797acea53eb091..00000000000000
--- a/src/android/CHIPTVServer/.idea/runConfigurations.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/app/server/java/AppMain.cpp b/src/app/server/java/AndroidAppServerWrapper.cpp
similarity index 98%
rename from src/app/server/java/AppMain.cpp
rename to src/app/server/java/AndroidAppServerWrapper.cpp
index 3a34c10cede618..f32c9bdd25c393 100644
--- a/src/app/server/java/AppMain.cpp
+++ b/src/app/server/java/AndroidAppServerWrapper.cpp
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-#include "AppMain.h"
+#include "AndroidAppServerWrapper.h"
#include
#include
#include
diff --git a/src/app/server/java/AppMain.h b/src/app/server/java/AndroidAppServerWrapper.h
similarity index 83%
rename from src/app/server/java/AppMain.h
rename to src/app/server/java/AndroidAppServerWrapper.h
index ae544754e2bdb3..c128328564920c 100644
--- a/src/app/server/java/AppMain.h
+++ b/src/app/server/java/AndroidAppServerWrapper.h
@@ -17,6 +17,11 @@
*/
#pragma once
+#include
#include
CHIP_ERROR ChipAndroidAppInit(void);
+
+jint AndroidAppServerJNI_OnLoad(JavaVM * jvm, void * reserved);
+
+void AndroidAppServerJNI_OnUnload(JavaVM * jvm, void * reserved);
diff --git a/src/app/server/java/BUILD.gn b/src/app/server/java/BUILD.gn
index d4170c2f6f1d93..dd40c94eaf1862 100644
--- a/src/app/server/java/BUILD.gn
+++ b/src/app/server/java/BUILD.gn
@@ -20,18 +20,16 @@ import("${chip_root}/build/chip/java/rules.gni")
import("${chip_root}/src/app/common_flags.gni")
import("${chip_root}/src/lib/lib.gni")
-shared_library("jni") {
- output_name = "libCHIPAppServer"
+static_library("jni") {
+ output_name = "libCHIPAppServerJni"
sources = [
- "AppMain.cpp",
- "AppMain.h",
+ "AndroidAppServerWrapper.cpp",
+ "AndroidAppServerWrapper.h",
"CHIPAppServer-JNI.cpp",
]
deps = [
- "${chip_root}/examples/tv-app/android:android-tv-app",
- "${chip_root}/examples/tv-app/tv-common",
"${chip_root}/src/app/server",
"${chip_root}/src/inet",
"${chip_root}/src/lib",
@@ -41,10 +39,6 @@ shared_library("jni") {
]
public_configs = [ "${chip_root}/src:includes" ]
-
- output_dir = "${root_out_dir}/lib/jni/${android_abi}"
-
- ldflags = [ "-Wl,--gc-sections" ]
}
android_library("java") {
diff --git a/src/app/server/java/CHIPAppServer-JNI.cpp b/src/app/server/java/CHIPAppServer-JNI.cpp
index 777a4755794ea8..57301485269b8d 100644
--- a/src/app/server/java/CHIPAppServer-JNI.cpp
+++ b/src/app/server/java/CHIPAppServer-JNI.cpp
@@ -21,7 +21,7 @@
* Implementation of JNI bridge for CHIP App Server for Android TV apps
*
*/
-#include "AppMain.h"
+#include "AndroidAppServerWrapper.h"
#include
#include
#include
@@ -53,7 +53,7 @@ pthread_t sIOThread = PTHREAD_NULL;
jclass sChipAppServerExceptionCls = NULL;
} // namespace
-jint JNI_OnLoad(JavaVM * jvm, void * reserved)
+jint AndroidAppServerJNI_OnLoad(JavaVM * jvm, void * reserved)
{
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env;
@@ -91,7 +91,7 @@ jint JNI_OnLoad(JavaVM * jvm, void * reserved)
return (err == CHIP_NO_ERROR) ? JNI_VERSION_1_6 : JNI_ERR;
}
-void JNI_OnUnload(JavaVM * jvm, void * reserved)
+void AndroidAppServerJNI_OnUnload(JavaVM * jvm, void * reserved)
{
chip::DeviceLayer::StackLock lock;
ChipLogProgress(AppServer, "JNI_OnUnload() called");
diff --git a/src/app/server/java/src/chip/appserver/ChipAppServer.java b/src/app/server/java/src/chip/appserver/ChipAppServer.java
index 6d9bb3a884bddb..79a8d5eb23751c 100644
--- a/src/app/server/java/src/chip/appserver/ChipAppServer.java
+++ b/src/app/server/java/src/chip/appserver/ChipAppServer.java
@@ -21,9 +21,5 @@
public class ChipAppServer {
private static final String TAG = ChipAppServer.class.getSimpleName();
- static {
- System.loadLibrary("CHIPAppServer");
- }
-
public native boolean startApp();
}
diff --git a/src/setup_payload/java/BUILD.gn b/src/setup_payload/java/BUILD.gn
index ae8d01118e2cc6..f2b922a2a34b2d 100644
--- a/src/setup_payload/java/BUILD.gn
+++ b/src/setup_payload/java/BUILD.gn
@@ -24,8 +24,8 @@ shared_library("jni") {
sources = [ "SetupPayloadParser-JNI.cpp" ]
deps = [
- "//src/lib",
- "//src/setup_payload",
+ "${chip_root}/src/lib",
+ "${chip_root}/src/setup_payload",
]
output_dir = "${root_out_dir}/lib/jni/${android_abi}"