I am a new developer studying the world of Android. I am currently working on Udacity tutorials to create a Sunshine application. In the fragment activity class, to get data from openweathermap, I have to add the API key obtained from my account to the end of the generated URL. There is a call to BuildConfig.java in the Activity Snippet (click to see the call to BuildConfig.java, which is on the 6th line as part of the String apiKey).
The build.gradle file is as follows:
apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.1" 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', 'c882c94be45fff9d16a1cf845fc16ec5' } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.1.0' }
in buildTypes.each it.buildConfigField is called with 'String', 'OPEN_WEATHER_MAP_API_KEY', 'c882c94be45fff9d16a1cf845fc16ec5', which leads to
public static final String OPEN_WEATHER_MAP_API_KEY = c882c94be45fff9d16a1cf845fc16ec5;
is created in BuildConfig.java, however I keep getting this error: Unable to resolve the character (click to see the error message and the BuildConfig.java file) I donβt understand why String OPEN_WEATHER_MAP_API_KEY is automatically created as just a group of letters and numbers without quotes around them. but if I edit the code to read:
public static final String OPEN_WEATHER_MAP_API_KEY = "c882c94be45fff9d16a1cf845fc16ec5";
or
public static final String OPEN_WEATHER_MAP_API_KEY = 'c882c94be45fff9d16a1cf845fc16ec5';
BuildConfig.java automatically changes itself. I'm not sure what I'm doing wrong, and I checked many of the Udacity videos that did not have any information about this issue. Please let me know if you know how to fix this.
Sincerely.
java android weather-api openweathermap
Kevin rajan
source share