background

Recently, the major domestic application markets collectively require developers to provide 64-bit APK, which requires us to provide ARMV8-64-bit native libraries for each SO library in the project. However, many SO libraries just look at their names, and we don’t know which third party introduced them, so we can’t find the corresponding V8 library, or they are in the output APK package. If you find a Native library from an unknown source, you can quickly locate it by doing the following, or analyze which Native library it belongs to based on the AAR package it belongs to.

In actual combat

Apk is generated by Gradle. Gradle is involved in all the details of apK formation, so we can probe everything about APK from Gradle.

Find Gradle Task name

Gradle builds Apk using a set of tasks to implement the final build. The first step is to find out in your project which task your Gradle is using to implement the native library into Apk. Typically, the name of this task must contain a keyword like “Native Wibs”.

Paste the following code into the app’s build.gradle end

tasks.whenTaskAdded { task ->
    println("> > >"+task.name)
}
Copy the code

You can type the names of all the tasks in your project that are involved in gradle builds. You are sure to find that task. This task is called mergeDebugNativeLibs or merge “Flavor” DebugNativeLibs. Contains (NativeLibs) contains(Task.name. contains)

2. Print the source of the so library according to the name

Paste the following code into the app’s build.gradle end

tasks.whenTaskAdded { task ->
    if (task.name == 'mergeDebugNativeLibs') {
        task.doFirst {
           println("------------------- find so files start -------------------")
           it.inputs.files.each { file ->
                printDir(new File(file.absolutePath))
            }
           println("------------------- find so files end -------------------")}}}def printDir(File file) {
    if(file ! =null) {
        if (file.isDirectory()) {
            file.listFiles().each {
                printDir(it)
            }
        } else if (file.absolutePath.endsWith(".so")) {
            println "find so file: $file.absolutePath"}}}Copy the code

Third, analyze the source

After the above operation, the source of the so library used in the project will be printed, they are usually located in the Gradle cache, usually with the AndroidManifest, JAR, etc., by opening these things, get the package name, class name, etc., you can help you locate the so library belongs to which third party.