来自单个源代码的多个 Android 应用程序包 .apk 文件 [英] Multiple Android Application Package .apk files from single source code

查看:22
本文介绍了来自单个源代码的多个 Android 应用程序包 .apk 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个 Android 构建系统过程、命令行或 Eclipse,从单个源代码库生成多个 .apk 文件.造成这种情况的一些常见原因 - 为具有不同要求的市场提供特定版本或免费和付费版本.

I would like an Android build system procedure, command line or Eclipse, to generate several .apk files from a single source codebase. Some common reasons for this - having specific versions for markets with different requirements or a free and paid version.

这个问题不是关于:

  • 将共享代码打包到 Android 库 或进入外部 Java jar

  • Packaging shared code into Android libraries or into external Java jars

生成调试版本与 签名版本 .apk

Google 您可能需要创建为您打算发布的每个 APK 单独的 Android 项目,以便您可以分别适当地开发它们.您可以通过简单地复制现有项目并给它一个新名称来实现这一点."然后他们好心地建议使用我理解的库.然后,他们顺便提到了我真正想要的:一个可以根据构建配置输出不同资源的构建系统"

Google says "you probably need to create separate Android projects for each APK you intend to publish so that you can appropriately develop them separately. You can do this by simply duplicating your existing project and give it a new name." Then they kindly suggest using libraries, which I understand. Then, they mention in passing exactly what I do want: "a build system that can output different resources based on the build configuration"

  • 我知道要在 JAVA 中完成条件编译,可以关闭public static final"变量.在 build.xml 中有一个调整示例这样的值.请提供任何更完整的 Android Ant 构建配置示例或指向现在正在执行此操作的 OSS 项目的链接?顺便说一句,build.xml 是自动生成的,但我见过有人破解它,那么它是如何工作的?

  • I know that to accomplish conditional compilation in JAVA one can key off a 'public static final' variable. There is an example of tweaking such a value in build.xml. Any more complete example of an Android Ant build configuration for this or a link to an OSS project doing that now, please? BTW, build.xml is auto-generated, but I have seen people hacking it, so how does that work?

在 Manifest.xml 中声明的包名称为 package="com.example.appname",如果需要发出多个不同名称的 .apk,是否每个都需要一个单独的项目?

With the package name declared in Manifest.xml as package="com.example.appname", if one needs to emit multiple .apks that vary that name, is one stuck with a separate project for each?

推荐答案

我从一个单一的源代码树中生成了 2 个不同的 APK(演示版和生产版),并进行了 3 次小修改:

I'm generating 2 different APK's (demo and production) from one single source tree with 3 small modifications:

1) 我有 public static final DEMO=true;//false; 在我的 Application 类中,并根据该值我用来在演示/生产功能之间切换代码

1) I have public static final DEMO=true; //false; in my Application class and depending on that value I used to switch code between demo/production features

2) 有 2 个主要活动,例如:

2) There are 2 main activities, like:

package mypackage;
public class MyProduction extends Activity 
{
    //blah-blah
}

package mypackage.demo;
public class MyDemoActivity extends mypackage.MyProductionActivity
{
    //blah-blah
}

3) 最后是 2 个独立的 AndroidManifest.xml 文件,它们指向不同的启动器活动,具体取决于演示/生产切换

3) And in the end 2 separate AndroidManifest.xml files which points to different launcher activities depending on demo/production switch

我正在手动在 2 个 APK 之间切换,但在编写小型 ANT 任务以在它们之间自动切换时没有看到任何困难

I'm switching between 2 APK's manually, but see nothing difficult in writing small ANT task to switch between them automatically

这篇关于来自单个源代码的多个 Android 应用程序包 .apk 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆