Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling externalNativeBuild with ABI split

I've switched to cmake build system from ndk-build. But can't get APK split function to work.

Here is my app build.gradle file

The result of the build is only one file - foo.bar-armeabi-v7a-release-1.5.1.apk.
If I'm building an app for x86 emulator, the result is foo.bar-x86-release-1.5.1.apk

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    jcenter()
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileOptions.encoding = 'ISO-8859-1'
    compileSdkVersion CompiledSdkVersion
    buildToolsVersion BuildToolsVersion

    defaultConfig {
        applicationId "foo.bar"
        minSdkVersion MinSdkVersion
        targetSdkVersion TargetSdkVersion
        versionCode VersionCode
        versionName VersionName
        vectorDrawables.useSupportLibrary = true

        externalNativeBuild {
            cmake {
                cppFlags "-fexceptions", "-std=c++11"
            }
        }

        ndk {
            abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
        }
    }

    signingConfigs {
        release {
            storeFile file("..\\release.keystore")
        }
    }

    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
    }

    splits {
        abi {
            enable true
            reset()
            include "armeabi", "armeabi-v7a", "arm64-v8a", "mips", "mips64", "x86", "x86_64"
            universalApk true
        }
    }

    project.ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, 'mips': 5, 'mips64': 6, 'x86': 8, 'x86_64': 9]
    android.applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.versionCodeOverride = project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.FilterType.ABI), 0) * 1000000 + android.defaultConfig.versionCode
            output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace(".apk", "-${variant.versionName}.apk"))
        }
    }

    externalNativeBuild {
        cmake {
            path 'src/main/jni/CMakeLists.txt'
        }
    }
}

crashlytics {
    enableNdk false // too many reports for third-party modules
    androidNdkOut '.externalNativeBuild/cmake/release'
    androidNdkLibsOut 'src/main/libs'
}

dependencies {
    compile project(':common-sources')
    compile project(':chess-board-library')
    compile project(':number-picker')

    compile files('libs/kxml2-2.3.0.jar')
    compile files('libs/StartADLib-1.0.1.jar')

    compile Dependencies.appCompat
    compile Dependencies.cardView
    compile Dependencies.firebaseAds
    compile Dependencies.googleAnalytics
    compile Dependencies.googlePlus
    compile Dependencies.googleGames

    compile(Dependencies.crashlytics) {
        transitive = true
    }
    compile(Dependencies.crashlyticsNdk) {
        transitive = true
    }
}

apply plugin: 'com.google.gms.google-services'

P.S. Please vote up my issue in Google's bug tracker if you can reproduce the error, but can't find the solution.

like image 688
Artem Mostyaev Avatar asked Oct 24 '16 09:10

Artem Mostyaev


2 Answers

Looks like this is a bug in build-tools. The ABI Split doesn't work even with the old ndk-build.

During the research I've found a good workaround - launch build right from the command line.

gradlew assembleDebug

or

gradlew assembleRelease

Command needs to be launched from the project's root directory.

Much thanks for this sudden comment :)

like image 103
Artem Mostyaev Avatar answered Nov 20 '22 10:11

Artem Mostyaev


It looks like your problem is in your variants.outputs.each code. For one thing, getFilter only takes one argument. (See the Output class implementation.)

See this post for why you should not use com.android.build.OutputFile.ABI (use OutputFile.FilterType.ABI instead). This issue caused a similar failure of split APKs for that poster.

like image 1
Hod Avatar answered Nov 20 '22 12:11

Hod