Lepotec
Lepotec

Reputation: 13

Cannot resolve string symbol AndroidManifest.xml

I'm creating a weather app using this tutorial: https://blog.teamtreehouse.com/beginners-guide-location-android I noticed that for some reason I got the errors: 'Cannot resolve symbol 'R'' and 'Cannot resolve symbol 'setUpMapIfNeeded()'. These are all the things I already tried: Clean/Build project, File > Invalidate Caches/Restart.., Deleted Build folders, Synced Gradle first, added "include ':app'" in settings.gradle, even imported .R and I get the same error for the import... Eventually, I found out that there's probably something wrong with one of my .xml files.

It turns out that in my AndroidManifest.xml file under the meta-data section the android:value="@string/google_maps_key"/> is colored red and it also says 'Cannot resolve symbol'.

Here is the full Manifest code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="weatherapp.com.drek">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

    <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key"/>

    <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

The google_maps_key is just an API key for accessing weather data. The actual key is in google_maps_api.xml and this is all the code there is inside it:

<resources>
<string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">YOUR_KEY_HERE</string>
</resources>

I still don't understand why the google maps key string cannot be resolved just like for the other 2 symbols. I don't know what else to do, I've tried everything. Below is also a screenshot of the main class:

enter image description here

Upvotes: 1

Views: 2068

Answers (2)

Tung Duong
Tung Duong

Reputation: 1166

Mistake from String resource. You pasted wrong, name need to be name="google_maps_key"

<resources>
  <string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">AIzaSyDtyUdRtbkQ3GqpXaT_......</string>
</resources>

Upvotes: 1

PicTools
PicTools

Reputation: 49

Check https://github.com/treehouse/android-location-example

In MapsActivity there is the implementation of the setUpMapIfNeeded method

Upvotes: 0

Related Questions