Search code examples
androidgradlebuildarchitecturebuild.gradle

Separate build for each architecture but the resulting APK files are identical?


I want individual builds for each architecture, to distribute them separately. So I did some research and for example had a look at Android - build separate APKs for different processor architectures and linked article https://androidbycode.wordpress.com/2015/06/30/android-ndk-version-code-scheme-for-publishing-apks-per-architecture/ and I seem to follow those steps, as far as I can tell. Following these resources, I added the following to my build.gradle:

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

With those changes, I'm indeed getting individual APKs for each architecture. However, the resulting files are identical:

$ md5sum *
9673c9c50c3d2d8dbe02b073676b90d4  app-arm64-v8a-release-unsigned.apk
9673c9c50c3d2d8dbe02b073676b90d4  app-armeabi-v7a-release-unsigned.apk
9673c9c50c3d2d8dbe02b073676b90d4  app-x86_64-release-unsigned.apk
9673c9c50c3d2d8dbe02b073676b90d4  app-x86-release-unsigned.apk

How is this possible? What am I doing wrong? Unfortunately, I don't have devices for each architecture, to test. But it seems wrong to me that the build should yield the same checksum for each architecture.

In case it's relevant, here is my full build.gradle: https://pastebin.com/v6Ya3Kan


Solution

  • APK files are just zip files. You can unzip them to inspect. You can also use the APK Analyzer to see what they contain.

    If your Android project only includes Java/Kotlin code, that code will be compiled into dex files which doesn't depend on the CPU architecture of the device.

    If you have C/C++ code (for games, performance computation, cross platform libraries) that will be processed via the Android Native Development Kit (NDK) into CPU architecture libraries which will need to included in the appropriate APK files.