Android project's unit test, which needs to test with different BuildConfig.DEBUG
value
The BuildConfig class has DEBUG as final
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
}
This code works fine until update to java 17
ReflectionHelpers.setStaticField(BuildConfig.class, "DEBUG", true);
With java 17, now it gets error:
IllegalArgumentException: Cannot set the value of final field public static final boolean com.oath.mobile.shadowfax.adm.BuildConfig.DEBUG
java.lang.RuntimeException: java.lang.RuntimeException:
I think for the test case we can modify the code to use a function for the BuildConfig.DEBUG
value. But ingeneral is there alternative to do modify a final field of a class?