1 2// Set when building only part of the abis in the apk. 3def abiFiltersForWrapScript = [] 4 5android { 6 buildTypes { 7 profiling { 8 initWith debug 9 externalNativeBuild { 10 cmake { 11 // cmake Debug build type uses -O0, which makes the code slow. 12 arguments "-DCMAKE_BUILD_TYPE=Release" 13 } 14 } 15 packagingOptions { 16 // Exclude wrap.sh for architectures not built. 17 if (abiFiltersForWrapScript) { 18 def exclude_abis = ["armeabi", "armeabi-v7a", "arm64-v8a", 19 "x86", "x86_64", "mips", "mips64"] 20 .findAll{ !(it in abiFiltersForWrapScript) } 21 .collect{ "**/" + it + "/wrap.sh" } 22 excludes += exclude_abis 23 } 24 } 25 26 // Add lib/xxx/wrap.sh in the apk. This is to enable java profiling on Android O 27 // devices. 28 sourceSets { 29 profiling { 30 resources { 31 srcDir { 32 "profiling_apk_add_dir" 33 } 34 } 35 } 36 } 37 } 38 } 39} 40 41def writeWrapScriptToFullyCompileJavaApp(wrapFile) { 42 wrapFile.withWriter { writer -> 43 writer.write('#!/system/bin/sh\n') 44 writer.write('\$@\n') 45 } 46} 47 48task createProfilingApkAddDir { 49 for (String abi : ["armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mips64"]) { 50 def dir = new File("app/profiling_apk_add_dir/lib/" + abi) 51 dir.mkdirs() 52 def wrapFile = new File(dir, "wrap.sh") 53 writeWrapScriptToFullyCompileJavaApp(wrapFile) 54 println "write file " + wrapFile.path 55 } 56} 57 58