Android 判断是开发debug模式,还是发布release模式
2017-01-16 19:33
447 查看
转载来源http://blog.csdn.net/catoop/article/details/47341125
public class LogUtils {
public static boolean APP_DBG = false; // 是否是debug模式
public static void init(Context context){
APP_DBG = isApkDebugable(context);
}
/**
* 但是当我们没在AndroidManifest.xml中设置其debug属性时:
* 使用Eclipse运行这种方式打包时其debug属性为true,使用Eclipse导出这种方式打包时其debug属性为法false.
* 在使用ant打包时,其值就取决于ant的打包参数是release还是debug.
* 因此在AndroidMainifest.xml中最好不设置android:debuggable属性置,而是由打包方式来决定其值.
*
* @param context
* @return
* @author SHANHY
* @date 2015-8-7
*/
public static boolean isApkDebugable(Context context) {
try {
ApplicationInfo info= context.getApplicationInfo();
return (info.flags&ApplicationInfo.FLAG_DEBUGGABLE)!=0;
} catch (Exception e) {
}
return false;
}
}
项目开发中,我们根据debug属性来输出日志。
但是有些时候我们想在给公司的测试机上安装的release版本也输出日志,那么这个时候我们到 AndroidManifest.xml 中的application 标签中添加属性强制设置debugable即可,如下:
[html]
view plain
copy
<application android:debuggable="true" tools:ignore="HardcodedDebugMode"
....
.... />
init 方法在客户端的第一个Activity的onCreate方法中执行一下即可。
public class LogUtils {
public static boolean APP_DBG = false; // 是否是debug模式
public static void init(Context context){
APP_DBG = isApkDebugable(context);
}
/**
* 但是当我们没在AndroidManifest.xml中设置其debug属性时:
* 使用Eclipse运行这种方式打包时其debug属性为true,使用Eclipse导出这种方式打包时其debug属性为法false.
* 在使用ant打包时,其值就取决于ant的打包参数是release还是debug.
* 因此在AndroidMainifest.xml中最好不设置android:debuggable属性置,而是由打包方式来决定其值.
*
* @param context
* @return
* @author SHANHY
* @date 2015-8-7
*/
public static boolean isApkDebugable(Context context) {
try {
ApplicationInfo info= context.getApplicationInfo();
return (info.flags&ApplicationInfo.FLAG_DEBUGGABLE)!=0;
} catch (Exception e) {
}
return false;
}
}
项目开发中,我们根据debug属性来输出日志。
但是有些时候我们想在给公司的测试机上安装的release版本也输出日志,那么这个时候我们到 AndroidManifest.xml 中的application 标签中添加属性强制设置debugable即可,如下:
[html]
view plain
copy
<application android:debuggable="true" tools:ignore="HardcodedDebugMode"
....
.... />
init 方法在客户端的第一个Activity的onCreate方法中执行一下即可。
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件