Android的摇篮 - 如何从包含根项目资产? [英] Android Gradle - How to include assets from the root project?
问题描述
我有以下项目结构
MyProject
|-- build.gradle
|-- client.private
|-- server.public
|-- app
| |-- build.gradle
| |-- lint.xml
| |-- proguard-project.txt
| |-- project.properties
| `-- src
和希望包括 client.private
和 server.public
文件进入最终的apk的资产文件夹但遗憾的是没能如愿。
and would like to include client.private
and server.public
files into the assets folder of the final apk but unfortunately not able to do so.
在以下我的应用程序/的build.gradle
...
android {
...
applicationVariants.all { variant ->
variant.mergeAssets.doLast {
copy {
from(['../client.private', '../server.public'])
into("${buildDir}/assets/${variant.dirName}")
}
}
}
}
但它只是将文件复制到应用程序/编译/资产/调试
,它不是打包在APK。
but it only copies the files to app/build/assets/debug
, its not packaged with the apk.
推荐答案
UPDATE(正确的解决方法)
终于来了!想我已经理解了评论的意思
Finally! think I have understood what the comment meant
android {
...
...
applicationVariants.all { variant ->
variant.mergeResources.doLast {
copy {
from (["../client.private", "../server.public"])
into ("$outputDir/raw")
}
}
}
}
旧液(作品,但不是一个理想的)
我一直没能找到一种方法,包括在sourceSets所以接下来的诀窍是尽量将文件复制到原材料
文件夹中的单个文件。
I haven't been able to find a way to include individual files in the sourceSets so the next trick was to try copying the files to the raw
folder
该解决方案是基于<一href=\"https://www.reddit.com/r/androiddev/comments/3femjd/including_your_readme_file_to_your_resource/\"相对=nofollow>这个 reddit的线程
The solution is based on this reddit thread
task copyKeyStores(type: Copy) {
from files(["../client.private", "../server.public"])
into 'src/main/res/raw'
}
tasks.copyKeyStores.execute()
注意:按<一个href=\"https://www.reddit.com/r/androiddev/comments/3femjd/including_your_readme_file_to_your_resource/ctoaoxo\"相对=nofollow>的意见之一,在reddit的线程的,有一个更好的办法,但我摸不清吧。
Note: As per one of the comments in the reddit thread, there is a better way but I am unable to figure it out.
这篇关于Android的摇篮 - 如何从包含根项目资产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!