Skip to content

Instantly share code, notes, and snippets.

@shts
Last active January 13, 2017 03:13
Show Gist options
  • Save shts/98c4014a19eedb1795ed to your computer and use it in GitHub Desktop.
Save shts/98c4014a19eedb1795ed to your computer and use it in GitHub Desktop.
gradle.propertiesに定義した値をJavaソースから参照する ref: http://qiita.com/shts/items/d94834437b22712415c5
# BuildConfig.java を公開しないようにするため
/build
# gradle.properties を公開しないようにするため
gradle.properties
buildTypes {
debug {
buildConfigField "String", "PARSE_API_ID", "\"${project.property("parseApiId")}\""
buildConfigField "String", "PARSE_API_KEY", "\"${project.property("parseApiKey")}\""
}
release {
buildConfigField "String", "PARSE_API_ID", "\"${project.property("parseApiId")}\""
buildConfigField "String", "PARSE_API_KEY", "\"${project.property("parseApiKey")}\""
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
public final class BuildConfig {
// Fields from build type: debug
public static final String PARSE_API_ID = "xxxxxxxxxxxxxxxxxxxxx";
public static final String PARSE_API_KEY = "xxxxxxxxxxxxxxxxxxxxx";
}
buildConfigField "String", "PARSE_API_ID", "\"${project.property("parseApiId")}\""
buildConfigField "String", "PARSE_API_KEY", "\"${project.property("parseApiKey")}\""
parseApiId=xxxxxxxxxxxxxxxxxxxxx
parseApiKey=xxxxxxxxxxxxxxxxxxxxx
public class MyApplication extends Application {
public MyApplication() {
super();
}
@Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, BuildConfig.PARSE_API_ID, BuildConfig.PARSE_API_KEY);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment