如何使用 android gradle-experimental 来限制目标平台?

How to limit target platform with android gradle-experimental?

当 运行 我的 android 应用程序 Android Studio 打印错误时:

Error:Execution failed for task ':app:processAndroidArmDebugJniLibs'.
> java.io.FileNotFoundException: <path here>\distribution\wb\lib\x86\libwb.so (The system cannot find the path specified)

它试图访问 x86 库,但我试图将目标平台限制为 arm 平台。如果我在 app.gradle(gradle-实验)文件中用 armeabi 替换 ${targetPlatform.getName()} 错误就消失了:

model {
repositories {
    libs(PrebuiltLibraries) {
        wb {
            binaries.withType(SharedLibraryBinary) {
                sharedLibraryFile = file("${lib_distribution_root}/wb/lib/${targetPlatform.getName()}/libwb.so")
            }
        }
    }
}
android {
    // ...
    sources {
        main {
            jniLibs {
                dependencies {
                    library "wb"
                }
            }
        }
    }
    productFlavors {
        create("arm") {
            ndk.abiFilters.add("armeabi")
        }
    }
}
// ...

如何修复构建以便仅使用 arm 库?

您可以在 build.gradle 中添加 ndk.abiFilters:


    android {
        ....
        defaultConfig {
        ndk {
            abiFilters 'armeabi'
            }
        }
        ....
    }