Android Studio 3.2.1解決錯誤資訊"ABIs [armeabi] are not supported for platform. Supported A...
在用 Android+Studio/">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' }
參考連結
- ofollow,noindex" target="_blank">How to use exec() output in gradle
- Execute shell script in Gradle
- Projucer-generated Android Studio project build.gradle contains unsupported ndk abiFilter ‘armeabi’
- "No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android"