这是来自我的blog post,它描述了如何使用库项目构建免费/付费版本。
通常,您将创建三个项目;免费项目、付费项目和图书馆项目。
然后您将在您的库项目中创建一个 Build.java 文件,如下所示:
public class Build {
public final static int FREE = 1;
public final static int PAID = 2;
public static int getBuild(Context context){
return context.getResources().getInteger(R.integer.build);
}
}
现在,您将在每个项目中创建一个 build.xml 资源:
[库]/resources/values/build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<integer name="build">0</integer>
</resources>
[免费]/resources/values/build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<integer name="build">1</integer>
</resources>
[付费]/resources/values/build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<integer name="build">2</integer>
</resources>
然后您将能够在运行时检查版本:
if (Build.getBuild(context) == Build.FREE){
// Do the free stuff
} else {
// Do the paid stuff
}
blog post 详细说明了在 Linux 命令行中从头开始创建项目所需的确切步骤。