From 222c9cfd1b3f50d21d4a1f93b0b52dd4973fe1b5 Mon Sep 17 00:00:00 2001 From: ziadb Date: Thu, 31 May 2018 15:55:09 -0400 Subject: Added support for visual debugging on Android Studio Change-Id: Icaf848c31167db10d6fbb13d74c7287b03628fb6 Bug: skia: Reviewed-on: https://skia-review.googlesource.com/130144 Reviewed-by: Derek Sollenberger --- gn/BUILD.gn | 2 +- gn/BUILDCONFIG.gn | 2 + platform_tools/android/CMakeLists.txt | 48 ++++++++++++ platform_tools/android/apps/build.gradle | 89 ---------------------- platform_tools/android/apps/skqp/build.gradle | 51 ++++++++++++- .../skqp/src/main/java/org/skia/skqp/SkQP.java | 2 +- platform_tools/android/apps/viewer/build.gradle | 56 +++++++++++++- .../java/org/skia/viewer/ViewerApplication.java | 2 +- 8 files changed, 152 insertions(+), 100 deletions(-) create mode 100644 platform_tools/android/CMakeLists.txt diff --git a/gn/BUILD.gn b/gn/BUILD.gn index 7a6a8211d5..9d65118c96 100644 --- a/gn/BUILD.gn +++ b/gn/BUILD.gn @@ -143,7 +143,7 @@ config("default") { libs += [ malloc ] } - if (is_android) { + if (is_android && !is_android_cmake) { asmflags += [ "--target=$ndk_target" ] cflags += [ "--sysroot=$ndk/sysroot", diff --git a/gn/BUILDCONFIG.gn b/gn/BUILDCONFIG.gn index e5440b9b76..3d4d65ad6e 100644 --- a/gn/BUILDCONFIG.gn +++ b/gn/BUILDCONFIG.gn @@ -10,6 +10,7 @@ is_skia_standalone = true declare_args() { is_official_build = false is_component_build = false + is_android_cmake = false ndk = "" # It's nice to keep ndk_api set to what Clank targets, but probably no big deal if we can't. @@ -37,6 +38,7 @@ declare_args() { skia_vulkan_sdk = getenv("VULKAN_SDK") skia_moltenvk_path = "" } + declare_args() { is_debug = !is_official_build } diff --git a/platform_tools/android/CMakeLists.txt b/platform_tools/android/CMakeLists.txt new file mode 100644 index 0000000000..c7a8a962b4 --- /dev/null +++ b/platform_tools/android/CMakeLists.txt @@ -0,0 +1,48 @@ +cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR) +cmake_policy(VERSION 2.8.8) + +## Supported ABIs: 'x86', 'x86_64', armeabi-v7a', 'arm64-v8a' +message("Build Type: ${CMAKE_BUILD_TYPE}") + +##### ARGS.GN +## Set dev in Android-CMake to true +set (android_cmake "true") +set (arg_android_cmake "is_android_cmake = ${android_cmake}") + +## Set the NDK path +set (arg_ndk "ndk = \"${ANDROID_NDK}\"") + +## Set target ABI +if(ANDROID_ABI STREQUAL "arm64-v8a") + set (arg_abi "target_cpu = \"arm64\"") +elseif(ANDROID_ABI STREQUAL "x86") + set (arg_abi "target_cpu = \"x86\"") +elseif(ANDROID_ABI STREQUAL "x86_64") + set (arg_abi "target_cpu = \"x64\"") +elseif(ANDROID_ABI STREQUAL "armeabi-v7a") + set (arg_abi "target_cpu = \"arm\"") +endif() +message ("Target ABI: ${ANDROID_ABI}") +message ("Target Builds: ${TARGETS}") + +set (android_out "${CMAKE_CURRENT_SOURCE_DIR}/../../out/android_cmake_${ANDROID_ABI}") + +execute_process(COMMAND mkdir -p ${android_out}/) +execute_process(COMMAND touch ${android_out}/args.gn) +file(WRITE "${android_out}/args.gn" "${arg_ndk}\n${arg_abi}\n${arg_android_cmake}\n") + +message("CMake Target Output Directory: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") +##### GN to CMAKE +set (bin_gn "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/gn") +set (gen "gen") +message("GN Output Directory: ${android_out}") + +set (ide "--ide=json") +set (script_arg "--json-ide-script=") +set (script_path "${CMAKE_CURRENT_SOURCE_DIR}/../../gn/gn_to_cmake.py") + +execute_process (COMMAND ${bin_gn} ${gen} ${android_out} ${ide} ${script_arg}${script_path} +WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +##### NINJA +include(${android_out}/CMakeLists.txt) \ No newline at end of file diff --git a/platform_tools/android/apps/build.gradle b/platform_tools/android/apps/build.gradle index 9f285e5b06..7aa9b56af8 100644 --- a/platform_tools/android/apps/build.gradle +++ b/platform_tools/android/apps/build.gradle @@ -18,92 +18,3 @@ allprojects { jcenter() } } - -def setupSkiaLibraryBuild(project, appVariants, appName) { - appVariants.all{ variant -> - def buildNativeLib = project.task("${variant.name}_BuildSkiaLib", type:Exec) { - workingDir '../../../..' // top-level skia directory - commandLine constructBuildCommand(project, variant, appName).split() - } - buildNativeLib.onlyIf { !project.hasProperty("suppressNativeBuild") } - - def copyNativeLib = project.task("${variant.name}_CopySkiaLib", type:Copy) { - def fromDir = getVariantOutDir(project, variant).skiaOut - def intoDir = getVariantOutDir(project, variant).androidOut - from fromDir - into intoDir - include "${appName}.so" - } - - TaskCollection compileTask = project.tasks.matching { - // println(it.name) - it.name.toLowerCase().contains("compile" + variant.name.toLowerCase()) && - it.name.toLowerCase().endsWith("ndk") - } - compileTask.findAll()*.dependsOn copyNativeLib - copyNativeLib.dependsOn buildNativeLib - } -} - -def getLocalProperties() { - Properties properties = new Properties() - File propFile = project.rootProject.file('local.properties') - if (propFile.canRead()) { - properties.load(propFile.newDataInputStream()) - } - propFile = project.rootProject.file('gradle.properties') - if (propFile.canRead()) { - properties.load(propFile.newDataInputStream()) - } - return properties -} - -def getVariantOutDir(project, variant) { - String variantPrefix = null - String androidLibDir = null - if (variant.name.startsWith("arm64")) { - variantPrefix = "arm64" - androidLibDir = "arm64-v8a" - } else if (variant.name.startsWith("arm")) { - variantPrefix = "arm" - androidLibDir = "armeabi-v7a" - } else if (variant.name.startsWith("x64")) { - variantPrefix = "x64" - androidLibDir = "x86_64" - } else if (variant.name.startsWith("x86")) { - variantPrefix = "x86" - androidLibDir = "x86" - } - - String skiaOutDir = null - String propName = "${variantPrefix}.out.dir" - if (project.hasProperty(propName)) { - skiaOutDir = project.getProperties().getAt(propName) - } else { - skiaOutDir = getLocalProperties().getProperty(propName, "missing_variant_out") - } - - return [skiaOut: skiaOutDir, - androidOut: "src/main/libs/${androidLibDir}"] -} - -def constructBuildCommand(project, variant, appName) { - String depotToolsDir = null - for (String entry : System.getenv("PATH").split(":")) { - if (entry.contains("depot_tools")) { - depotToolsDir = entry; - break; - } - } - if (depotToolsDir == null) { - depotToolsDir = getLocalProperties().getProperty('depot_tools.dir', null) - } - - if (depotToolsDir == null) { - throw GradleScriptException("Depot Tools not found! Please update your path to include" + - " depot_tools or define depot_tools.dir in local.properties") - } - - String out_dir = getVariantOutDir(project, variant).skiaOut - return "${depotToolsDir}/ninja -C $out_dir $appName" -} diff --git a/platform_tools/android/apps/skqp/build.gradle b/platform_tools/android/apps/skqp/build.gradle index e368a66ef6..7d747c1791 100644 --- a/platform_tools/android/apps/skqp/build.gradle +++ b/platform_tools/android/apps/skqp/build.gradle @@ -4,8 +4,12 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ + apply plugin: 'com.android.application' +//Make sure this is directory corresponds to skia/platform_tools/android +final String ANDROID_CMAKE_HEADER_PATH = "../../CMakeLists.txt" + dependencies { compile 'com.android.support:design:26.+' compile 'com.android.support.test:runner:0.5' @@ -21,9 +25,48 @@ android { versionCode 1 versionName "1.0" signingConfig signingConfigs.debug + + externalNativeBuild { + cmake { + //Native libraries to build + targets "libskqp_app" + + arguments "-DANDROID_STL=c++_static", + "-DTARGETS=${android.defaultConfig.externalNativeBuild.cmake.targets}" + } + } + + buildTypes { + debug { + applicationIdSuffix ".debug" + debuggable true + } + } + + productFlavors { + arm { + ndk { + abiFilters "armeabi-v7a" + } + } + + x86 { + ndk { + abiFilters "x86" + } + } + + x64 { + ndk { + abiFilters "x86_64" + } + } + } + } + + externalNativeBuild { + cmake { + path ANDROID_CMAKE_HEADER_PATH + } } - sourceSets.main.jni.srcDirs = [] - sourceSets.main.jniLibs.srcDir "src/main/libs" - productFlavors { universal{}; arm {}; arm64 {}; x86 {}; x64 {}; arm64vulkan{}; } - setupSkiaLibraryBuild(project, applicationVariants, "libskqp_app") } diff --git a/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQP.java b/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQP.java index 58e09ec982..4457fc61f8 100644 --- a/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQP.java +++ b/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQP.java @@ -28,7 +28,7 @@ public class SkQP { protected static final String LOG_PREFIX = "org.skia.skqp"; static { - System.loadLibrary("skqp_app"); + System.loadLibrary("libskqp_app"); } protected void runTests(Context context, String outputDirPath) { diff --git a/platform_tools/android/apps/viewer/build.gradle b/platform_tools/android/apps/viewer/build.gradle index 630544d0bb..ad34f8a61d 100644 --- a/platform_tools/android/apps/viewer/build.gradle +++ b/platform_tools/android/apps/viewer/build.gradle @@ -4,8 +4,12 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ + apply plugin: 'com.android.application' +//Make sure this is directory corresponds to skia/platform_tools/android +final String ANDROID_CMAKE_HEADER_PATH = "../../CMakeLists.txt" + dependencies { compile 'com.android.support:support-v13:23.3.0' compile 'com.android.support:appcompat-v7:23.3.0' @@ -21,10 +25,54 @@ android { versionCode 1 versionName "1.0" signingConfig signingConfigs.debug + + externalNativeBuild { + cmake { + //Native libraries to build + targets "libviewer" + + arguments "-DANDROID_STL=c++_static", + "-DTARGETS=${android.defaultConfig.externalNativeBuild.cmake.targets}" + } + } + + buildTypes { + debug { + applicationIdSuffix ".debug" + debuggable true + } + } + + productFlavors { + arm64 { + ndk { + abiFilters "arm64-v8a" + } + } + + arm { + ndk { + abiFilters "armeabi-v7a" + } + } + + x86 { + ndk { + abiFilters "x86" + } + } + + x64 { + ndk { + abiFilters "x86_64" + } + } + } } - sourceSets.main.jni.srcDirs = [] //disable automatic ndk-build call - sourceSets.main.jniLibs.srcDir "src/main/libs" - productFlavors { universal{}; arm {}; arm64 {}; x86 {}; x64 {}; arm64vulkan{}; } - setupSkiaLibraryBuild(project, applicationVariants, "libviewer") + externalNativeBuild { + cmake { + path ANDROID_CMAKE_HEADER_PATH + } + } } diff --git a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java index 7253eb7503..0c007ef363 100644 --- a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java +++ b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java @@ -16,7 +16,7 @@ public class ViewerApplication extends Application { private String mStateJsonStr, mTitle; static { - System.loadLibrary("viewer"); + System.loadLibrary("libviewer"); } private native long createNativeApp(AssetManager assetManager); -- cgit v1.2.3