How to choose different minSdkVersion for different android ABI?

Issue

I have Android app which builds armeabi-v7a and arm64-v8a. Here is the build.gradle:

apply plugin: 'com.android.library'

allprojects {
    repositories {
        jcenter()
        google()
    }
}

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        externalNativeBuild {
            cmake {
                // Linker flags and Visibility options keeps the size of the library small
                cppFlags "-stdc++11"
                arguments "-DANDROID_STLgnustl_static",
                          "-DANDROID_CPP_FEATURESrtti exceptions",
                          "-DANDROID_TOOLCHAINgcc"
            }
        }
    }

    buildTypes {
        release {
            ndk {
                abiFilters 'armeabi-v7a', 'arm64-v8a'
            }
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            externalNativeBuild {
                cmake {
                    cppFlags "-Wl,--exclude-libsALL -Wl,--gc-sections -fvisibilityhidden -fvisibility-inlines-hidden -ffunction-sections"
                }
            }
        }
        debug {
            ndk {
                abiFilters 'armeabi-v7a', 'arm64-v8a'
            }
        }
    }
    externalNativeBuild {
        cmake {
            path 'CMakeLists.txt'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}

I am using the minSdkVersion 21 to support arm64. I would like to change the minSdkVersion based on the abiFilters i.e., use 16 for v7 and use 21 for arm64.

Solution

You don’t need to do anything mentioned in the selected answer. Just set minSdkVersion 16 and the 64-bit ABIs will automatically use minSdkVersion 21 because that’s the lowest available API for 64-bit.

Answered By – Dan Albert

Leave a Comment