Android 库资源文件夹不会被复制
我正在创建一个 Android 库,它有一个包含图像的 assets
文件夹。 当我在另一个项目中使用它时,资产不会被复制。
还有其他人遇到这个问题吗?
I am creating an Android library and it has an assets
folder with images.
When I use it in another project the assets doesn't get copied.
Anyone else had this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
基于Gradle的新的Android构建系统支持库中的资源文件夹项目!
对于基于 ANT 的构建,这仍然是不可能的:
但是您可以
The new Android Build System that is based on Gradle supports asset folders in library projects!
With ANT based builds it's still not possible:
But you could
可以通过小修复将资源放入生成的库 jar 中:
将“custom_rules.xml”放入您的库项目主目录(靠近 build.xml):
这会将您的库资源打包到生成的库 jar 中。因此,这些资产将包含在您的应用程序的生成的 .apk 中。
在 OSX 上检查 Android SDK 工具修订版 21.1.0
It is possible to put assets into resulting library jar by small fix:
Put "custom_rules.xml" into you library project home (near the build.xml):
This will pack your library assets into you resulting library jar. As result, these assets will be included into resulting .apk of your application.
Checked on Android SDK Tools Revision 21.1.0 on OSX
在 Eclipse 和 ANT 中,您可以从多个项目引用相同的“assets”文件夹。
这允许您的源代码树拥有资产文件的单个副本,但将它们包含在多个 APK 中。
请参阅 Android:用于在 eclipse 中进行调试的目标 res 文件夹
从 ProjectA 我能够引用 ProjectB 中的 ..\ProjectA\Assets。
在 Eclipse 上(至少在 Windows 下,我还没有在 Linux 上尝试过),我必须创建一个新变量来引用 ..\ProjectA 并在“链接文件夹位置”中使用该变量。如果我尝试在“链接文件夹位置”中使用“..”,Eclipse 将不会接受它。
From Eclipse and ANT you can reference the same "assets" folder from multiple projects.
This allows your source tree to have a single copy of the assets files, but have them included in multiple APKs.
See Android: targeted res folders for debugging in eclipse
From ProjectA I was able to reference ..\ProjectA\Assets from ProjectB.
On Eclipse (under Windows at least, I've not tried on Linux yet), I had to create a new variable to reference ..\ProjectA and use that variable in "Linked Folder Location". If I attempted to use ".." in "Linked Folder Location" eclipse wouldn't accept it.
对于使用 IntelliJ IDEA 的用户,您可以更改应用程序模块的打包设置以包含相关资产。请注意,这是在 IntelliJ 社区版 14.0.2 版本上完成的。我的主应用程序模块现在继承了我的库项目的资产文件夹中的文件,就好像它们位于主项目中一样!
右键单击应用程序模块>打开模块设置。在模块上选择Android树节点>包装标签。选中“将依赖项中的资产包含到 APK 中”
注意:我从未使用过 Android Studio,但我猜想该应用程序中有类似的设置。
For those using IntelliJ IDEA, you can make a change to your application module's packaging settings to include depedent assets. Note, this was done on version 14.0.2 of IntelliJ Community edition. My main application module now inherits files form my library project's assets folder as if they were right in the main project!
Right click application module > Open Module SEttings. Select Android tree node on module > Packaging Tab. Check "Include assets from dependencies into APK"
Note: I've never used Android Studio, but I would guess there is a similar setting for this in that application.
首先创建android lib项目,创建后关闭。这将阻止自动构建
在 Windows Android 上使用 cmd 终端命令是批处理文件
将工具添加到路径
C:\Users\user_bss>PATH=%PATH%;C:\adt-bundle-windows-x86-20140321\sdk\tools
为 ant 生成 build.xml
android更新项目 -p C:\Users\user_bss\Documents\Workspace\SDKAdvanced -n SDKAdvanced
notepad custom_rules.xml 添加上面的代码不要忘记结束标记
运行“ant debug”或“ant release”来构建
你请参阅 bin 目录中的classes.jar,这是您的打包库
start by creating android lib project, close after creation. this'll prevert autobuild
use cmd terminal on windows android command is batch file
add tools to path
C:\Users\user_bss>PATH=%PATH%;C:\adt-bundle-windows-x86-20140321\sdk\tools
Generate build.xml for ant
android update project -p C:\Users\user_bss\Documents\Workspace\SDKAdvanced -n SDKAdvanced
notepad custom_rules.xml add the code from above don't forget end tag
run "ant debug" or "ant release" to build
you'll see classes.jar in bin dir this is your packed lib