Gradle如何从apk中排除文件

时间:2015-10-01 10:53:42

标签: android gradle

我将我的密钥库存储在我的资产目录中。如何在构建中排除它以创建.apk?

我试过这种方式,但仍然在那里:

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

它排除LICENSE.txt但不排除keystore

2 个答案:

答案 0 :(得分:2)

尝试下一步:

    ...
    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
    //}
}

参考:https://stackoverflow.com/a/29168827/717267

答案 1 :(得分:-2)

This可以提供帮助。

或者简单地说:

exclude '**/assets/keystore'