I found a solution by gradle, hope it helps whoever meets the same situation.
Adding the following task and task dependency in your module's build.gradle, and replace your actual file path in the example, then rebuild your apk. It should solve the problem.
task put_files_in_META_INF {
def resDir = new File(buildDir, 'generated/files_for_META_INF/')
def destDir = new File(resDir, 'META-INF/')
// THIS IS KEY: Add resDir as a resource directory so that it is
// automatically included in the APK
android {
sourceSets {
main.resources {
srcDir resDir
}
}
}
doLast {
destDir.mkdirs()
copy {
into destDir
from <SOURCE_LOCATION_OF_LICENSE_FILE>
}
}
}
// Specify when put_files_in_META_INF should run
project.afterEvaluate {
tasks.findAll { task ->
task.name.startsWith('merge') && task.name.endsWith('Resources')
}.each { t -> t.dependsOn put_files_in_META_INF }
}
Refs:
https://discuss.gradle.org/t/add-generated-file-to-meta-inf/11831/7