I want to have a final variable that is true when I run the Debug version of my project, and false when I run the Run version. I understand I can do this with build configurations but have no idea how to set this up in Eclipse. There don't appear to be any tutorials or questions on Stack Exchange regarding defining variables specifically.

我希望有一个最终变量,当我运行我的项目的Debug版本时是真的,而当我运行Run版本时是false。我知道我可以使用构建配置来做到这一点但不知道如何在Eclipse中进行设置。在Stack Exchange上似乎没有关于具体定义变量的任何教程或问题。

I'm compiling Java in Eclipse Classic 4.2, creating an Android app using the ADT plugin.

我正在Eclipse Classic 4.2中编译Java,使用ADT插件创建一个Android应用程序。


EDIT: Per @Xavi, I set up the following:

编辑:Per @Xavi,我设置了以下内容:

    try {
        String line = null;
        java.lang.Process p = Runtime.getRuntime().exec("getprop debugging");
        BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
        while ((line = input.readLine()) != null) {
            Log.d("Property:", line); //<-- Parse data here.
        }
        input.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

And in the "Additional Emulator Command Line Options" field of the Target tab of the Debug Configurations window, I've entered:

在Debug Configurations窗口的Target选项卡的“Additional Emulator Command Line Options”字段中,我输入了:

-prop debugging=true

Unfortunately it looks like this only works in emulator mode. It doesn't print anything when running on my phone. (It works fine running on an emulator.)

不幸的是,它看起来只适用于模拟器模式。在手机上运行时,它不会打印任何内容。 (它在模拟器上运行良好。)


EDIT: Per @Sharks I found some links that seem relevant, but I don't know how to apply them to my situation:

编辑:Per @Sharks我发现一些似乎相关的链接,但我不知道如何将它们应用于我的情况:

  • Android - use ant to create build configurations that change configuration values
  • Android - 使用ant创建更改配置值的构建配置
  • http://www.bonobolabs.com/fuck-the-android-build-process/
  • http://www.bonobolabs.com/fuck-the-android-build-process/

3 个解决方案

#1


4

If you're working in Eclipse with ADT then you can check variable BuildConfig.DEBUG. It's generated automatically and placed in the gen/<package>/BuildConfig.java:

如果您使用ADT在Eclipse中工作,那么您可以检查变量BuildConfig.DEBUG。它是自动生成的并放在gen / /BuildConfig.java中:

if (BuildConfig.DEBUG) {
   variable = true;
}

更多相关文章

  1. 在string.xml中调用变量[重复]
  2. 将常量文本放在EditText中,这应该是不可编辑的——Android
  3. 增强的for循环中局部变量的范围
  4. JAVA-全局变量与局部变量-继承-封装-(是三节哦!今天的有点多)
  5. 小聊天程序,访问文件之间的变量
  6. 环境变量在cron中看不到
  7. java中的成员变量和局部变量的区别
  8. 如何在另一个类中使用静态类中的变量?
  9. JAVA 静态方法和静态变量和final和※静态import※

随机推荐

  1. Android省电策略
  2. [android] HttpURLConnection的初步学习
  3. android关于使用哪个版本开发的讨论
  4. Android状态栏和虚拟导航栏的适配总结
  5. [Android]Android SDK 2.3与Eclipse最新
  6. 自定义Seekbar拖动条式样
  7. Android(安卓)实例-个人理财工具 之一 启
  8. Android(安卓)Studio Jni 开发
  9. android学到啥时候就高级了啊
  10. Android表达式计算器