From aee4512cc5bec007673ebdab10fc1d38e2f164f8 Mon Sep 17 00:00:00 2001 From: Park DongHa Date: Mon, 12 Mar 2018 19:40:25 +0000 Subject: [PATCH] Gradle (#649) * Gradle Gradle support to make ease of import in Android Java projects. * Gradle Gradle support for Android projects. For command line build, `gradle assembe` will trigger build phase - Config for Android .so file generation - Commented build.gradle - Automatic file copy after build - Dummy AndroidManifest file * Build with Gradle - Build job for Travis CI - Moved gradle file to support/ * Gradle Path - Absolute path for Gradle binary * File check after Gradle build - Additional script for build success - Check the Gradle's `assemble.doLast` task --- .gitignore | 11 +++++ .travis.yml | 30 ++++++++++++ support/AndroidManifest.xml | 1 + support/build.gradle | 98 +++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 support/AndroidManifest.xml create mode 100644 support/build.gradle diff --git a/.gitignore b/.gitignore index b9ea0fea..1e6172fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,14 @@ +.vscode/ + +*.iml +.idea/ +.externalNativeBuild/ +.gradle/ +gradle/ +gradlew* +local.properties +build/ + bin/ /_CPack_Packages /CMakeScripts diff --git a/.travis.yml b/.travis.yml index 314a2000..8d4fad1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,36 @@ matrix: exclude: - os: osx env: BUILD=Doc + include: + - language: android + android: + components: + - tools + - platform-tools + - android-21 + - sys-img-armeabi-v7a-android-21 + env: + - ANDROID=true + before_install: + - git submodule update --init --recursive + - sudo apt-get install wget unzip tree + install: + # Accept SDK Licenses + Install NDK + - yes | sdkmanager --update > /dev/null 2>&1 + - sdkmanager ndk-bundle > /dev/null 2>&1 + # Download Gradle 4.3.1 + - wget https://services.gradle.org/distributions/gradle-4.3.1-bin.zip + - mkdir -p gradle + - unzip -q -d ./gradle gradle-4.3.1-bin.zip + - export GRADLE=${TRAVIS_BUILD_DIR}/gradle/gradle-4.3.1/bin/gradle + before_script: + - bash $GRADLE --version + - cd ./support + script: + - bash $GRADLE clean assemble + after_success: + - cd ${TRAVIS_BUILD_DIR} + - tree ./libs # Install gcc-6 for extended constexpr support. addons: diff --git a/support/AndroidManifest.xml b/support/AndroidManifest.xml new file mode 100644 index 00000000..29fb0789 --- /dev/null +++ b/support/AndroidManifest.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/support/build.gradle b/support/build.gradle new file mode 100644 index 00000000..1dd64391 --- /dev/null +++ b/support/build.gradle @@ -0,0 +1,98 @@ +// General gradle arguments for root project +buildscript { + repositories { + google() + jcenter() + } + + dependencies { + classpath 'com.android.tools.build:gradle:3.0.1' + } +} + +// Output: Shared library (.so) for Android +apply plugin: 'com.android.library' + +android { + compileSdkVersion 25 // Android 7.0 + + // Target ABI + // - This option controls target platform of module + // - The platform might be limited by compiler's support + // some can work with Clang(default), but some can work only with GCC... + // if bad, both toolchains might not support it + splits { + abi { + enable true + // Be general, as much as possible ... + // universalApk true + + // Specify platforms for Application + reset() + include "x86", "x86_64", "armeabi-v7a", "arm64-v8a" + } + } + + defaultConfig { + minSdkVersion 21 // Android 5.0+ + targetSdkVersion 25 // Follow Compile SDK + versionCode 16 // Follow release count + versionName "4.1.0" // Follow Official version + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + externalNativeBuild { + cmake { + arguments "-DANDROID_STL=c++_shared" // Specify Android STL + arguments "-DBUILD_SHARED_LIBS=true" // Build shared object + arguments "-DFMT_TEST=false" // Skip test + arguments "-DFMT_DOC=false" // Skip document + cppFlags "-std=c++14" + } + } + println("Gradle CMake Plugin: ") + println(externalNativeBuild.cmake.cppFlags) + println(externalNativeBuild.cmake.arguments) + } + + // External Native build + // - Use existing CMakeList.txt + // - Give path to CMake. This gradle file should be + // neighbor of the top level cmake + externalNativeBuild { + cmake { + path "../CMakeLists.txt" + // buildStagingDirectory "./build" // Custom path for cmake output + } + //println(cmake.path) + } + + sourceSets{ + // Android Manifest for Gradle + main { + manifest.srcFile 'AndroidManifest.xml' + } + } +} + +assemble.doLast +{ + // Instead of `ninja install`, Gradle will deploy the files. + // We are doing this since FMT is dependent to the ANDROID_STL after build + copy { + from 'build/intermediates/cmake' + into '../libs' + } + // Copy debug binaries + copy { + from '../libs/debug/obj' + into '../libs/debug' + } + // Copy Release binaries + copy { + from '../libs/release/obj' + into '../libs/release' + } + // Remove empty directory + delete '../libs/debug/obj' + delete '../libs/release/obj' +}