• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17                // Exclude wrap.sh for architectures not built.
18                if (abiFiltersForWrapScript) {
19                    def exclude_abis = ["armeabi", "armeabi-v7a", "arm64-v8a",
20                                        "x86", "x86_64", "mips", "mips64"]
21                            .findAll{ !(it in abiFiltersForWrapScript) }
22                            .collect{ "**/" + it + "/wrap.sh" }
23                    excludes += exclude_abis
24                }
25            }
26
27            // Add lib/xxx/wrap.sh in the apk. This is to enable java profiling on Android O
28            // devices.
29            sourceSets {
30                profiling {
31                    resources {
32                        srcDir {
33                            "profiling_apk_add_dir"
34                        }
35                    }
36                }
37            }
38        }
39    }
40}
41
42def writeWrapScriptToFullyCompileJavaApp(wrapFile) {
43    wrapFile.withWriter { writer ->
44        writer.write('#!/system/bin/sh\n')
45        writer.write('\$@\n')
46    }
47}
48
49task createProfilingApkAddDir {
50    for (String abi : ["armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mips64"]) {
51        def dir = new File("app/profiling_apk_add_dir/lib/" + abi)
52        dir.mkdirs()
53        def wrapFile = new File(dir, "wrap.sh")
54        writeWrapScriptToFullyCompileJavaApp(wrapFile)
55        println "write file " + wrapFile.path
56    }
57}
58
59