java - Android 编译器无法找到元数据,即使它存在于 list 文件中

标签 java android android-studio

我正在尝试运行 Google Cloud 消息传递系统,logcat 显示 元数据应该包括 android 名称和 android 值,这已经是 存在于 list 内

3016-3016/com.icanappz.gcmimplementation E/AndroidRuntime﹕ FATAL   EXCEPTION: main


 Process: com.icanappz.gcmimplementation, PID: 3016
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.icanappz.gcmimplementation/com.icanappz.gcmimplementation.MainActivity}: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 6587000 but found 6171000.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
    at android.app.ActivityThread.access$800(ActivityThread.java:144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
 Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 6587000 but found 6171000.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
        at com.google.android.gms.common.GooglePlayServicesUtil.D(Unknown Source)
        at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
        at com.icanappz.gcmimplementation.MainActivity.onCreate(MainActivity.java:112)
        at android.app.Activity.performCreate(Activity.java:5933)

这是 logcat,这是最主要的:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.icanappz.gcmimplementation"
    android:versionCode="2"
    android:versionName="1.1.0" >

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <!-- This app has permission to register and receive data message. -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <!-- Permission to vibrate -->
    <uses-permission android:name="android.permission.VIBRATE" />

    <!-- Creates a custom permission so only this app can receive its messages. -->
    <permission
        android:name="com.icanappz.gcmimplementation.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.icanappz.gcmimplementation.permission.C2D_MESSAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/icanTheme" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>
        <activity
            android:name="com.icanappz.gcmimplementation.MainActivity"
            android:theme="@style/Theme.AppCompat.Light"
            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="com.icanappz.gcmimplementation.DailogeNotice"
            android:theme="@style/AppTheme.Dialog" >
        </activity>
        <activity
            android:name="com.icanappz.gcmimplementation.CustomeWebView"
            android:theme="@style/Theme.AppCompat.Light" >
        </activity>

        <activity
            android:name="com.icanappz.gcmimplementation.PreferenceActivity"
            android:theme="@style/Theme.AppCompat.Light" >
        </activity>

        <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />





        <receiver
                android:name="com.icanappz.gcmimplementation.GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>

                <!-- Receives the actual messages. -->
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />

                <category android:name="com.icanappz.gcmimplementation" />
            </intent-filter>
        </receiver>

        <service     android:name="com.icanappz.gcmimplementation.GcmIntentService" />
    </application>

</manifest>

最佳答案

您需要将此元数据添加到您的 AndroidManifest.xml 中里面<application> :

 <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

并且您在获取正确的 Google Play 服务版本时不会遇到任何问题。

关于java - Android 编译器无法找到元数据,即使它存在于 list 文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28639001/

相关文章:

java - 如何在 Java 中使用正则表达式拆分 map 字符串

java - RecyclerView在最新版本中无法实例化。 Android Studio 的

java - Spring 文件上传 etat HTTP 405 - 不支持请求方法 'POST'

java - Apache netbeans IDE 10.0 安装了 JEE 支持,但注释仍然错误

Android Studio 渲染问题 : The following classes could not be found

android - 修复recyclerview选中项的位置

Java 将 ArrayList 转换为字符串并返回 ArrayList?

java - Android - 如何将位图列表作为参数传递给另一个 Activity

android-studio - 实现Google Play服务时应用崩溃

java - 重新启动应用程序刽子手