Skip to content

Commit 9b7910d

Browse files
committed
Improve android gradle utils
1 parent f03bce1 commit 9b7910d

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

core/platform/android/libcocos2dx/axistools.gradle

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class VersionComparator implements Comparator<String> {
9191

9292
class axistools {
9393

94-
static String[] findNativeBuildTools(project, ndkVer = "23.2.8568313", cmakeVer = "3.22.1+") {
94+
static String[] findNativeBuildTools(project, ndkVer = "23.2.8568313+", cmakeVer = "3.22.1+") {
9595

9696
// Detecting sdkRoot
9797
def sdkRoot = null
@@ -131,14 +131,25 @@ class axistools {
131131
ndkVer = ndkVer.substring(0, ndkVer.length() - 1)
132132
}
133133

134-
def ndkDirs = []
135-
File dir = new File("${sdkRoot}/ndk")
134+
def verList = []
135+
File dir = new File("${sdkRoot}${File.separator}ndk")
136136
if (dir.isDirectory()) {
137137
for (ndkDir in dir.listFiles()) {
138-
ndkDirs.add(ndkDir.toString())
138+
verList.add(ndkDir.getName())
139139
}
140140
}
141141

142+
verList.sort {a,b ->
143+
return axistools.compareVersion(b, a)
144+
}
145+
146+
def ndkDirs = []
147+
148+
// Collect ndkDirs for search
149+
for(ver in verList){
150+
ndkDirs.add("${sdkRoot}${File.separator}ndk${File.separator}${ver}")
151+
}
152+
142153
/* Find suitable ndk in dirs */
143154
rets[0] = ndkVer
144155

@@ -173,7 +184,7 @@ class axistools {
173184
def verList = []
174185

175186
// Scan installed cmake in $sdk_root/cmake
176-
File sdkCMakeDir = new File(sdkRoot + '/cmake')
187+
File sdkCMakeDir = new File("${sdkRoot}${File.separator}cmake")
177188
if (sdkCMakeDir.isDirectory()) {
178189
for (cmakeDir in sdkCMakeDir.listFiles()) {
179190
verList.add(cmakeDir.getName())
@@ -186,8 +197,8 @@ class axistools {
186197
}
187198

188199
// Collect cmakeBinDirs for search
189-
for(foundVer in verList){
190-
cmakeBinDir = sdkRoot + File.separator + "cmake" + File.separator + foundVer + File.separator + "bin"
200+
for(ver in verList){
201+
cmakeBinDir = sdkRoot + File.separator + "cmake" + File.separator + ver + File.separator + "bin"
191202
if(new File(cmakeBinDir).isDirectory()) {
192203
cmakeBinDirs.add(cmakeBinDir)
193204
}
@@ -222,7 +233,7 @@ class axistools {
222233
private static String findNDKInDir(ndkVer, allowNewerNdk, ndkDir, rets) {
223234
def found = null
224235
def properties = new Properties()
225-
File propertiesFile = new File("$ndkDir/source.properties")
236+
File propertiesFile = new File("$ndkDir${File.separator}source.properties")
226237
propertiesFile.withInputStream {
227238
properties.load(it)
228239
def foundNdkVer = properties['Pkg.Revision']

0 commit comments

Comments
 (0)