@@ -151,6 +151,9 @@ android {
151
151
' -DANDROID_PROJECT_DIR=' + " ${ android_project_dir} " ,
152
152
' -DENABLE_ASAN=false' ,
153
153
' -DBUILD_RUNTIME_API=' + " ${ buildRuntimeApi} "
154
+ if (project. hasProperty(' enableASan' ) && " true" == project. getProperty(' enableASan' )) {
155
+ cppFlags " -fsanitize=address -fno-omit-frame-pointer"
156
+ }
154
157
}
155
158
}
156
159
}
@@ -264,11 +267,10 @@ if(file('../license/LICENSE').exists()){
264
267
}
265
268
preBuild. dependsOn licenseFormat
266
269
}
267
-
270
+ def ndkDir = ' '
268
271
task checkNdkVersion () {
269
272
def rootDir = project. rootDir
270
273
def localProperties = new File (rootDir, " local.properties" )
271
- def ndkDir = ' '
272
274
if (localProperties. exists()) {
273
275
Properties properties = new Properties ()
274
276
localProperties. withInputStream { instr ->
@@ -360,7 +362,45 @@ artifactory {
360
362
}
361
363
}
362
364
}
363
-
365
+ def asanAbi = project. hasProperty(' asanAbi' ) ? project. getProperty(' asanAbi' ) : ' arm64-v8a'
366
+ task clearASanLibs (type : Delete ){
367
+ delete project. android. sourceSets. main. resources. srcDirs
368
+ delete fileTree(project. android. sourceSets. main. jniLibs. srcDirs[-1 ]) {
369
+ include ' **/libclang_rt.asan-*-android.so'
370
+ }
371
+ }
372
+ task copyWrapScript (type : Copy ,dependsOn : clearASanLibs) {
373
+ if (project. hasProperty(' enableASan' ) && " true" == project. getProperty(' enableASan' )) {
374
+ from ' ../../scripts/wrap.sh'
375
+ into new File (project. android. sourceSets. main. resources. srcDirs[-1 ], " lib" )
376
+ eachFile {
377
+ it. path = " ${ asanAbi} /${ it.name} "
378
+ }
379
+ }
380
+ }
381
+ task copyASanLib (type : Copy ,dependsOn : copyWrapScript){
382
+ if (project. hasProperty(' enableASan' ) && " true" == project. getProperty(' enableASan' )) {
383
+ def ndkPath = ndkDir == ' ' ? System . getenv(" ANDROID_NDK_HOME" ): ndkDir
384
+ def dir = ndkPath + ' /toolchains/llvm/prebuilt/'
385
+ def renamedAbi = asanAbi
386
+ if (asanAbi == " armeabi-v7a" || asanAbi == " armeabi" )
387
+ renamedAbi = " arm"
388
+ if (asanAbi == " arm64-v8a" )
389
+ renamedAbi = " aarch64"
390
+ if (asanAbi == " x86" )
391
+ renamedAbi = " i686"
392
+ new File (dir). eachFileRecurse { file ->
393
+ if (file. name == ' libclang_rt.asan-' + renamedAbi + ' -android.so' )
394
+ from file. absolutePath
395
+ into project. android. sourceSets. main. jniLibs. srcDirs[-1 ]
396
+ eachFile {
397
+ it. path = " ${ asanAbi} /${ it.name} "
398
+ }
399
+ includeEmptyDirs = false
400
+ }
401
+ }
402
+ }
403
+ preBuild. dependsOn copyASanLib
364
404
365
405
afterEvaluate { project ->
366
406
transformNativeLibsWithStripDebugSymbolForRelease << {
0 commit comments