Skip to content

Commit 75aad11

Browse files
committed
APL-VH-Android: December 2022 Release of APL 2022.2.2 compliant Viewhost Code
1 parent bcb4462 commit 75aad11

File tree

573 files changed

+9777
-19316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

573 files changed

+9777
-19316
lines changed

README.md

Lines changed: 39 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,61 @@
1-
#README: APL Android
1+
# Alexa Presentation Language (APL) ViewHost Android version 2022.2
22

3-
The APL Android target contains 3 modules
3+
APLViewHostAndroid is a view host implementation for the Android Platform. It consists of
4+
a thin JNI layer that interacts with APL Core Engine for component inflation and command
5+
handling, and a native Android layout that maps APL Components to Android Views and ViewGroups.
46

5-
- APL jni adapter: 'libaplcore-jni.so' allows in process communication between the
6-
core C++ and Java Android layers.
7+
The APL Android Viewhost consists of two elements:
78

8-
- APL Android Library: .aar library exposing functionality of the APL spec, for use by Android
9-
applications. This library embeds the core and jni libraries. The aar build targets SDK 28 and
10-
supports a minimum SDK 22, it has 4 flavors:
11-
12-
- apl-core-release.aar - The release library
13-
- apl-demo-release.aar - The release library with sample APL layout assets included.
14-
- apl-core-debug.aar - The debug library
15-
- apl-demo-debug.aar - The debug library with sample APL layout assets included.
9+
- APL JNI adapter: 'libaplcore-jni.so' allows in process communication between the
10+
core C++ and Java Android layers.
1611

17-
- APL Android Sample App: A simple sample application that uses the demo library sample assets.
12+
- APL Android Library: .aar library exposing functionality of the APL spec, for use by Android
13+
applications. This library embeds the Core and JNI libraries. The aar build targets SDK 28 and
14+
supports a minimum SDK 22, it has 2 flavors:
1815

19-
The Android library and Sample application are built with gradle. The Gradle cmake integration plugin
20-
will build the the APL core library and core jni dependencies.
16+
- apl-release.aar - The release library
17+
- apl-debug.aar - The debug library
2118

19+
The Android library is built with Gradle. The Gradle CMake integration plugin
20+
will build the APL Core Library and Core JNI dependencies.
2221

2322
### Prerequisites
2423

25-
- [Install NDK](https://developer.android.com/ndk/guides/#download-ndk) version 20
26-
- Higher versions of NDK are not currently compatible with the current gradle plugin.
27-
- [Install Android SDK](https://developer.android.com/studio/intro/update) version 28 or higher
28-
- Install Ninja (Needed for APLCoreEngine when building from APLViewhostAndroid)
29-
- Setup a workspace with the APL Android, and (optionally) APL Core code
30-
```bash
31-
$ ls
32-
APLCoreEngine
33-
APLViewhostAndroid
34-
```
35-
> The APL Core code is required for building the APL Android project. The Gradle build
36-
> assumes it is in a sibling folder to the APLAndroidViewhost project. If the APL Core
37-
> code is located elsewhere gradle commands must be augmented with `-PaplCoreDir=<path.to.core>`
38-
> or set the value in the `gradle.properties` file.
39-
40-
## Android Studio
24+
Make sure you have installed:
4125

42-
The APL Android sample application is used to test and demo the APL Android functionality. It has a fixed
43-
build dependency on apl-demo-debug.aar . The sample app targets Android SDK 28 and can be run with
44-
an emulator for desktop display and projection.
26+
- [Android SDK](https://developer.android.com/studio/intro/update) version 28 or higher
27+
- [Android NDK](https://developer.android.com/ndk/guides/#download-ndk) version 22 or higher
28+
- APL Core build dependencies (e.g. one of supported C++ compilers, CMake)
29+
- Ninja (Needed for APLCoreEngine when building from APLViewhostAndroid)
4530

46-
To run the project in Android Studio:
31+
Setup a directory with the APL Android and APL Core - https://github.com/alexa/apl-core-library
4732

48-
- Launch the latest Android Studio (3.3.0+)
49-
- Import the gradle project located at <workspace>/APLAndroidViewhost/
50-
- You will see Android Studio Modules for "apl" and "app"
51-
- Open file app/com/amazon/apl/examples/AplSampleActivity and select your preferred demo data, or add your own
52-
- Run AplSampleActivity
53-
54-
> To debug the project configure Android Studio to find the debug symbols.
55-
> "Run"->"Edit Configuration"->"Debugger"->"Symbol Directories" add the APL
56-
> Android target root directory <workspace>/APLViewhostAndroid
57-
58-
## Building the APL Core for the Android APL Library
59-
60-
The APL Core library is a required dependency of the Android Viewhost and must be built using the CMAKE defines for Android.
61-
62-
To compile 'libaplcore.a' and 'libaplcore-jni.so' for armeabi-v7a devices, do the following, from the APL Core Library project:
63-
```
64-
$ mkdir build
65-
$ cd build
66-
$ cmake -DANDROID_ABI="armeabi-v7a" -DANDROID_PLATFORM=android-28 -DCMAKE_TOOLCHAIN_FILE=$NDK_HOME/build/cmake/android.toolchain.cmake -DAPL_JNI=ON ..
67-
$ make -j4
33+
```bash
34+
$ ls
35+
apl-core-library
36+
apl-viewhost-android
6837
```
69-
For other architectures, the ANDROID_ABI flag should be set appropriately:
70-
for example, -DANDROID_ABI="x86" for an x86 build
38+
The APL Core code is required for building the APL Android project. The Gradle build
39+
assumes it is in a sibling folder to the `apl-viewhost-android` project. If the APL Core
40+
code is located elsewhere, Gradle commands must be augmented with `-PaplCoreDir=<path.to.core>`
41+
or you can set the value in the `gradle.properties` file.
7142

7243
## Building the Android APL Library
7344

45+
Set the Android SDK root environment variable:
7446

75-
To build the Android APL library and the Sample application:
7647
```bash
77-
$ ./gradlew build
48+
$ export ANDROID_SDK_ROOT=/Users/YOUR-LOGIN-HERE/Library/Android/sdk/
7849
```
79-
To install the `APL Sample App` connect your device or emulator:
50+
51+
Build the Android APL library:
8052
```bash
81-
$ ./gradlew app:installDebug
53+
$ ./gradlew build
8254
```
83-
To see a full list of gradle tasks:
55+
56+
This step will also build the APL Core Library as a dependency.
57+
58+
To see a full list of Gradle tasks:
8459
```bash
8560
$ ./gradlew tasks
8661
```
@@ -89,23 +64,7 @@ To see a full list of gradle tasks:
8964

9065
### CMake Error
9166
```
92-
CMake Error at /Volumes/workplace/APLAndroid/src/APLCoreEngine/thirdparty/thirdparty.cmake:120 (message):
67+
CMake Error at ...APLCoreEngine/thirdparty/thirdparty.cmake:120 (message):
9368
CMake step for googletest failed: 1
9469
```
95-
The `ninja` build tool needs to be available on the `PATH`.
96-
97-
### Gradle Error
98-
```
99-
> Could not get unknown property 'externalNativeBuildCoreDebug' for project ':apl' of type org.gradle.api.Project.
100-
```
101-
102-
The current android gradle version (3.3.0) requires a NDK install that includes a `platforms` folder.
103-
Starting with NDK 22.x, the `platforms` folder no longer exists. Additionally,
104-
the default ndk location for 3.3.0 is `$ANDROID_SDK_HOME/ndk-bundle`, but the current version of
105-
Android Studio (4.1.2) is no longer capable of installing the NDK to that location.
106-
107-
To work around this error (on a mac), you should download a compatible ndk version (< 22.x) and then
108-
symbolic link it to the `ndk-bundle` folder:
109-
```
110-
ln -s /Users/$USER/Library/Android/sdk/ndk/20.0.5594570/ /Users/$USER/Library/Android/sdk/ndk-bundle
111-
```
70+
The `ninja` build tool needs to be available on the `PATH`.

apl/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ add_custom_target(generate-android-enums ALL
213213
${APL_CORE_DIR}/aplcore/include/apl/touch/*.h
214214
${APL_CORE_DIR}/aplcore/include/apl/focus/*.h
215215
DEPENDS enumgen
216-
)
216+
)
217217

218218
add_dependencies(apl-jni generate-android-enums)
219219

@@ -222,4 +222,4 @@ find_program(CCACHE_FOUND ccache)
222222
if(CCACHE_FOUND)
223223
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
224224
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
225-
endif(CCACHE_FOUND)
225+
endif(CCACHE_FOUND)

apl/build.gradle

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['test']) {
2626
classDirectories.from(files(debugTree))
2727

2828
executionData.from(fileTree(dir: "$buildDir", includes: [
29-
"jacoco/*.exec"
29+
"jacoco/*.exec",
30+
"outputs/code_coverage/debugAndroidTest/connected/*coverage.ec"
3031
]))
3132
reports {
3233
xml.enabled = true
@@ -35,7 +36,7 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['test']) {
3536
}
3637

3738
ext {
38-
aplAndroidCmakeArgs = " -DCMAKE_VERBOSE_MAKEFILE=ON"
39+
aplAndroidCmakeArgs = "-DCMAKE_VERBOSE_MAKEFILE=ON"
3940
aplCoreDirCmakeArg = "-DAPL_CORE_DIR=" + projectDir + "/../../apl-core-library"
4041
if (project.hasProperty('aplCoreDir')) {
4142
aplCoreDirCmakeArg = "-DAPL_CORE_DIR=" + aplCoreDir
@@ -57,8 +58,7 @@ android {
5758
externalNativeBuild {
5859
cmake {
5960
// Sets optional flags for the C++ compiler.
60-
// Enables RTTI (RunTime Type Information) support and C++ exceptions.
61-
cppFlags "-std=c++11", "-frtti", "-fexceptions", "-DBUILD_ALEXAEXTENSIONS=On", "-DALEXAEXTENSIONS=1"
61+
cppFlags "-std=c++11", "-fno-rtti", "-fno-exceptions"
6262
// Build the APL Core JNI library (excludes all other targets)
6363
targets "apl", "apl-jni"
6464
// Enable APL Core JNI build, and be verbose.
@@ -76,13 +76,15 @@ android {
7676
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
7777
buildConfigField("long", "VERSION_CODE", "${defaultConfig.versionCode}")
7878
buildConfigField("String","VERSION_NAME","\"${defaultConfig.versionName}-core\"")
79+
buildConfigField 'boolean', 'DEBUG_LOGGING', 'false'
7980
}
8081
debug {
8182
testCoverageEnabled true
8283
debuggable true
8384
aplAndroidCmakeArgs += " -DDEBUG_MEMORY_USE=ON"
8485
buildConfigField("long", "VERSION_CODE", "${defaultConfig.versionCode}")
8586
buildConfigField("String","VERSION_NAME","\"${defaultConfig.versionName}-core\"")
87+
buildConfigField 'boolean', 'DEBUG_LOGGING', 'true'
8688
}
8789
}
8890
// Temporary fix until alpha10 - "More than one file was found with OS independent path 'META-INF/proguard/androidx-annotations.pro"
@@ -92,7 +94,7 @@ android {
9294

9395
externalNativeBuild {
9496
cmake {
95-
version "3.10.2"
97+
version "3.18.1"
9698

9799
// Tells Gradle to find the root CMake APL build script. path is relative to
98100
// the directory containing the module's build.gradle file. Gradle requires this
@@ -112,47 +114,63 @@ android {
112114
fatal 'StopShip'
113115
disable 'LongLogTag'
114116
}
115-
116117
testOptions {
117118
animationsDisabled true
118119

119120
unitTests {
120121
includeAndroidResources = true
121122
}
123+
unitTests.all {
124+
systemProperty "java.library.path", String.join(":",
125+
"""${projectDir.absolutePath}/.cxx/cmake/debug/host/""",
126+
"""${projectDir.absolutePath}/../discovery/.cxx/cmake/debug/host/""",
127+
"""${projectDir.absolutePath}/../common/.cxx/cmake/debug/host/"""
128+
)
129+
}
122130
}
123131
}
124132

125133
dependencies {
126134
compileOnly 'org.projectlombok:lombok:1.18.12'
127135
implementation fileTree(include: ['*.jar'], dir: 'libs')
128-
implementation 'androidx.annotation:annotation:1.0.0'
136+
implementation 'androidx.annotation:annotation:1.4.0'
129137
implementation 'androidx.core:core:1.0.0'
130138
implementation 'androidx.appcompat:appcompat:1.2.0'
131139
implementation 'com.github.bumptech.glide:glide:4.6.1'
132140
implementation project(':common')
133141
implementation (project(':discovery')) { transitive = false }
134-
testImplementation 'junit:junit:4.12'
135-
testImplementation 'org.robolectric:robolectric:4.2'
142+
testImplementation 'junit:junit:4.13.2'
143+
testImplementation 'org.robolectric:robolectric:4.8.1'
136144
testImplementation 'org.robolectric:shadows-httpclient:4.2'
137-
testImplementation 'androidx.test:core:1.1.0'
138-
testImplementation 'org.mockito:mockito-core:2.25.0'
139-
androidTestImplementation 'org.mockito:mockito-core:2.25.0'
140-
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
141-
androidTestImplementation 'androidx.annotation:annotation:1.0.0'
142-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
143-
androidTestImplementation 'androidx.test:runner:1.1.1'
144-
androidTestImplementation 'androidx.test:rules:1.1.1'
145+
testImplementation 'androidx.test:core:1.4.0'
146+
testImplementation 'androidx.test.ext:junit:1.1.3'
147+
testImplementation 'org.mockito:mockito-core:4.7.0'
148+
testImplementation 'androidx.test:rules:1.4.0'
149+
androidTestImplementation 'org.mockito:mockito-core:3.12.4'
150+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
151+
androidTestImplementation 'androidx.test:core:1.4.0'
152+
androidTestImplementation 'androidx.annotation:annotation:1.4.0'
153+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
154+
androidTestImplementation 'androidx.test:runner:1.4.0'
155+
androidTestImplementation 'androidx.test:rules:1.4.0'
145156
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
146157
androidTestImplementation 'com.linkedin.dexmaker:dexmaker:2.25.0'
147158
androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito:2.25.0'
148159
androidTestImplementation project(":commonTest")
160+
androidTestImplementation 'com.squareup.leakcanary:leakcanary-android-instrumentation:2.9.1'
161+
androidTestImplementation 'com.squareup.leakcanary:leakcanary-object-watcher-android:2.9.1'
149162
androidTestUtil 'androidx.test:orchestrator:1.1.1'
150163
api "com.google.auto.value:auto-value-annotations:1.7"
151164
api 'com.google.guava:guava:27.0.1-jre'
152165
annotationProcessor "com.google.auto.value:auto-value:1.7"
153166
annotationProcessor 'org.projectlombok:lombok:1.18.12'
154167
}
155168

169+
task buildHostJNI(type: com.amazon.apl.android.CMakeTask) {
170+
cmakeArgs aplCoreDirCmakeArg, aplAndroidCmakeArgs
171+
makeTargets 'apl-jni'
172+
}
173+
156174
project.afterEvaluate {
157175
// Dump configuration settings
158176
println "APL CMake Args: " + aplAndroidCmakeArgs
@@ -164,7 +182,18 @@ project.afterEvaluate {
164182
compileDebugJavaWithJavac.dependsOn externalNativeBuildDebug
165183
compileReleaseJavaWithJavac.dependsOn externalNativeBuildRelease
166184

185+
javaPreCompileDebug.dependsOn externalNativeBuildDebug
186+
187+
// We need to make sure the host jni library is built before any debug or release unit testing.
188+
tasks.preDebugUnitTestBuild.dependsOn(buildHostJNI)
189+
tasks.preReleaseUnitTestBuild.dependsOn(buildHostJNI)
190+
tasks.preDebugUnitTestBuild.dependsOn(':discovery:buildHostJNI')
191+
tasks.preReleaseUnitTestBuild.dependsOn(':discovery:buildHostJNI')
192+
tasks.preDebugUnitTestBuild.dependsOn(':common:buildHostJNI')
193+
tasks.preReleaseUnitTestBuild.dependsOn(':common:buildHostJNI')
194+
167195
tasks.test.finalizedBy(jacocoTestReport)
168196
}
169197

198+
170199
tasks.build.dependsOn(assembleAndroidTest)

apl/src/androidTest/java/com/amazon/apl/android/APLTestDocs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public final class APLTestDocs {
1414
// can have optional template properties.
1515
public final static String COMPONENT_BASE_DOC = "{" +
1616
" \"type\": \"APL\"," +
17-
" \"version\": \"1.0\"," +
17+
" \"version\": \"%s\"," +
1818
" \"onConfigChange\": [\n" +
1919
" {\n" +
2020
" \"type\": \"SendEvent\",\n" +

apl/src/androidTest/java/com/amazon/apl/android/APLViewhostTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
package com.amazon.apl.android;
77

8-
public class APLViewhostTest {
8+
import com.amazon.common.test.LeakRulesBaseClass;
9+
10+
public class APLViewhostTest extends LeakRulesBaseClass {
911
// Load the APL library.
1012
static {
1113
System.loadLibrary("common-jni");

0 commit comments

Comments
 (0)