Skip to content

Commit 6cdd1be

Browse files
authored
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/
1 parent bcc20b2 commit 6cdd1be

File tree

2 files changed

+50
-24
lines changed

2 files changed

+50
-24
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ gradle/
99
gradlew*
1010
local.properties
1111
build/
12+
support/.cxx
1213

1314
bin/
1415
/_CPack_Packages

support/build.gradle

+49-24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import java.nio.file.Paths
12

23
// General gradle arguments for root project
34
buildscript {
@@ -7,24 +8,25 @@ buildscript {
78
}
89
dependencies {
910
//
10-
// https://developer.android.com/studio/releases/gradle-plugin
11+
// https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
1112
//
12-
// Notice that 3.3.0 here is the version of [Android Gradle Plugin]
13-
// Accroding to URL above you will need Gradle 5.0 or higher
13+
// Notice that 4.0.0 here is the version of [Android Gradle Plugin]
14+
// Accroding to URL above you will need Gradle 6.1 or higher
1415
//
15-
// If you are using Android Studio, and it is using Gradle's lower
16-
// version, Use the plugin version 3.1.3 ~ 3.2.0 for Gradle 4.4 ~ 4.10
17-
classpath 'com.android.tools.build:gradle:3.3.0'
16+
classpath "com.android.tools.build:gradle:4.1.1"
1817
}
1918
}
2019
repositories {
2120
google()
2221
jcenter()
2322
}
24-
25-
// Output: Shared library (.so) for Android
26-
apply plugin: 'com.android.library'
2723

24+
// Project's root where CMakeLists.txt exists: rootDir/support/.cxx -> rootDir
25+
def rootDir = Paths.get(project.buildDir.getParent()).getParent()
26+
println("rootDir: ${rootDir}")
27+
28+
// Output: Shared library (.so) for Android
29+
apply plugin: "com.android.library"
2830
android {
2931
compileSdkVersion 25 // Android 7.0
3032

@@ -41,13 +43,13 @@ android {
4143
include "arm64-v8a", "armeabi-v7a", "x86_64"
4244
}
4345
}
46+
ndkVersion "21.3.6528147" // ANDROID_NDK_HOME is deprecated. Be explicit
4447

4548
defaultConfig {
4649
minSdkVersion 21 // Android 5.0+
4750
targetSdkVersion 25 // Follow Compile SDK
48-
versionCode 21 // Follow release count
49-
versionName "5.3.0" // Follow Official version
50-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
51+
versionCode 34 // Follow release count
52+
versionName "7.1.2" // Follow Official version
5153

5254
externalNativeBuild {
5355
cmake {
@@ -56,9 +58,9 @@ android {
5658
arguments "-DFMT_TEST=false" // Skip test
5759
arguments "-DFMT_DOC=false" // Skip document
5860
cppFlags "-std=c++17"
61+
targets "fmt"
5962
}
6063
}
61-
println("Gradle CMake Plugin: ")
6264
println(externalNativeBuild.cmake.cppFlags)
6365
println(externalNativeBuild.cmake.arguments)
6466
}
@@ -69,16 +71,27 @@ android {
6971
// neighbor of the top level cmake
7072
externalNativeBuild {
7173
cmake {
72-
path "../CMakeLists.txt"
74+
version "3.10.0+"
75+
path "${rootDir}/CMakeLists.txt"
7376
// buildStagingDirectory "./build" // Custom path for cmake output
7477
}
75-
//println(cmake.path)
7678
}
7779

7880
sourceSets{
7981
// Android Manifest for Gradle
8082
main {
81-
manifest.srcFile 'AndroidManifest.xml'
83+
manifest.srcFile "AndroidManifest.xml"
84+
}
85+
}
86+
87+
// https://developer.android.com/studio/build/native-dependencies#build_system_configuration
88+
buildFeatures {
89+
prefab true
90+
prefabPublishing true
91+
}
92+
prefab {
93+
fmt {
94+
headers "${rootDir}/include"
8295
}
8396
}
8497
}
@@ -88,20 +101,32 @@ assemble.doLast
88101
// Instead of `ninja install`, Gradle will deploy the files.
89102
// We are doing this since FMT is dependent to the ANDROID_STL after build
90103
copy {
91-
from 'build/intermediates/cmake'
92-
into '../libs'
104+
from "build/intermediates/cmake"
105+
into "${rootDir}/libs"
93106
}
94107
// Copy debug binaries
95108
copy {
96-
from '../libs/debug/obj'
97-
into '../libs/debug'
109+
from "${rootDir}/libs/debug/obj"
110+
into "${rootDir}/libs/debug"
98111
}
99112
// Copy Release binaries
100113
copy {
101-
from '../libs/release/obj'
102-
into '../libs/release'
114+
from "${rootDir}/libs/release/obj"
115+
into "${rootDir}/libs/release"
103116
}
104117
// Remove empty directory
105-
delete '../libs/debug/obj'
106-
delete '../libs/release/obj'
118+
delete "${rootDir}/libs/debug/obj"
119+
delete "${rootDir}/libs/release/obj"
120+
121+
// Copy AAR files. Notice that the aar is named after the folder of this script.
122+
copy {
123+
from "build/outputs/aar/support-release.aar"
124+
into "${rootDir}/libs"
125+
rename "support-release.aar", "fmt-release.aar"
126+
}
127+
copy {
128+
from "build/outputs/aar/support-debug.aar"
129+
into "${rootDir}/libs"
130+
rename "support-debug.aar", "fmt-debug.aar"
131+
}
107132
}

0 commit comments

Comments
 (0)