无法解析 'R.string.gcm_send_message'

Cannot resolve 'R.string.gcm_send_message'

知道为什么我会收到此错误吗?与 cannot resolve R.string.token_error_messagecannot resolve R.string.registrationProgressBar 一起尝试使用 GCM?

我认为问题出在 Manifest 所以我做了各种更改,但没有任何帮助。

清单:

<manifest
    package="com.example.android.bluetoothchat"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionCode="1"
    android:versionName="1.0">

    <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle -->

    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- GCM START -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <permission android:name="com.example.android.bluetoothchat.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.example.android.bluetoothchat.permission.C2D_MESSAGE" />

    <!-- GCM END -->

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <!-- GCM START -->
        <receiver
            android:name="com.google.android.gms.gcm.GcmReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.example.android.bluetoothchat" />
            </intent-filter>
        </receiver>

        <service
            android:name=".MyGcmListenerService"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>
        <service
            android:name=".MyInstanceIDListenerService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.gms.iid.InstanceID"/>
            </intent-filter>
        </service>

        <!-- GCM END -->
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="portrait"

            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <activity
            android:name=".DeviceListActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/select_device"
            android:theme="@android:style/Theme.Holo.Dialog"/>

    </application>

</manifest>

看看这个link。看来,您应该在您的项目中创建自己的字符串 strings.xml 并在您的布局中添加一个 ProgressBar

要添加的字符串(来自 link 以上):

<string name="gcm_send_message">Token retrieved and sent to server! You can now use gcmsender to
    send downstream messages to this app.</string>
<string name="registering_message">Generating InstanceID token...</string>
<string name="token_error_message">An error occurred while either fetching the InstanceID token,
    sending the fetched token to the server or subscribing to the PubSub topic. Please try
    running the sample again.</string>

此外,您的布局必须包含 ProgressBar,id 为 registrationProgressBar:

<ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/registrationProgressBar" />