2

Is it possible to use a .properties file in android from assets in release and other when I do debug in android studio?

I'm using gradle, but I don't have any idea how can I do it this.

Thanks

ozbek
  • 20,955
  • 5
  • 61
  • 84
colymore
  • 11,776
  • 13
  • 48
  • 90

3 Answers3

2

I suggest you to name your files this way:

file_debug.properties    => debug file
file.properties          => release file

and in your code do this:

final String mode = isDebugMode() ? "_debug" : "";
final String suffix = mode + ".properties";

String fileName = "file" + suffix; //either file_debug.properties or file.properties

private boolean isDebugMode() {
    return android.os.Debug.isDebuggerConnected(); //is being debugged via ADB
    // or
    //return 0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE); //can be debugged, but maybe not at the moment
}
Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76
0

You can check wheter you are in debug or release and load your necessary file from assets. Check this post How to check programmatically whether app is running in debug mode or not?

Community
  • 1
  • 1
Ispas Claudiu
  • 1,890
  • 2
  • 28
  • 54
0

except you can detect the debug mode in your code and choose which branch to go, you also can custom you ant build process to change the properties file like pre_compile.

we now have an configure file when developing, and we have an isolated build machine to build release version, and in the build machine, we change the property file to the release version.

powerfj
  • 156
  • 6