From 8f5216d9cb03842042a32732fb58e2ba75c795a7 Mon Sep 17 00:00:00 2001 From: Clayton Wilkinson Date: Fri, 29 Jan 2016 14:18:31 -0800 Subject: [PATCH] Updating build.gradle files to depend on gpg-sdk This adds a dependency task to each sample for running the Common/gpg-sdk project. This project downloads and unzips the C++ SDK before compilation. Change-Id: I0013f66ecc5ce045f1ed3d85537ab78347049bc1 --- samples-android/ButtonClicker/build.gradle | 24 ++++--- .../CollectAllTheStarsNative/build.gradle | 13 ++++ .../Common/cpufeatures/build.gradle | 23 +++++-- .../Common/native_app_glue/build.gradle | 67 +++++-------------- samples-android/Minimalist/build.gradle | 13 ++++ samples-android/Teapot/build.gradle | 13 ++++ .../TrivialQuestNative/build.gradle | 13 ++++ 7 files changed, 100 insertions(+), 66 deletions(-) diff --git a/samples-android/ButtonClicker/build.gradle b/samples-android/ButtonClicker/build.gradle index decbe50..53e9d94 100644 --- a/samples-android/ButtonClicker/build.gradle +++ b/samples-android/ButtonClicker/build.gradle @@ -1,6 +1,17 @@ apply plugin: 'com.android.model.application' -evaluationDependsOn(':Common/gpg-sdk') +// Depend on another project that downloads and unzips the C++ SDK. +evaluationDependsOn(':Common/gpg-sdk') + +// As the plugin has created the build tasks, add the gpg-sdk task to +// the task dependencies so it gets done before compiling +tasks.whenTaskAdded { task -> + if (task.name.equals("preBuild")) { + project(':Common/gpg-sdk').defaultTasks.each { t -> + task.dependsOn project(':Common/gpg-sdk').tasks[t] + } + } +} def gpg_cpp_path = file(project(':Common/gpg-sdk').projectDir).absolutePath + "/gpg-cpp-sdk/android" @@ -21,20 +32,11 @@ model { } } android { - signingConfigs.with { - debug { - storeFile = file('/Users/wilkinsonclay/gswitch/automation-cpp-android-samples/configs/debug.keystore') - keyAlias = 'androiddebugkey' - keyPassword = 'android' - storePassword = 'android' - } -} - compileSdkVersion=23 buildToolsVersion="23.0.2" defaultConfig.with { - applicationId= "com.google.clayton.play.bc" + applicationId="com.google.example.games.ButtonClicker" minSdkVersion.apiLevel = 11 targetSdkVersion.apiLevel = 23 } diff --git a/samples-android/CollectAllTheStarsNative/build.gradle b/samples-android/CollectAllTheStarsNative/build.gradle index 7c696ca..6aaabff 100644 --- a/samples-android/CollectAllTheStarsNative/build.gradle +++ b/samples-android/CollectAllTheStarsNative/build.gradle @@ -1,5 +1,18 @@ apply plugin: 'com.android.model.application' +// Depend on another project that downloads and unzips the C++ SDK. +evaluationDependsOn(':Common/gpg-sdk') + +// As the plugin has created the build tasks, add the gpg-sdk task to +// the task dependencies so it gets done before compiling +tasks.whenTaskAdded { task -> + if (task.name.equals("preBuild")) { + project(':Common/gpg-sdk').defaultTasks.each { t -> + task.dependsOn project(':Common/gpg-sdk').tasks[t] + } + } +} + def gpg_cpp_path = file(project(':Common/gpg-sdk').projectDir).absolutePath + "/gpg-cpp-sdk/android" // stlport configuration ["c++_static", "c++_shared", "gnustl_static", "gnustl_shared"] diff --git a/samples-android/Common/cpufeatures/build.gradle b/samples-android/Common/cpufeatures/build.gradle index 737f118..d9adf77 100644 --- a/samples-android/Common/cpufeatures/build.gradle +++ b/samples-android/Common/cpufeatures/build.gradle @@ -1,9 +1,22 @@ apply plugin: "com.android.model.native" -// Retrieve ndk path: ndk.dir MUST be set in file local.properties -Properties properties = new Properties() -properties.load(project.rootProject.file('local.properties').newDataInputStream()) -def ndkDir = properties.getProperty('ndk.dir') +def ndkDir = null + +if (project.rootProject.file('local.properties').exists()) { + // Retrieve ndk path: ndk.dir MUST be set in file local.properties + Properties properties = new Properties() + properties.load(project.rootProject.file('local.properties').newDataInputStream()) + ndkDir = properties.getProperty('ndk.dir') +} else if (System.getProperty('ANDROID_NDK_HOME') != null) { + ndkDir = System.getProperty('ANDROID_NDK_HOME') +} else if (System.getenv('ANDROID_NDK_HOME') != null) { + ndkDir = System.getenv('ANDROID_NDK_HOME') +} + +if (ndkDir == null || ndkDir == "") { + throw new Exception("Need to run from Android Studio or define ANDROID_NDK_HOME") +} + model { android { @@ -13,7 +26,7 @@ model { android.ndk { moduleName = "cpufeatures" } - + android.sources { main { jni { diff --git a/samples-android/Common/native_app_glue/build.gradle b/samples-android/Common/native_app_glue/build.gradle index dd9b69f..9c06bd7 100644 --- a/samples-android/Common/native_app_glue/build.gradle +++ b/samples-android/Common/native_app_glue/build.gradle @@ -1,9 +1,21 @@ apply plugin: "com.android.model.native" -// Retrieve ndk path: ndk.dir MUST be set in file local.properties -Properties properties = new Properties() -properties.load(project.rootProject.file('local.properties').newDataInputStream()) -def ndkDir = properties.getProperty('ndk.dir') +def ndkDir = null + +if (project.rootProject.file('local.properties').exists()) { + // Retrieve ndk path: ndk.dir MUST be set in file local.properties + Properties properties = new Properties() + properties.load(project.rootProject.file('local.properties').newDataInputStream()) + ndkDir = properties.getProperty('ndk.dir') +} else if (System.getProperty('ANDROID_NDK_HOME') != null) { + ndkDir = System.getProperty('ANDROID_NDK_HOME') +} else if (System.getenv('ANDROID_NDK_HOME') != null) { + ndkDir = System.getenv('ANDROID_NDK_HOME') +} + +if (ndkDir == null || ndkDir == "") { + throw new Exception("Need to run from Android Studio or define ANDROID_NDK_HOME") +} model { android { @@ -33,52 +45,7 @@ model { We are building a static library, so disable all the shared library tasks. */ tasks.whenTaskAdded { task -> - if (task.name == 'linkArmeabi-v7aDebugNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'linkArm64-v8aDebugNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'linkArmeabiDebugNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'linkX86DebugNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'stripSymbolsArmeabi-v7aDebugNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'stripSymbolsArm64-v8aDebugNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'stripSymbolsArmeabiDebugNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'stripSymbolsX86DebugNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'linkArm64-v8aReleaseNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'stripSymbolsArm64-v8aReleaseNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'linkArmeabi-v7aReleaseNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'stripSymbolsArmeabi-v7aReleaseNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'linkArmeabiReleaseNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'stripSymbolsArmeabiReleaseNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'linkX86ReleaseNative_app_glueSharedLibrary') { - task.enabled = false - } - else if (task.name == 'stripSymbolsX86ReleaseNative_app_glueSharedLibrary') { + if (task.name.contains("SharedLibrary")) { task.enabled = false } } diff --git a/samples-android/Minimalist/build.gradle b/samples-android/Minimalist/build.gradle index 7f69d78..e0cf787 100644 --- a/samples-android/Minimalist/build.gradle +++ b/samples-android/Minimalist/build.gradle @@ -1,5 +1,18 @@ apply plugin: 'com.android.model.application' +// Depend on another project that downloads and unzips the C++ SDK. +evaluationDependsOn(':Common/gpg-sdk') + +// As the plugin has created the build tasks, add the gpg-sdk task to +// the task dependencies so it gets done before compiling +tasks.whenTaskAdded { task -> + if (task.name.equals("preBuild")) { + project(':Common/gpg-sdk').defaultTasks.each { t -> + task.dependsOn project(':Common/gpg-sdk').tasks[t] + } + } +} + def gpg_cpp_path = file(project(':Common/gpg-sdk').projectDir).absolutePath + "/gpg-cpp-sdk/android" // stlport configuration ["c++_static", "c++_shared", "gnustl_static", "gnustl_shared"] diff --git a/samples-android/Teapot/build.gradle b/samples-android/Teapot/build.gradle index 987953a..4649614 100644 --- a/samples-android/Teapot/build.gradle +++ b/samples-android/Teapot/build.gradle @@ -1,5 +1,18 @@ apply plugin: 'com.android.model.application' +// Depend on another project that downloads and unzips the C++ SDK. +evaluationDependsOn(':Common/gpg-sdk') + +// As the plugin has created the build tasks, add the gpg-sdk task to +// the task dependencies so it gets done before compiling +tasks.whenTaskAdded { task -> + if (task.name.equals("preBuild")) { + project(':Common/gpg-sdk').defaultTasks.each { t -> + task.dependsOn project(':Common/gpg-sdk').tasks[t] + } + } +} + def gpg_cpp_path = file(project(':Common/gpg-sdk').projectDir).absolutePath + "/gpg-cpp-sdk/android" // stlport configuration ["c++_static", "c++_shared", "gnustl_static", "gnustl_shared"] diff --git a/samples-android/TrivialQuestNative/build.gradle b/samples-android/TrivialQuestNative/build.gradle index ffd146d..4722a84 100644 --- a/samples-android/TrivialQuestNative/build.gradle +++ b/samples-android/TrivialQuestNative/build.gradle @@ -1,5 +1,18 @@ apply plugin: 'com.android.model.application' +// Depend on another project that downloads and unzips the C++ SDK. +evaluationDependsOn(':Common/gpg-sdk') + +// As the plugin has created the build tasks, add the gpg-sdk task to +// the task dependencies so it gets done before compiling +tasks.whenTaskAdded { task -> + if (task.name.equals("preBuild")) { + project(':Common/gpg-sdk').defaultTasks.each { t -> + task.dependsOn project(':Common/gpg-sdk').tasks[t] + } + } +} + def gpg_cpp_path = file(project(':Common/gpg-sdk').projectDir).absolutePath + "/gpg-cpp-sdk/android" // stlport configuration ["c++_static", "c++_shared", "gnustl_static", "gnustl_shared"]