为 NDK 构建指定目标架构

imb*_*imb 4 c++ android android-ndk

我正在尝试使用 NDK 构建一个包含本机代码的 Android 应用程序。我正在使用 cmake,因为它似乎是本机代码的首选构建系统。链接期间构建失败,我收到以下消息,用于链接的预构建库:“添加符号时出错:文件格式错误”。查看正在使用的工具链,它使用 mips64el-linux-android-4.9。在库上调用 objdump 将格式显示为“文件格式 elf64-x86-64”,这正是我想要的。我如何告诉 Android Studio 为 x86_64 构建应用程序,以便它使用正确的工具链?我尝试将以下内容添加到我的应用程序的 build.gradle 文件中,但这并没有改变任何东西:

splits {
    abi {
        enable true
        reset()
        include "x86_64"
    }
}
Run Code Online (Sandbox Code Playgroud)

imb*_*imb 6

经过更多的实验,我能够通过向我的 buildTypes 添加一个带有 abiFilters 属性的 ndk 块来实现它。例如:

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        ndk {
            abiFilters "x86_64"
        }
    }
    debug {
        ndk {
            abiFilters "x86_64"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)