Android Studio 3.2.1解决错误信息"ABIs [armeabi] are not supported for platform. Supported ABIs are [arm64-v8a, armeabi-v7a, x86, x86_64]."

在用Android Studio 3.2.1导入以前的项目,进行编译的时候,报告如下错误信息:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> ABIs [armeabi] are not supported for platform. Supported ABIs are [arm64-v8a, armeabi-v7a, x86, x86_64].

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s

问题发生的原因在于以前的代码在build.gradle中指定了abiFilters 'armeabi',但是从NDK r17版本开始,已经不支持"armeabi、mips、mips64"这三种ABI了。

虽然可以简单的修改成abiFilters 'armeabi-v7a',来解决问题,但是我们更希望能有一个办法,在老版本的支持abiFilters 'armeabi'NDK上继续使用abiFilters 'armeabi'进行编译,用来兼容老设备。而在只支持abiFilters 'armeabi-v7a'的设备上,我们使用abiFilters 'armeabi-v7a'保证能编译通过。

我们通过执行NDK目录下的ndk-which输出的支持的ABI列表的方式获取当前的NDK是否支持abiFilters 'armeabi',如果不支持,我们就设置为abiFilters 'armeabi-v7a'

具体的操作如下图所示:

习惯于复制黏贴的懒人们,可以在下面复制代码:

def ndkWhich = new File(getNdkDirectory(),"ndk-which")
// from NDK r17 "armeabi、mips、mips64" not supported
try {
    def ndkWhichExec = ndkWhich.toString().execute() //ndk-which not exists cause exception
    def abiOutput = new ByteArrayOutputStream()
    ndkWhichExec.waitForProcessOutput(abiOutput, null)
    abiOutput = abiOutput.toString().toUpperCase()
    if (abiOutput.contains('USAGE:') && abiOutput.contains("ABI")) {
        if (abiOutput.contains("'armeabi'")) {
            abiFilters 'armeabi'
        } else {
            abiFilters 'armeabi-v7a'
        }
    } else {
        abiFilters 'armeabi'
    }
} catch (Exception  e) {
    abiFilters 'armeabi'
}

参考链接


发布者

《Android Studio 3.2.1解决错误信息"ABIs [armeabi] are not supported for platform. Supported ABIs are [arm64-v8a, armeabi-v7a, x86, x86_64]."》上有2条评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注