简体   繁体   English

如何从演示应用程序中的库项目中导入一些资源,而不是其他资源

[英]How to import some resources and some not from a library project in a demo app

I am creating two versions of my app; 我正在创建两个版本的应用程序; the full and the demo one. 完整版和演示版。 The full one has over 500 sound files in the raw folder. 完整的原始文件夹中有500多个声音文件。 The demo one idealy should import everything from resources but I only want about 33% of the sound files otherwise the size of the demo one will be the same as the full one. 理想的演示示例应该从资源中导入所有内容,但我只需要大约33%的声音文件,否则演示示例的大小将与完整的演示文件相同。

Is there a way to do this using a library project, so that I don't have to clone almost everything as that would make much more difficult to edit the code or image resources later? 有没有一种使用库项目来执行此操作的方法,这样我就不必克隆几乎所有内容,因为那样会使以后编辑代码或图像资源变得更加困难?

I've used the library project before, but I am not sure if I can partially import resources. 我之前使用过库项目,但是不确定是否可以部分导入资源。 One idea is not to import resources at all but only the code from the library, while the resources would be duplicated in these two versions. 一种想法是根本不导入资源,而仅导入库中的代码,而在这两个版本中资源将重复。

You probably couldn't do this with Eclipse, but if you build your app using ant you could probably do this with only one main project without using library project. 您可能无法使用Eclipse做到这一点,但是如果您使用ant来构建应用程序,则可能仅使用一个主项目就可以做到这一点,而无需使用库项目。

Here's how I would do it, setup the project so that you can build the app from the command line. 我将按照以下方法进行操作,设置项目,以便您可以从命令行构建应用程序。 eg 'ant release' should build the and sign the release app for you automatically. 例如,“ ant release”应构建并自动为您签名发布应用。

Next add two new targets in your build.xml file: 'release_full', 'release_demo'. 接下来,在您的build.xml文件中添加两个新目标:“ release_full”,“ release_demo”。 The 'release_demo' target will first clean the raw folder, and then copy the demo sound files in there and then proceed with the normal 'release' build. “ release_demo”目标将首先清理原始文件夹,然后在其中复制演示声音文件,然后继续进行正常的“ release”构建。 The 'release_full' target does the same thing, but it will copy all the sound files into raw folder. “ release_full”目标执行相同的操作,但是它将所有声音文件复制到原始文件夹中。 In the new targets, make sure you rename the apk file once they're build. 在新目标中,请确保在构建apk文件后将其重命名。 eg rename from MyApp.apk to 'MyAppFull.apk' or 'MyAppDemo.apk'. 例如,从MyApp.apk重命名为“ MyAppFull.apk”或“ MyAppDemo.apk”。

When you're ready to distribute your app, issue 'ant release_demo' and 'ant release_full' and you will have two apks, one for demo, and one for release. 当您准备发布您的应用程序时,发出“ ant release_demo”和“ ant release_full”,您将有两个apk,一个用于演示,一个用于发布。

Of course, you need to setup the build.xml such that it knows where to find your sound files that are not part of your Android source folder, where to copy them into. 当然,您需要设置build.xml,以便它知道在哪里可以找到不属于Android源文件夹的声音文件,以及将它们复制到何处。 All these can be defined by ant property task. 所有这些都可以通过ant属性任务来定义。

To copy files use <copy> task, to delete files use <delete> task.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM