区分调试的Andr​​oid应用程序和生产建设 [英] Differentiating debug and production build of an Android app

查看:144
本文介绍了区分调试的Andr​​oid应用程序和生产建设的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始学习Android应用开发。这也是我对Java语言第一次经历。

I recently started learning about Android app development. It's also my first experience with the Java language.

有,我想将其纳入我的应用程序开发的Java包依赖的一种形式,一些调试工具。由于显而易见的原因,我想只包括它建立调试。

There are some debugging tools that I want to incorporate into my app development in a form of Java package dependency. For obvious reasons, I would like to include it only for debug builds.

在iOS系统中,我们可以使用构建配置与调试库链接只为调试版本,并使用宏来消除code表示调试处理的部分。这使得它很容易调试和产品构建之间切换。总之,以达到同样为Android?

In iOS, we can use build configuration to link with debugging libraries only for debug builds, and use macros to remove parts of code that deals with debugging. This makes it really easy to switch between debug and production builds. Anyway to achieve the same for Android?

目前为止,最接近我得到的是使用Maven的配置文件来覆盖属性文件,它被应用程序加载,但这需要调试库还是进口的。

So far, the closest I got is using Maven profiles to overwrite properties files, which gets loaded by the application, but this requires that the debugging libraries are still imported.

要澄清我的问题,这里是我想做的事: 我建立,可以让你浏览SQLite数据库浏览器上的一个库。这对于调试目的非常有用,但我不希望随库我的应用程序。

To clarify my question, here is what I want to do: I built a library that will let you browse the SQLite database on your browser. It's really useful for debugging purposes, but I don't want to ship my app with the library.

另一个目的是利用HockeyApp。 HockeyApp提供了两个功能:更新通知,和崩溃报告。我需要三个不同的构建对于这项工作:

Another purpose is to use HockeyApp. HockeyApp provides two features: Update notification, and crash reporting. I need three different builds for this to work:

  • 生产:崩溃汇报,更新通知关闭
  • 测试版:无论在
  • 调试:都关闭

推荐答案

在清单的的 <应用> ,您可以设置可调试属性。如果省略属性Eclipse将自动为您完成此。调试版本有可调试=真正的,以及出口建立具有可调试=假

In the manifest's <application>, you can set the debuggable attribute. Eclipse does this for you automatically if you omit the attribute. Debug builds have debuggable=true, well exported builds have debuggable=false.

这会影响Log.d,你可以在code。使用下列条件查询:

This affects Log.d, and you can conditionally check in code using the following:

boolean isDebuggable = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));

这篇关于区分调试的Andr​​oid应用程序和生产建设的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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