diff options
Diffstat (limited to 'platform_tools/android/apps')
5 files changed, 99 insertions, 101 deletions
diff --git a/platform_tools/android/apps/build.gradle b/platform_tools/android/apps/build.gradle index 7aa9b56af8..9f285e5b06 100644 --- a/platform_tools/android/apps/build.gradle +++ b/platform_tools/android/apps/build.gradle @@ -18,3 +18,92 @@ 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<Task> 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 7d747c1791..e368a66ef6 100644 --- a/platform_tools/android/apps/skqp/build.gradle +++ b/platform_tools/android/apps/skqp/build.gradle @@ -4,12 +4,8 @@ * 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' @@ -25,48 +21,9 @@ 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 4457fc61f8..58e09ec982 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("libskqp_app"); + System.loadLibrary("skqp_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 ad34f8a61d..630544d0bb 100644 --- a/platform_tools/android/apps/viewer/build.gradle +++ b/platform_tools/android/apps/viewer/build.gradle @@ -4,12 +4,8 @@ * 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' @@ -25,54 +21,10 @@ 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{}; } - externalNativeBuild { - cmake { - path ANDROID_CMAKE_HEADER_PATH - } - } + setupSkiaLibraryBuild(project, applicationVariants, "libviewer") } 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 0c007ef363..7253eb7503 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("libviewer"); + System.loadLibrary("viewer"); } private native long createNativeApp(AssetManager assetManager); |