Skip to content

Commit

Permalink
APL-VH-Android: March 2024 Release of APL 2024.1 compliant Viewhost Code
Browse files Browse the repository at this point in the history
  • Loading branch information
amzn-abhinvs committed Mar 12, 2024
1 parent c41ebf3 commit 083314b
Show file tree
Hide file tree
Showing 271 changed files with 12,347 additions and 1,775 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ build
.idea/
.vscode
.DS_Store
apl/.cxx/
**/.cxx/
jacoco.exec
# Project-specific cache directory generated by Gradle
/.gradle/
# Generated by run-gradlew
gradle/wrapper/gradle-wrapper.properties
97 changes: 55 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,58 @@
# Alexa Presentation Language (APL) ViewHost Android version 2023.3
# Alexa Presentation Language (APL) ViewHost Android version 2024.1

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

The APL Android Viewhost consists of two elements:

- APL JNI adapter: 'libaplcore-jni.so' allows in process communication between the
- APL jni adapter: 'libaplcore-jni.so' allows in process communication between the
core C++ and Java Android layers.

- APL Android Library: .aar library exposing functionality of the APL spec, for use by Android
applications. This library embeds the Core and JNI libraries. The aar build targets SDK 28 and
supports a minimum SDK 22, it has 2 flavors:

- apl-release.aar - The release library
- apl-debug.aar - The debug library

The Android library is built with Gradle. The Gradle CMake integration plugin
will build the APL Core Library and Core JNI dependencies.
- APL Android Library: .aar library exposing functionality of the APL spec, for use by Android
applications. This library embeds the core and jni libraries. The aar build targets SDK 34 and
supports a minimum SDK 22, it has 5 flavors:

- apl-core-release.aar - The release library
- apl-demo-release.aar - The release library with sample APL layout assets included.
- aplMinSized-release.aar - The release library with size optimizations to minimize download size.
- apl-core-debug.aar - The debug library
- apl-demo-debug.aar - The debug library with sample APL layout assets included.

The Android library is built with gradle. The Gradle cmake integration plugin
will build the APL core library and core jni dependencies.

The library ships with a discovery module which adds the extension discovery functionality. The
discovery library has following flavors and should be only used with its compatible flavor of
apl library, when needed:

- discovery-standard-debug.aar should be used with apl-core-debug.aar
- discovery-standard-release.aar should be used with apl-core-release.aar
- discovery-standardMinsized-release.aar should be used with apl-core-release.aar
- discovery-serviceV2-debug.aar should be used with apl-core-debug.aar
- discovery-serviceV2ls --release.aar should be used with apl-core-release.aar

### Prerequisites

Make sure you have installed:

- [Android SDK](https://developer.android.com/studio/intro/update) version 28 or higher
- [Android NDK](https://developer.android.com/ndk/guides/#download-ndk) version 22 or higher
- APL Core build dependencies (e.g. one of supported C++ compilers, CMake)
- Ninja (Needed for APLCoreEngine when building from APLViewhostAndroid)

Setup a directory with the APL Android and APL Core - https://github.com/alexa/apl-core-library

- [Install NDK](https://developer.android.com/ndk/guides/#download-ndk) version 23.0.7599858
- [Install Android SDK](https://developer.android.com/studio/intro/update) version 34 or higher
- Install Ninja (Needed for APLCoreEngine when building from APLViewhostAndroid)
- Java 17 (https://adoptium.net/ is recommended)
- Setup a directory with the APL Android and APL Core - https://github.com/alexa/apl-core-library
```bash
$ ls
apl-core-library
apl-viewhost-android
APLCoreEngine
APLViewhostAndroid
```
The APL Core code is required for building the APL Android project. The Gradle build
assumes it is in a sibling folder to the `apl-viewhost-android` project. If the APL Core
code is located elsewhere, Gradle commands must be augmented with `-PaplCoreDir=<path.to.core>`
or you can set the value in the `gradle.properties` file.
> The APL Core code is required for building the APL Android project. The Gradle build
> assumes it is in a sibling folder to the APLAndroidViewhost project. If the APL Core
> code is located elsewhere gradle commands must be augmented with `-PaplCoreDir=<path.to.core>`
> or set the value in the `gradle.properties` file.
## Building the Android APL Library

Set the Android SDK root environment variable:

```bash
$ export ANDROID_SDK_ROOT=/Users/YOUR-LOGIN-HERE/Library/Android/sdk/
```

Build the Android APL library:
To build the Android APL library:
```bash
$ ./gradlew build
```

This step will also build the APL Core Library as a dependency.

To see a full list of Gradle tasks:
To see a full list of gradle tasks:
```bash
$ ./gradlew tasks
```
Expand All @@ -67,4 +64,20 @@ To see a full list of Gradle tasks:
CMake Error at ...APLCoreEngine/thirdparty/thirdparty.cmake:120 (message):
CMake step for googletest failed: 1
```
The `ninja` build tool needs to be available on the `PATH`.
The `ninja` build tool needs to be available on the `PATH`.

### Gradle Error: Lombok

When building _outside_ of Android Studio using `gradlew`, you may get a fatal error from Lombok:
```
> java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x1b65ad4c) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module @0x1b65ad4c
```

This may occur because the Lombok library version must be compatible with the
Java compiler. Android Studio uses an internal verson of Java, so the Lombok
library supplied with APLViewhostAndroid is compatible with that Java.
Building from the command line gives you whichever version of Java is in your
path, which you can see with `echo $JAVA_HOME`. If your version of Java is
too new (or too old), the view host will not compile.

We recommend the Temurin 17 JDK.
84 changes: 84 additions & 0 deletions alexaextjni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.
include(FetchContent OPTIONAL RESULT_VARIABLE HAS_FETCH_CONTENT)

cmake_minimum_required(VERSION 3.18.1)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(ENABLE_PIC ON)
project (alexaextjni VERSION 1.0.0 LANGUAGES C CXX)


# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
alexaextjni
# Sets the library as a static library.
STATIC
src/main/cpp/jniextensionexecutor.cpp
src/main/cpp/jniextensionproxy.cpp
src/main/cpp/jniextensionregistrar.cpp
src/main/cpp/jniextensionresource.cpp)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

if (NOT ANDROID)
# Ensure jni.h is found
find_package(JNI REQUIRED)
include_directories(${JAVA_INCLUDE_PATH})
include_directories(${JAVA_INCLUDE_PATH2})

add_library(alexaext STATIC IMPORTED)
set_target_properties(alexaext
PROPERTIES
IMPORTED_LOCATION
"${CMAKE_CURRENT_SOURCE_DIR}/../coreengine/.cxx/cmake/debug/host/_deps/aplcore-build/extensions/alexaext/libalexaext.a"
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/../coreengine/src/main/cpp/alexaext/include"
)

add_library(rapidjson INTERFACE)
target_include_directories(rapidjson INTERFACE
# When we're building against RapidJSON, just use the include directory we discovered above
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../coreengine/src/main/cpp/rapidjson/include>
)

target_link_libraries(alexaextjni rapidjson alexaext)
else()
find_library( # Sets the name of the path variable.
log-lib

# Specifies the name of the NDK library that
# you want CMake to locate.
log)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
alexaextjni

# Links the target library to the log library
# included in the NDK.
${log-lib})

find_package(coreengine REQUIRED CONFIG)
target_link_libraries(alexaextjni coreengine::alexaext coreengine::rapidjson)
endif()

# Specifies a path to native header files.
include_directories(src/main/cpp/include)

# Common lib includes
include_directories(../common/src/main/cpp/include)
95 changes: 95 additions & 0 deletions alexaextjni/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.library'

ext {
cmakeProjectPath = projectDir.absolutePath
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
cmakeProjectPath = cmakeProjectPath.replace('\\', '/')
}
aplAndroidCmakeArgs = "-DCMAKE_VERBOSE_MAKEFILE=ON"
}

android {
namespace 'com.amazon.alexa.android.extension.alexaextjni'
compileSdk 34
buildToolsVersion = "33.0.0"
ndkVersion "23.0.7599858"

defaultConfig {
minSdkVersion 22
versionCode 1
versionName "1.0"
targetSdkVersion 34

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'

externalNativeBuild {
cmake {
// Sets optional flags for the C++ compiler.
cppFlags "-std=c++11", "-fno-rtti", "-fno-exceptions"
// Build the APL Core JNI library (excludes all other targets)
targets "alexaextjni"
// Enable APL Core JNI build, and be verbose.
arguments aplAndroidCmakeArgs
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

externalNativeBuild {
cmake {
version "3.18.1"
path "CMakeLists.txt"
}
}

buildFeatures {
prefab true
prefabPublishing true
}
prefab {
alexaextjni {
headers "src/main/cpp/include"
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":common")
implementation project(':coreengine')
}

task buildHostJNI(type: com.amazon.apl.android.CMakeTask) {
cmakeArgs aplAndroidCmakeArgs
makeTargets "alexaextjni"
dependsOn ':coreengine:buildHostJNI'
}

project.afterEvaluate {
// Dump configuration settings
println "APL CMake Args: " + aplAndroidCmakeArgs
println "Android SDK Directory: " + android.sdkDirectory.path
println "Android NDK Directory: " + android.ndkDirectory.path

// We need to make sure the host jni library is built before any debug or release unit testing.
tasks.preDebugUnitTestBuild.dependsOn(buildHostJNI)
tasks.preReleaseUnitTestBuild.dependsOn(buildHostJNI)
tasks.buildHostJNI.dependsOn(':coreengine:buildHostJNI')
tasks.buildHostJNI.dependsOn(':common:buildHostJNI')
}

tasks.build.dependsOn(buildHostJNI)

6 changes: 0 additions & 6 deletions apl/.classpath

This file was deleted.

23 changes: 0 additions & 23 deletions apl/.project

This file was deleted.

2 changes: 0 additions & 2 deletions apl/.settings/org.eclipse.buildship.core.prefs

This file was deleted.

0 comments on commit 083314b

Please sign in to comment.