본문 바로가기

Android/Knowhow

[Android] input String quotes in BuildConfig

I clone some project.


To run app, must input my API KEY instead of placeholder.




In above file, I input my API KEY instead of "MyOpenWeatherMapApiKey".

But BuildConfig.java linked with app/build.gradle doesn't create quotes(") and occurs error. 



app/build.gradle


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
apply plugin: 'com.android.application'
 
android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
 
    defaultConfig {
        applicationId "com.example.android.sunshine.app"
        minSdkVersion 10
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildTypes.each {
        it.buildConfigField 'String''OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherMapApiKey
    }
}
 
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.2'
}
cs




BuildConfig.java


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
 * Automatically generated file. DO NOT MODIFY
 */
package com.example.android.sunshine.app;
 
public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String APPLICATION_ID = "com.example.android.sunshine.app";
  public static final String BUILD_TYPE = "debug";
  public static final String FLAVOR = "";
  public static final int VERSION_CODE = 1;
  public static final String VERSION_NAME = "1.0";
  // Fields from build type: debug
  public static final String OPEN_WEATHER_MAP_API_KEY = MyOpenWeatherMapApiKey;
}
cs






As a result, I solve the quotes problem by adding \"


For more detail, refer this URL.