我可以在构建时使用Ant在我的Android项目中设置一些静态变量吗?(Can I use Ant to set some static variables in my Android project

系统教程 行业动态 更新时间:2024-06-14 16:55:57
我可以在构建时使用Ant在我的Android项目中设置一些静态变量吗?(Can I use Ant to set some static variables in my Android project when building?)

我想用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); } }

更多推荐

本文发布于:2023-04-10 11:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/8b65b178fb0d55caeddef505c8444510.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   静态   项目   Android   Ant

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!