How to reduce build variants of native library in

2020-07-07 10:11发布

问题:

In Android Studio 3.2.1 I had two build variants visible for my native library; Release and Debug. In 3.3 I get a combination of these and all ABIs. I don't want to build multiple APKs for all the ABIs.

The relevant parts of the native library project:

apply plugin: 'com.android.library'

android {
    defaultConfig {
        ndk {
            // Specifies the ABI configurations of your native
            // libraries Gradle should build and package with your APK.
            abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
        }
    }

    buildTypes {
        release {
        }
        debug {
        }
    }

    externalNativeBuild {
        ndkBuild {
            path 'jni/Android.mk'
        }
    }

    sourceSets {
        main {
            java.srcDir generatedSrcDir
        }
    }

    sourceSets {
        main {
            jni.srcDirs = []
        }
    }
}

Build warnings

Maybe unrelated, but I observed this warning in the Build log (actually twice in a row):

WARNING: ABIs [arm64-v8a,armeabi-v7a,armeabi] set by 'android.injected.build.abi' gradle flag contained 'ARMEABI' not targeted by this project.

How do I get back to the old behavior?

回答1:

Apparently this is an intentional change: see this issue.

According to the linked ticket, this is only "cosmetic"(ie a UI change); a full/fat .apk is still built.