我想在Application class
文件中设置build.gradle
中的属性值,例如:
MyApplication.URL = "someurl.com"
应根据构建确定,
我试过了:
productFlavors {
myApp {
qualified.package.path.MyApplication.URL = "someurl.com"
}
}
但失败了
答案 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;
}
}