【问题标题】:Cannot resolve string symbol AndroidManifest.xml无法解析字符串符号 AndroidManifest.xml
【发布时间】:2018-10-02 14:29:15
【问题描述】:

我正在使用本教程创建一个天气应用程序: https://blog.teamtreehouse.com/beginners-guide-location-android 我注意到由于某种原因我得到了错误:'无法解析符号'R''和'无法解析符号'setUpMapIfNeeded()'。这些是我已经尝试过的所有事情: 清理/构建项目,文件>无效缓存/重新启动..,删除构建文件夹,首先同步Gradle,在settings.gradle中添加“包含':app'”,甚至导入.R,我得到相同的导入错误.. . 最终,我发现我的一个 .xml 文件可能有问题。

事实证明,在我的 AndroidManifest.xml 文件中的元数据部分下,android:value="@string/google_maps_key"/> 是红色的,并且还显示“无法解析符号”。

这是完整的清单代码:

<?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>

google_maps_key 只是用于访问天气数据的 API 密钥。实际的密钥在 google_maps_api.xml 中,这是其中的所有代码:

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

我仍然不明白为什么不能像其他 2 个符号一样解析 google maps 键字符串。我不知道还能做什么,我什么都试过了。下面也是主类的截图:

【问题讨论】:

  • 您很可能不小心将您的 API 密钥暴露给世界...我建议您购买一个新的。

标签: java android


【解决方案1】:

字符串资源错误。你贴错了,名字必须是name="google_maps_key"

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

【讨论】:

    【解决方案2】:

    查看https://github.com/treehouse/android-location-example

    在MapsActivity中有setUpMapIfNeeded方法的实现

    【讨论】:

      猜你喜欢
      • 2023-01-03
      • 2020-05-01
      • 2014-06-20
      • 2013-12-07
      • 1970-01-01
      • 1970-01-01
      • 2018-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多