Gradle How to exclude files from apk

2019-02-19 04:49发布

问题:

I store my keystore at my assets directory. How can exclude it in the build to create the .apk?

I tried in that way but still there:

android {
    ...
    packagingOptions {
            ...
            exclude 'META-INF/LICENSE.txt'
            ...
            exclude 'assets/keystore'
    }
}

It exclude the LICENSE.txt but not the keystore

回答1:

Try with next:

    ...
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
    }
}

android.applicationVariants.all { variant ->
    //if (variant.name.contains('Release')) { // exclude source and sourcemap from release builds
    def rmkeystore = task("delete${variant.name}.rmkeystore", type: Delete) {
        delete "${buildDir}/intermediates/assets/${variant.dirName}/keystore"
    }
    variant.mergeAssets.finalizedBy rmkeystore
    //}
}

Ref: https://stackoverflow.com/a/29168827/717267



回答2:

This could help.

Or Simply:

exclude '**/assets/keystore'