You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

构建全量ABI但仅打包指定子集的配置问题求助

Hey there! Let's tackle this ABI filtering issue you're facing. I've run into similar headaches before, so here are some practical fixes to get your desired ABI subset packaged correctly into your app:

1. Double-check your Gradle configuration placement

It’s super easy to put the ABI filter in the wrong block, which is the most common cause of this issue. You need to split your configuration into two parts:

  • Build all ABIs via your external native build setup (cmake/ndkBuild)
  • Filter which ABIs get packaged into the APK using abiFilters in the right Gradle section

Here’s a correct example:

android {
    defaultConfig {
        // This controls WHICH ABIs get PACKAGED into the APK
        ndk {
            abiFilters 'x86' // Only include x86 here
        }

        // This controls WHICH ABIs get BUILT (we build all)
        externalNativeBuild {
            cmake {
                arguments "-DANDROID_ABI=all"
                // Or list all ABIs explicitly: "-DANDROID_ABI=x86,x86_64,armeabi-v7a,arm64-v8a"
            }
        }
    }
}

The key here is that abiFilters lives under defaultConfig (or a specific build variant), not inside the externalNativeBuild block.

2. Wipe build caches and rebuild from scratch

Old build artifacts can cling to your project and ignore new configuration changes. Try these steps:

  • In Android Studio: Go to Build > Clean Project, then Build > Rebuild Project
  • Or use the command line: ./gradlew clean assembleDebug (swap Debug with your target build variant if needed)

3. Verify variant-specific configurations

If you’re setting abiFilters for a specific build type (like Release) or product flavor, make sure it’s not being overridden by the defaultConfig. For example:

android {
    buildTypes {
        release {
            ndk {
                abiFilters 'x86' // Only apply this to release builds
            }
        }
    }
}

4. Check for manually added .so files in jniLibs

If you’ve copied .so files directly into src/main/jniLibs, Gradle will default to packaging all of them. To fix this, add an exclusion rule in your source sets:

android {
    sourceSets {
        main {
            jniLibs {
                exclude '**/armeabi-v7a/**', '**/arm64-v8a/**', '**/x86_64/**'
            }
        }
    }
}

5. Validate the final APK

After building, rename your APK to a .zip file and extract it. Check the lib folder inside—you should only see the x86 directory if everything worked. If other ABIs are still present, go back and recheck your configuration blocks for typos or misplaced settings.

内容的提问来源于stack exchange,提问作者Jon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:47:00