Skip to content

Commit

Permalink
Build a AAR archive alongside the APK
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Aug 1, 2018
1 parent 78e90d6 commit e8af185
Show file tree
Hide file tree
Showing 16 changed files with 395 additions and 235 deletions.
6 changes: 4 additions & 2 deletions python/servo/package_commands.py
Expand Up @@ -214,10 +214,12 @@ def package(self, release=False, dev=False, android=None, debug=False, debugger=
if flavor is not None:
flavor_name = flavor.title()

task_name = "assemble" + flavor_name + build_type + build_mode
variant = ":assemble" + flavor_name + build_type + build_mode
apk_task_name = ":servoapp" + variant
aar_task_name = ":servoview" + variant
try:
with cd(path.join("support", "android", "apk")):
subprocess.check_call(["./gradlew", "--no-daemon", task_name], env=env)
subprocess.check_call(["./gradlew", "--no-daemon", apk_task_name, aar_task_name], env=env)
except subprocess.CalledProcessError as e:
print("Packaging Android exited with return value %d" % e.returncode)
return e.returncode
Expand Down
67 changes: 65 additions & 2 deletions support/android/apk/build.gradle
@@ -1,4 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
import org.apache.tools.ant.taskdefs.condition.Os

buildscript {
repositories {
jcenter()
Expand All @@ -17,6 +18,68 @@ allprojects {
}
google()
}
}

// Utility methods
String getTargetDir(boolean debug, String arch) {
def basePath = project.rootDir.getParentFile().getParentFile().getParentFile().absolutePath
return basePath + '/target/' + getSubTargetDir(debug, arch)
}

String getSubTargetDir(boolean debug, String arch) {
return getRustTarget(arch) + '/' + (debug ? 'debug' : 'release')
}

String getJniLibsPath(boolean debug, String arch) {
return getTargetDir(debug, arch) + '/apk/jniLibs'
}

static String getRustTarget(String arch) {
switch (arch.toLowerCase()) {
case 'arm' : return 'arm-linux-androideabi'
case 'armv7' : return 'armv7-linux-androideabi'
case 'arm64' : return 'aarch64-linux-android'
case 'x86' : return 'i686-linux-android'
default: throw new GradleException("Invalid target architecture " + arch)
}
}

buildDir = rootDir.absolutePath + "/../../../target/gradle"
static String getNDKAbi(String arch) {
switch (arch.toLowerCase()) {
case 'arm' : return 'armeabi'
case 'armv7' : return 'armeabi-v7a'
case 'arm64' : return 'arm64-v8a'
case 'x86' : return 'x86'
default: throw new GradleException("Invalid target architecture " + arch)
}
}

String getNdkDir() {
// Read environment variable used in rust build system
String ndkDir = System.getenv('ANDROID_NDK')
if (ndkDir == null) {
ndkDir = System.getenv('ANDROID_NDK_HOME')
}
if (ndkDir == null) {
ndkDir = System.getenv('ANDROID_NDK_ROOT')
}
if (ndkDir == null) {
// Fallback to ndkDir in local.properties
def rootDir = project.rootDir
def localProperties = new File(rootDir, "local.properties")
Properties properties = new Properties()
localProperties.withInputStream { instr ->
properties.load(instr)
}

ndkDir = properties.getProperty('ndk.dir')
}

def cmd = Os.isFamily(Os.FAMILY_WINDOWS) ? 'ndk-build.cmd' : 'ndk-build'
def ndkbuild = new File(ndkDir + '/' + cmd)
if (!ndkbuild.exists()) {
throw new GradleException("Please set a valid NDK_HOME environment variable" +
"or ndk.dir path in local.properties file");
}
return ndkbuild.absolutePath
}
2 changes: 1 addition & 1 deletion support/android/apk/jni/Android.mk
Expand Up @@ -17,6 +17,6 @@ MY_LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_PATH:= $(SERVO_TARGET_DIR)
LOCAL_MODULE := servo
LOCAL_MODULE := servojni
LOCAL_SRC_FILES := libsimpleservo.so
include $(PREBUILT_SHARED_LIBRARY)
2 changes: 1 addition & 1 deletion support/android/apk/jni/Application.mk
@@ -1,4 +1,4 @@
NDK_TOOLCHAIN_VERSION := 4.9
APP_MODULES := c++_shared servo
APP_MODULES := c++_shared servojni
APP_PLATFORM := android-18
APP_STL:= c++_shared

0 comments on commit e8af185

Please sign in to comment.