在Android Studio中,我可以单击IDE中的“运行”按钮来运行应用程序,该应用程序在调试模型下运行,但是我怎么知道以编程方式存在一个调试模型?就像下面的代码一样。

If (IsDebug()){
   Toast.makeText(getApplicationContext(), "This is in debug, it will diplay some prompt information",Toast.LENGTH_LONG).show();
}else{
   Toast.makeText(getApplicationContext(), "This is release edition, it will not diplay debug information",Toast.LENGTH_LONG).show();
}

最佳答案

为简单起见,您可以使用BuildConfig,例如if (BuildConfig.DEBUG) {...}

BuildConfig是在AndroidStudio中单击“运行”时在编译时生成的,如下所示:

public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String APPLICATION_ID = "YOUR APP";
  public static final String BUILD_TYPE = "debug";
  public static final String FLAVOR = "";
  public static final int VERSION_CODE = 1;
  public static final String VERSION_NAME = "YOUR VERSION";
}


但是,如果在库项目中使用此错误,则会报告一些错误。
http://www.digipom.com/be-careful-with-buildconfig-debug/

如果需要更高级的方法,可以在build.gradle中进行定义。
增强您的BuildConfig
http://toastdroid.com/2014/03/28/customizing-your-build-with-gradle/

10-08 19:06