Skip to content

Commit b7b1abc

Browse files
authored
Update Android Gradle Plugin to 9.x (#4658)
1 parent d58e3f0 commit b7b1abc

File tree

4 files changed

+68
-35
lines changed

4 files changed

+68
-35
lines changed

support/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
<manifest package="dev.fmt" />
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
</manifest>

support/build.gradle

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,68 @@
1+
//UPDATED: Updated for Android Gradle Plugin 9.x
2+
//Removes deprecated APIs
3+
14
import java.nio.file.Paths
25

36
// General gradle arguments for root project
47
buildscript {
58
repositories {
69
google()
7-
jcenter()
10+
mavenCentral() // UPDATED: jcenter() is deprecated and shut-down
811
}
912
dependencies {
13+
/*
14+
https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
1015
//
11-
// https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
12-
//
13-
// Notice that 4.0.0 here is the version of [Android Gradle Plugin]
14-
// According to URL above you will need Gradle 6.1 or higher
15-
//
16-
classpath "com.android.tools.build:gradle:4.1.1"
16+
UPDATED to Android Gradle Plugin 9.0.0
17+
18+
According to URL above you will need Gradle 6.1 or higher
19+
*/
20+
classpath "com.android.tools.build:gradle:9.0.0"
1721
}
1822
}
1923
repositories {
2024
google()
21-
jcenter()
25+
mavenCentral() // UPDATED: jcenter replacement
2226
}
2327

2428
// Project's root where CMakeLists.txt exists: rootDir/support/.cxx -> rootDir
29+
2530
def rootDir = Paths.get(project.buildDir.getParent()).getParent()
2631
println("rootDir: ${rootDir}")
2732

28-
// Output: Shared library (.so) for Android
33+
// Output: Shared library (.so) for Android
34+
2935
apply plugin: "com.android.library"
3036
android {
31-
compileSdkVersion 25 // Android 7.0
32-
33-
// Target ABI
34-
// - This option controls target platform of module
35-
// - The platform might be limited by compiler's support
36-
// some can work with Clang(default), but some can work only with GCC...
37-
// if bad, both toolchains might not support it
38-
splits {
39-
abi {
40-
enable true
41-
// Specify platforms for Application
42-
reset()
43-
include "arm64-v8a", "armeabi-v7a", "x86_64"
44-
}
45-
}
46-
ndkVersion "21.3.6528147" // ANDROID_NDK_HOME is deprecated. Be explicit
37+
38+
// UPDATED: Namespace is now required in build.gralde for AGP 8+ (it was moved from manifest)
39+
40+
namespace = "dev.fmt"
41+
42+
compileSdk 36 // UPDATED: Target Android 16 (API 36). 'compileSdkVersion' is deprecated
43+
44+
/* Target ABI
45+
- This option controls target platform of module
46+
- The platform might be limited by compiler's support
47+
some can work with Clang(default), but some can work only with GCC...
48+
if bad, both toolchains might not support it
49+
-* UPDATED: 'splits' block is deprecated for libraries. We now use 'ndk.abifilters' in defaultConfig
50+
-> splits { abi { ...... } } -> removed
51+
*/
52+
53+
ndkVersion = "28.2.13676358" // UPDATED: Locked to stable NDK 28 (AGP 9 defualt). Be explicit.
4754

4855
defaultConfig {
49-
minSdkVersion 21 // Android 5.0+
50-
targetSdkVersion 25 // Follow Compile SDK
56+
minSdk 21 // Android 5.0+ (UPDATED: syntax)
57+
targetSdkVersion 36 // Follow Compile SDK (UPDATED: syntax)
5158
versionCode 34 // Follow release count
5259
versionName "7.1.2" // Follow Official version
53-
60+
61+
// UPDATED: Correct way to filter ABIs for a library in modern AGP
62+
ndk{
63+
abiFilters "arm64-v8a", "armeabi-v7a", "x86_64"
64+
}
65+
5466
externalNativeBuild {
5567
cmake {
5668
arguments "-DANDROID_STL=c++_shared" // Specify Android STL
@@ -71,7 +83,7 @@ android {
7183
// neighbor of the top level cmake
7284
externalNativeBuild {
7385
cmake {
74-
version "3.10.0+"
86+
version = "3.22.1" // UPDATED: 3.10 is too old for AGP 9
7587
path "${rootDir}/CMakeLists.txt"
7688
// buildStagingDirectory "./build" // Custom path for cmake output
7789
}
@@ -86,20 +98,26 @@ android {
8698

8799
// https://developer.android.com/studio/build/native-dependencies#build_system_configuration
88100
buildFeatures {
89-
prefab true
90-
prefabPublishing true
101+
prefab = true
102+
prefabPublishing = true
91103
}
92104
prefab {
93105
fmt {
94-
headers "${rootDir}/include"
106+
headers = "${rootDir}/include"
95107
}
96108
}
97109
}
98110

99111
assemble.doLast
100112
{
101-
// Instead of `ninja install`, Gradle will deploy the files.
102-
// We are doing this since FMT is dependent to the ANDROID_STL after build
113+
/*
114+
*- Instead of `ninja install`, Gradle will deploy the files.
115+
*- We are doing this since FMT is dependent to the ANDROID_STL after build
116+
117+
UPDATED: Path Adjustments
118+
-> AGP 9+ often puts intermediates in build/intermediates/cxx/ or similar
119+
-> Note: This manual copy is Fragile. If empty, check 'build/intermediates/cxx'.
120+
*/
103121
copy {
104122
from "build/intermediates/cmake"
105123
into "${rootDir}/libs"

support/gradle.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Required for modern Android builds (AGP 8.0+)
2+
android.useAndroidX=true
3+
4+
# Improves build performance
5+
android.nonTransitiveRClass=true
6+
7+
# Memory settings for the build process
8+
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
#This downloads Gradle 9.3 automatically
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.0-bin.zip
5+
zipStoreBase=GRADLE_USER_HOME
6+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)