From 78c9225b9ecc5235745a84f7bbc238448e899727 Mon Sep 17 00:00:00 2001 From: guanghuafan Date: Wed, 26 Apr 2017 14:31:16 -0700 Subject: [PATCH] demo/smoke Android build update: use latest cmake with Android Studio --- demos/smoke/android/CMakeLists.txt | 54 +++++++++++ demos/smoke/android/build-and-install | 3 +- demos/smoke/android/build.gradle | 105 ++++++--------------- .../gradle/wrapper/gradle-wrapper.properties | 4 +- 4 files changed, 88 insertions(+), 78 deletions(-) create mode 100644 demos/smoke/android/CMakeLists.txt diff --git a/demos/smoke/android/CMakeLists.txt b/demos/smoke/android/CMakeLists.txt new file mode 100644 index 0000000..8846bce --- /dev/null +++ b/demos/smoke/android/CMakeLists.txt @@ -0,0 +1,54 @@ +# +# Copyright (C) 2017 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +project(Smoke) +cmake_minimum_required(VERSION 3.4.1) + +get_filename_component(demosDir "${CMAKE_SOURCE_DIR}/../.." ABSOLUTE) +set(smokeDir "${demosDir}/smoke") +get_filename_component(glmDir "${demosDir}/../libs" ABSOLUTE) +get_filename_component(vulkanDir "${demosDir}/../include" ABSOLUTE) + +# build native_app_glue as a static lib +add_library(native_activity_glue STATIC + ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c) + +# Build application's shared lib +set(CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} -std=c++11 -fexceptions -Wall \ + -Wextra -Wno-unused-parameter \ + -DVK_NO_PROTOTYPES -DVK_USE_PLATFORM_ANDROID_KHR \ + -DGLM_FORCE_RADIANS") +add_library(Smoke SHARED + ${smokeDir}/Game.cpp + ${smokeDir}/Meshes.cpp + ${smokeDir}/Simulation.cpp + ${smokeDir}/HelpersDispatchTable.cpp + ${smokeDir}/Shell.cpp + ${smokeDir}/ShellAndroid.cpp + ${smokeDir}/Smoke.cpp + ${smokeDir}/Main.cpp) + +target_include_directories(Smoke PRIVATE + ${ANDROID_NDK}/sources/android/native_app_glue + ${vulkanDir} + ${glmDir} + ${CMAKE_SOURCE_DIR}/src/main/jni) + +target_link_libraries(Smoke + android + log + native_activity_glue) diff --git a/demos/smoke/android/build-and-install b/demos/smoke/android/build-and-install index 7ee17b4..c3295a9 100755 --- a/demos/smoke/android/build-and-install +++ b/demos/smoke/android/build-and-install @@ -34,8 +34,7 @@ build() { } install() { - adb uninstall com.example.Smoke - adb install build/outputs/apk/android-fat-debug.apk + adb install -r build/outputs/apk/android-debug.apk } run() { diff --git a/demos/smoke/android/build.gradle b/demos/smoke/android/build.gradle index 943b46a..30df002 100644 --- a/demos/smoke/android/build.gradle +++ b/demos/smoke/android/build.gradle @@ -4,92 +4,49 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle-experimental:0.8.0' + classpath 'com.android.tools.build:gradle:2.3.0' } } -apply plugin: 'com.android.model.application' - -def demosDir = "../.." -def smokeDir = "${demosDir}/smoke" -def glmDir = "${demosDir}/../libs" -def vulkanDir = "${demosDir}/../include" -def layersDir = "${demosDir}/../build-android/libs" - -Properties properties = new Properties() -properties.load(project.rootProject.file('local.properties').newDataInputStream()) -def ndkDir = properties.getProperty('ndk.dir') - -model { - android { - compileSdkVersion = 23 - buildToolsVersion = "23.0.2" - - defaultConfig.with { - applicationId = "com.example.Smoke" - minSdkVersion.apiLevel = 22 - targetSdkVersion.apiLevel = 22 - versionCode = 1 - versionName = "0.1" +apply plugin: 'com.android.application' + +def layersDir = "../../../build-android/libs" + +android { + compileSdkVersion = 25 + buildToolsVersion = "25.0.2" + + defaultConfig { + applicationId = "com.example.Smoke" + minSdkVersion 24 + targetSdkVersion 24 + versionCode = 1 + versionName = "0.1" + ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86' + externalNativeBuild { + cmake.arguments '-DANDROID_PLATFORM=android-24', + '-DANDROID_STL=c++_static', + '-DANDROID_TOOLCHAIN=clang' } } - - android.ndk { - moduleName = "Smoke" - toolchain = "clang" - stl = "c++_static" - - cppFlags.addAll(["-std=c++11", "-fexceptions"]) - cppFlags.addAll(["-Wall", "-Wextra", "-Wno-unused-parameter"]) - - cppFlags.addAll([ - "-DVK_NO_PROTOTYPES", - "-DVK_USE_PLATFORM_ANDROID_KHR", - "-DGLM_FORCE_RADIANS", - ]) - - cppFlags.addAll([ - "-I${file("${ndkDir}/sources/android/native_app_glue")}".toString(), - "-I${file("${vulkanDir}")}".toString(), - "-I${file("${glmDir}")}".toString(), - "-I${file("src/main/jni")}".toString(), - ]) - - ldLibs.addAll(["android", "log", "dl"]) + externalNativeBuild { + cmake.path 'CMakeLists.txt' } - android.sources { - main { - jni { - source { - srcDir "${ndkDir}/sources/android/native_app_glue" - srcDir "${smokeDir}" - exclude 'ShellXcb.cpp' - exclude 'ShellWin32.cpp' - exclude 'ShellWayland.cpp' - } - } - jniLibs { - dependencies { - source.srcDir "${layersDir}" - } - } - } + // Need Android NDK-r12+ for pre-built validation layers + sourceSets { + main.jniLibs.srcDirs = [ "${layersDir}" ] } - android.buildTypes { + buildTypes { release { - ndk.with { + // enable debugging for release built too + ndk { debuggable = true } - } - } - - android.productFlavors { - create ("fat") { - ndk.abiFilters.add("arm64-v8a") - ndk.abiFilters.add("armeabi-v7a") - ndk.abiFilters.add("x86") + minifyEnabled = false + proguardFiles getDefaultProguardFile('proguard-android.txt'), + 'proguard-rules.pro' } } } diff --git a/demos/smoke/android/gradle/wrapper/gradle-wrapper.properties b/demos/smoke/android/gradle/wrapper/gradle-wrapper.properties index 6c7451b..5b57031 100644 --- a/demos/smoke/android/gradle/wrapper/gradle-wrapper.properties +++ b/demos/smoke/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Jan 27 08:20:52 CST 2016 +#Mon Apr 24 14:40:58 PDT 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip -- 2.7.4