@@ -90,52 +90,76 @@ class VersionComparator implements Comparator<String> {
90
90
}
91
91
92
92
class axistools {
93
+
94
+ static String [] findNativeBuildTools (project , ndkVer = " 23.2.8568313" , cmakeVer = " 3.22.1+" ) {
95
+
96
+ // Detecting sdkRoot
97
+ def sdkRoot = null
98
+ Properties projProps = new Properties ()
99
+ try {
100
+ projProps. load(project. rootProject. file(" local.properties" ). newDataInputStream())
101
+ sdkRoot = projProps. getProperty(" sdk.dir" )
102
+ }
103
+ catch (Exception ex) {
104
+ ex. printStackTrace()
105
+ }
106
+
107
+ if (sdkRoot == null || ! new File (sdkRoot). isDirectory()) {
108
+ sdkRoot = Paths . get(" ${ System.env.ANDROID_SDK_ROOT} " ). toAbsolutePath(). toString()
109
+ if (! new File (sdkRoot). isDirectory()) {
110
+ throw new Exception (' android sdk not specified properly in local.properties or system env ANDROID_SDK_ROOT' )
111
+ }
112
+ }
113
+
114
+ def rets = new String [3 ] // ndkVer,ndkPath,cmakeVer
115
+ findNDK(sdkRoot, ndkVer, rets)
116
+ findCMake(sdkRoot, cmakeVer, rets)
117
+ return rets
118
+ }
119
+
93
120
/**
94
121
* Find suitable ndk for current project
95
122
* @param project The current android project
96
123
* @param ndkVer The required ndk version for current project
124
+ * @param rets
97
125
* @return
98
126
*/
99
- static String [] findNDK (project , ndkVer = " 23.2.8568313 " ) {
127
+ private static void findNDK (sdkRoot , ndkVer , rets ) {
100
128
def allowNewerNdk = null
101
129
if (ndkVer. endsWith(' +' )) {
102
130
allowNewerNdk = true
103
131
ndkVer = ndkVer. substring(0 , ndkVer. length() - 1 )
104
132
}
105
133
106
134
def ndkDirs = []
107
- def sdkRoot = Paths . get(" ${ System.env.ANDROID_SDK_ROOT} " )
108
- if (Files . exists(sdkRoot)) {
109
- File dir = new File (sdkRoot. toAbsolutePath(). toString() + ' /ndk' )
110
- if (dir. isDirectory()) {
111
- for (ndkDir in dir. listFiles()) {
112
- ndkDirs. add(ndkDir. toString())
113
- }
135
+ File dir = new File (" ${ sdkRoot} /ndk" )
136
+ if (dir. isDirectory()) {
137
+ for (ndkDir in dir. listFiles()) {
138
+ ndkDirs. add(ndkDir. toString())
114
139
}
115
140
}
116
141
117
142
/* Find suitable ndk in dirs */
118
- def rets = new String [2 ]
119
143
rets[0 ] = ndkVer
120
144
121
145
for (ndkDir in ndkDirs) {
122
146
if (findNDKInDir(ndkVer, allowNewerNdk, ndkDir, rets)) {
123
- return rets
147
+ return
124
148
}
125
149
}
126
150
127
151
println (" No installed ndk found, the gradle will install ndk: $ndkVer automatically" )
128
152
rets[1 ] = null
129
- return rets
130
153
}
131
154
132
155
/**
133
156
* Find suitable cmake for current project
134
157
* @param project The current android project
135
158
* @param cmakeVer The required cmake version of project
159
+ * @param rets
136
160
* @return
137
161
*/
138
- static String findCMake (project , String cmakeVer = " 3.10.2+ " ) {
162
+ private static void findCMake (sdkRoot , String cmakeVer , rets ) {
139
163
def allowNewerCMake = false
140
164
if (cmakeVer. endsWith(' +' )) {
141
165
allowNewerCMake = true
@@ -145,38 +169,27 @@ class axistools {
145
169
def cmakeBinDirs = []
146
170
147
171
def cmakeBinDir = null
148
- if (project != null ) {
149
- cmakeBinDir = getCMakeBinFromProjectLocal(project)
150
- if (cmakeBinDir != null ) {
151
- cmakeBinDirs. add(cmakeBinDir);
152
- }
153
- }
154
-
155
- def sdkRoot = Paths . get(" ${ System.env.ANDROID_SDK_ROOT} " )
156
172
157
- if (Files . exists(sdkRoot)) {
158
- def verList = []
173
+ def verList = []
159
174
160
- // Scan installed cmake in $sdk_root/cmake
161
- File sdkCMakeDir = new File (sdkRoot. toAbsolutePath(). toString() + ' /cmake' )
162
- if (sdkCMakeDir. isDirectory()) {
163
- for (cmakeDir in sdkCMakeDir. listFiles()) {
164
- verList. add(cmakeDir. getName())
165
- }
175
+ // Scan installed cmake in $sdk_root/cmake
176
+ File sdkCMakeDir = new File (sdkRoot + ' /cmake' )
177
+ if (sdkCMakeDir. isDirectory()) {
178
+ for (cmakeDir in sdkCMakeDir. listFiles()) {
179
+ verList. add(cmakeDir. getName())
166
180
}
181
+ }
167
182
168
- // Sort cmake verList
169
- verList. sort {a ,b ->
170
- return axistools. compareVersion(b, a)
171
- }
183
+ // Sort cmake verList
184
+ verList. sort {a ,b ->
185
+ return axistools. compareVersion(b, a)
186
+ }
172
187
173
- // Collect cmakeBinDirs for search
174
- sdkRoot = sdkRoot. toAbsolutePath(). toString()
175
- for (foundVer in verList){
176
- cmakeBinDir = sdkRoot + File . separator + " cmake" + File . separator + foundVer + File . separator + " bin"
177
- if (new File (cmakeBinDir). isDirectory()) {
178
- cmakeBinDirs. add(cmakeBinDir)
179
- }
188
+ // Collect cmakeBinDirs for search
189
+ for (foundVer in verList){
190
+ cmakeBinDir = sdkRoot + File . separator + " cmake" + File . separator + foundVer + File . separator + " bin"
191
+ if (new File (cmakeBinDir). isDirectory()) {
192
+ cmakeBinDirs. add(cmakeBinDir)
180
193
}
181
194
}
182
195
@@ -199,11 +212,11 @@ class axistools {
199
212
foundCMakeVer = cmakeVer
200
213
}
201
214
202
- return foundCMakeVer
215
+ rets[ 2 ] = foundCMakeVer
203
216
}
204
217
205
218
private static int compareVersion (String ver1 , String ver2 ) {
206
- return new VersionComparator (). compare(ver1, ver2);
219
+ return new VersionComparator (). compare(ver1, ver2)
207
220
}
208
221
209
222
private static String findNDKInDir (ndkVer , allowNewerNdk , ndkDir , rets ) {
@@ -256,9 +269,9 @@ class axistools {
256
269
int exitVal = proc. exitValue()
257
270
if (exitVal == 0 ) {
258
271
InputStream stdIn = proc. getInputStream();
259
- InputStreamReader isr = new InputStreamReader (stdIn);
260
- BufferedReader br = new BufferedReader (isr);
261
- String verLine = br. readLine();
272
+ InputStreamReader isr = new InputStreamReader (stdIn)
273
+ BufferedReader br = new BufferedReader (isr)
274
+ String verLine = br. readLine()
262
275
def verInfo = verLine. split(" \\ s" )
263
276
if (verInfo. length >= 3 ) {
264
277
def foundVer = verInfo[2 ]
@@ -288,37 +301,19 @@ class axistools {
288
301
return foundCMakeVer
289
302
}
290
303
291
- private static String getCMakeBinFromProjectLocal (project ) {
292
- String programName = getCMakeProgramName();
293
- Properties properties = new Properties ()
294
- try {
295
- properties. load(project. rootProject. file(" local.properties" ))
296
- def cmakeDir = properties. getProperty(" cmake.dir" )
297
- if (cmakeDir != null ) {
298
- def cmakeBin = " $cmakeDir /bin"
299
- if (new File (" $cmakeBin /$programName " ). isFile())
300
- return cmakeBin;
301
- }
302
- }
303
- catch (Exception ) {
304
- }
305
-
306
- return null
307
- }
308
-
309
304
private static String getCMakeBinFromPath () {
310
- String cmakeExecName = getCMakeProgramName();
305
+ String cmakeExecName = getCMakeProgramName()
311
306
def foundBinPath = null
312
307
Stream . of(System . getenv(" PATH" ). split(Pattern . quote(File . pathSeparator)))
313
308
.map(Paths ::get)
314
309
.anyMatch(path -> {
315
- def programPath = path. resolve(cmakeExecName);
310
+ def programPath = path. resolve(cmakeExecName)
316
311
boolean fileExist = Files . exists(path. resolve(cmakeExecName))
317
312
if (fileExist) {
318
313
foundBinPath = path. toAbsolutePath(). toString()
319
314
}
320
315
return fileExist
321
- });
316
+ })
322
317
323
318
return foundBinPath
324
319
}
@@ -332,7 +327,7 @@ class axistools {
332
327
}
333
328
334
329
private static boolean isWindows () {
335
- return System . getProperty(" os.name" ). toLowerCase(). contains(" windows" );
330
+ return System . getProperty(" os.name" ). toLowerCase(). contains(" windows" )
336
331
}
337
332
}
338
333
0 commit comments