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