我想用Ant自动化我的Android项目构建。 目前,我必须在其中一个类中更改一些静态字符串和布尔字段,以用于不同市场的同一应用程序的不同类型的版本。
是否可以使用Ant设置这些变量,而无需复制带有一些奇怪标记的文件? 我希望能够继续使用Eclipse中的文件。
I would like to automate my Android project building with Ant. Currently I have to change some static String and Boolean fields in one of the classes for different kind of versions of the same app for different markets.
Is it possible to set these variables with Ant, without resorting to copying a file with some strange markers in it? I want to be able to keep using the files in Eclipse.
最满意答案
你可以 ,但你不应该。 不要让你的Ant构建文件搞乱代码; 它导致难以发现的奇怪和混乱的错误。
相反,使用java Properties 。
这是一个如何在static块中初始化static final的一个小例子:
class Junk { public static final int j ; static { // Use java.lang.Properties here to get the values j = 42; } public static void main(String[] argv){ System.out.printf("The answer is %d\n" , j); } }You can, but you shouldn't. Don't make your Ant build file mess with the code; it leads to strange and confusing errors that are hard to find.
Instead, use java Properties.
Here's a little example of how a static final can be initialized in a static block:
class Junk { public static final int j ; static { // Use java.lang.Properties here to get the values j = 42; } public static void main(String[] argv){ System.out.printf("The answer is %d\n" , j); } }更多推荐
发布评论