Use a java class in build.gradle

2019-05-08 09:07发布

问题:

Hi Maybe this is a foolish question but i am not much familiar with groovy and gradle and can't get the exact answer.

  public class Config{
   public static final String APPLICATION_ID="com.app.dracula";
   public static final int VERSION_CODE=1;
    public static final String VERSION_NAME="1.0.0";
}

I have class like above . Can i use this class in build.gradle to assign the all fields(Watch out the fields names).

I know i can create BuildConfigField from a properties file which i am doing right now . But out of curiosity is there a way to use a .java class or interface in build.gradle? Can i achieve something like .

 defaultConfig {
    applicationId Config.APPLICATION_ID
    minSdkVersion 16
    targetSdkVersion 26
    versionCode Config.VERSION_CODE
    versionName Config.VERSION_NAME
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary = true
}

Don't Confused by above code this is just an metaphor of what i want to achieve .