Update build.gradle for latest AGP (#2026)
* update build.gradle for latest AGP * bump Android Gradle Plugin version to 4.1.1 * ignore .cxx which was externalNativeBuild in old versions Use variable 'rootDir' instead of using relative path. * build.gradle copies AAR files to libs/
This commit is contained in:
parent
bcc20b29df
commit
6cdd1be93e
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,6 +9,7 @@ gradle/
|
|||||||
gradlew*
|
gradlew*
|
||||||
local.properties
|
local.properties
|
||||||
build/
|
build/
|
||||||
|
support/.cxx
|
||||||
|
|
||||||
bin/
|
bin/
|
||||||
/_CPack_Packages
|
/_CPack_Packages
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
// General gradle arguments for root project
|
// General gradle arguments for root project
|
||||||
buildscript {
|
buildscript {
|
||||||
@ -7,24 +8,25 @@ buildscript {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
//
|
//
|
||||||
// https://developer.android.com/studio/releases/gradle-plugin
|
// https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
|
||||||
//
|
//
|
||||||
// Notice that 3.3.0 here is the version of [Android Gradle Plugin]
|
// Notice that 4.0.0 here is the version of [Android Gradle Plugin]
|
||||||
// Accroding to URL above you will need Gradle 5.0 or higher
|
// Accroding to URL above you will need Gradle 6.1 or higher
|
||||||
//
|
//
|
||||||
// If you are using Android Studio, and it is using Gradle's lower
|
classpath "com.android.tools.build:gradle:4.1.1"
|
||||||
// version, Use the plugin version 3.1.3 ~ 3.2.0 for Gradle 4.4 ~ 4.10
|
|
||||||
classpath 'com.android.tools.build:gradle:3.3.0'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output: Shared library (.so) for Android
|
|
||||||
apply plugin: 'com.android.library'
|
|
||||||
|
|
||||||
|
// Project's root where CMakeLists.txt exists: rootDir/support/.cxx -> rootDir
|
||||||
|
def rootDir = Paths.get(project.buildDir.getParent()).getParent()
|
||||||
|
println("rootDir: ${rootDir}")
|
||||||
|
|
||||||
|
// Output: Shared library (.so) for Android
|
||||||
|
apply plugin: "com.android.library"
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 25 // Android 7.0
|
compileSdkVersion 25 // Android 7.0
|
||||||
|
|
||||||
@ -41,13 +43,13 @@ android {
|
|||||||
include "arm64-v8a", "armeabi-v7a", "x86_64"
|
include "arm64-v8a", "armeabi-v7a", "x86_64"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ndkVersion "21.3.6528147" // ANDROID_NDK_HOME is deprecated. Be explicit
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 21 // Android 5.0+
|
minSdkVersion 21 // Android 5.0+
|
||||||
targetSdkVersion 25 // Follow Compile SDK
|
targetSdkVersion 25 // Follow Compile SDK
|
||||||
versionCode 21 // Follow release count
|
versionCode 34 // Follow release count
|
||||||
versionName "5.3.0" // Follow Official version
|
versionName "7.1.2" // Follow Official version
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
|
||||||
|
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
@ -56,9 +58,9 @@ android {
|
|||||||
arguments "-DFMT_TEST=false" // Skip test
|
arguments "-DFMT_TEST=false" // Skip test
|
||||||
arguments "-DFMT_DOC=false" // Skip document
|
arguments "-DFMT_DOC=false" // Skip document
|
||||||
cppFlags "-std=c++17"
|
cppFlags "-std=c++17"
|
||||||
|
targets "fmt"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println("Gradle CMake Plugin: ")
|
|
||||||
println(externalNativeBuild.cmake.cppFlags)
|
println(externalNativeBuild.cmake.cppFlags)
|
||||||
println(externalNativeBuild.cmake.arguments)
|
println(externalNativeBuild.cmake.arguments)
|
||||||
}
|
}
|
||||||
@ -69,16 +71,27 @@ android {
|
|||||||
// neighbor of the top level cmake
|
// neighbor of the top level cmake
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
path "../CMakeLists.txt"
|
version "3.10.0+"
|
||||||
|
path "${rootDir}/CMakeLists.txt"
|
||||||
// buildStagingDirectory "./build" // Custom path for cmake output
|
// buildStagingDirectory "./build" // Custom path for cmake output
|
||||||
}
|
}
|
||||||
//println(cmake.path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets{
|
sourceSets{
|
||||||
// Android Manifest for Gradle
|
// Android Manifest for Gradle
|
||||||
main {
|
main {
|
||||||
manifest.srcFile 'AndroidManifest.xml'
|
manifest.srcFile "AndroidManifest.xml"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://developer.android.com/studio/build/native-dependencies#build_system_configuration
|
||||||
|
buildFeatures {
|
||||||
|
prefab true
|
||||||
|
prefabPublishing true
|
||||||
|
}
|
||||||
|
prefab {
|
||||||
|
fmt {
|
||||||
|
headers "${rootDir}/include"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,20 +101,32 @@ assemble.doLast
|
|||||||
// Instead of `ninja install`, Gradle will deploy the files.
|
// Instead of `ninja install`, Gradle will deploy the files.
|
||||||
// We are doing this since FMT is dependent to the ANDROID_STL after build
|
// We are doing this since FMT is dependent to the ANDROID_STL after build
|
||||||
copy {
|
copy {
|
||||||
from 'build/intermediates/cmake'
|
from "build/intermediates/cmake"
|
||||||
into '../libs'
|
into "${rootDir}/libs"
|
||||||
}
|
}
|
||||||
// Copy debug binaries
|
// Copy debug binaries
|
||||||
copy {
|
copy {
|
||||||
from '../libs/debug/obj'
|
from "${rootDir}/libs/debug/obj"
|
||||||
into '../libs/debug'
|
into "${rootDir}/libs/debug"
|
||||||
}
|
}
|
||||||
// Copy Release binaries
|
// Copy Release binaries
|
||||||
copy {
|
copy {
|
||||||
from '../libs/release/obj'
|
from "${rootDir}/libs/release/obj"
|
||||||
into '../libs/release'
|
into "${rootDir}/libs/release"
|
||||||
}
|
}
|
||||||
// Remove empty directory
|
// Remove empty directory
|
||||||
delete '../libs/debug/obj'
|
delete "${rootDir}/libs/debug/obj"
|
||||||
delete '../libs/release/obj'
|
delete "${rootDir}/libs/release/obj"
|
||||||
|
|
||||||
|
// Copy AAR files. Notice that the aar is named after the folder of this script.
|
||||||
|
copy {
|
||||||
|
from "build/outputs/aar/support-release.aar"
|
||||||
|
into "${rootDir}/libs"
|
||||||
|
rename "support-release.aar", "fmt-release.aar"
|
||||||
|
}
|
||||||
|
copy {
|
||||||
|
from "build/outputs/aar/support-debug.aar"
|
||||||
|
into "${rootDir}/libs"
|
||||||
|
rename "support-debug.aar", "fmt-debug.aar"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user