For those of you who don’t know what BuildConfig is, especially beginners, imagine disabling the Debug Log, changing the server Host from test server to official server, and so on every time we build a Release due to the different configuration of Debug and Relaease. It is common practice to modify the configuration before compiling the Release version and then modify it back to the Debug environment at development time. It’s tedious, isn’t it?
Please indicate the source of reprint:www.facex.xyzIf you find any errors or have other better implementation methods, please contact me.
At compile time, Android Studio generates a class called BuildConfig, which contains some constant Pointers used at compile time. The generated BuildConfig file looks like this:
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true|false");
public static final String APPLICATION_ID = "xyz.facex.demo";
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 = "1.0";
}Copy the code
When compiling the Debug version, the Debug variable in the BuildConfig class looks like this:
public static final boolean DEBUG = Boolean.parseBoolean("true");Copy the code
When compiling the Release version, the DEBUG variable in the BuildConfig class looks like this:
public static final boolean DEBUG = Boolean.parseBoolean("false");Copy the code
Yeah, I think you know by now.
HttpHost = ‘DEBUG’; HttpHost = ‘Host’; HttpHost = ‘Host’; HttpHost = ‘Host’;
public class HttpHost { public static final boolean DEBUG = BuildConfig.DEBUG; Public static final String HOST_TEST = "Test server address "; Public static final String HOST = "official server address "; /** * public static String getHost() {return debug? HOST_TEST : HOST; }}Copy the code
Following the above code, we didn’t need to change a single line of code when we released the Release.
Additionally, variables in BuildConfig support customization, so you can Google them if you’re interested.
Next: Trajectory simulation using AmAP