Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use different assets for debug and release

I would like to use different database files for debug and release builds. Is it possible to do it with using gradle and two different directories like assets and assets_deb for instance?

The verification code in the app, like this android.os.Debug.isDebuggerConnected() is not suitable in my situation.

Thanks

like image 478
VicPls Avatar asked Sep 30 '16 10:09

VicPls


2 Answers

You can use different assets folder, like:

app/src/main/assets
app/src/debug/assets
app/src/release/assets

Or you can define different src folders in the build.gradle file:

sourceSets {

        main.java.srcDirs = ['...']
        main.res.srcDirs = ['...']
        main.assets.srcDirs = ['...']
        debug.assets.srcDirs = ['...']
        flavor1.assets.srcDirs = ['...']
    }

To check the "debug" value you can use the default BuildConfig.DEBUG.
In the same way you can define your own boolean value:

buildTypes {
        debug {
            buildConfigField "boolean", "MYVALUE", "true"
        }
        release {
            buildConfigField "boolean", "MYVALUE", "false"
        }
    }

The automatically-generated BuildConfig class will contain the following fields based on the directive above:

public class BuildConfig {
    // ... other generated fields ...
    public static final boolean MYVALUE = false;
}
like image 91
Gabriele Mariotti Avatar answered Nov 04 '22 12:11

Gabriele Mariotti


Yes, you can. Just create another folder in your src folder as below:

-- src
----- debug
--------- assets
----- main
--------- assets

If you need something like different application name in Debug mode, you can define new res/value folder in debug folder as well.

like image 41
Kingfisher Phuoc Avatar answered Nov 04 '22 12:11

Kingfisher Phuoc