Search code examples
androidsplitarchitecture

Error: Could not find EOCD, after adding "splits" in Android


I am using the following splits code in my gradle to reduce APK size:

splits {
        abi {
            // Enable ABI split

        enable true

        // Clear list of ABIs
        reset()

        // Specify each architecture currently supported by the Video SDK
        include "armeabi-v7a", "arm64-v8a", "x86", "x86_64"

        // Specify that we do not want an additional universal SDK
        universalApk false
    }
}

When I run the app, the APK is generated fine, with reduced size and runs on Emulator.

But when I try to build APK file from Build > Build bundles/apks like enter image description here

I get this error:

Execution failed for task ':app:packageAbcDebug'.
> A failure occurred while executing com.android.build.gradle.tasks.PackageAndroidArtifact$IncrementalSplitterRunnable
   > Could not find EOCD in '....apk'

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

I only wanted to exclude "x86" architectures, to reduce the APK size and need to send the APK to my client. How do I fix this?


Solution

  • May be its late but here is the solution with reason for it to work.

    Since we are using splits to create apks for each architecture build system needs a different name for each apk being generated.

    Best solution is to provide a dynamic way of generating apk names.

    Just go to app level build.gradle file Add rules for release/debug build variants in buildTypes block inside android block like this

    buildTypes {
            release {
                minifyEnabled true
                shrinkResources true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                applicationVariants.all { variant ->
                    variant.outputs.all { output ->
                        project.ext { appName = 'YourApkName' }
                        outputFileName = "${appName}-${output.getFilter(OutputFile.ABI)}-${variant.name}-${variant.versionName}.apk"
                    }
                }
            }
        }
    

    Explaination : Here the apk name is appended by the ABI name that helps build system identify the apks for each architectures.