android gradle build set class属性值

时间:2015-05-21 13:19:42

标签: android android-studio android-gradle build.gradle

我想在Application class文件中设置build.gradle中的属性值,例如:

MyApplication.URL = "someurl.com"

应根据构建确定,

我试过了:

productFlavors {
    myApp {
       qualified.package.path.MyApplication.URL = "someurl.com"
    }
}

但失败了

1 个答案:

答案 0 :(得分:3)

您可以在BuildConfig类中编写字段,然后从那里获取它们。

productFlavors {
    myApp {
       buildConfigField "String", "URL", "\"someurl.com\""
    }
}


public class MyApplication extends Application {
    private String URL;

    @Override
    public void onCreate() {
        URL = BuildConfig.URL;
    }   
}