GoogleService初始化失败,状态:10

时间:2016-05-13 12:52:29

标签: android google-maps

我在Android应用程序中使用谷歌地图。我创建了密钥并在清单文件中添加了必要的权限:

清单:

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

    <uses-permission android:name="com....MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

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

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key"/>
        <activity
            android:name=".activities.MainActivity"
            android:windowSoftInputMode="stateHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

谷歌地图-api.xml:

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">
    AIzaSyAjGQ-...
</string>

另外,我已经将以下依赖compile 'com.google.android.gms:play-services:8.4.0'添加到编译中,它正在运行:

app.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com..."
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.google.android.gms:play-services:8.4.0'
}

我还将google-services.json添加到 PROJECT_NAME / app /

enter image description here

但是当应用程序启动时,我在调试器中收到此消息:

GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services.  Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.

我已经按照link的步骤进行了操作,但就我的情况而言,我可以错过哪些配置?

3 个答案:

答案 0 :(得分:3)

我认为

  1. 您应该将插件添加到应用级build.gradle的底部:
  2.   

    申请插件:'com.google.gms.google-services'

    1. 将依赖项添加到项目级build.gradle
    2.   

      classpath'com.google.gms:google-services:1.5.0-beta2'

      了解更多信息Check this

      编辑:

      build.gradle看起来像

      apply plugin: 'com.android.application'
      apply plugin: 'com.google.gms.google-services'
      
      android {
      compileSdkVersion 23
      buildToolsVersion "23.0.3"
      
      defaultConfig {
          applicationId "com..."
          minSdkVersion 21
          targetSdkVersion 23
          versionCode 1
          versionName "1.0"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
         }
      }
      
      dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      testCompile 'junit:junit:4.12'
      compile 'com.android.support:appcompat-v7:23.3.0'
      compile 'com.google.android.gms:play-services:8.4.0'
      }
      

答案 1 :(得分:0)

我有同样的问题。我试图解决它。但没有运气。如果你有备份项目使用那个。

答案 2 :(得分:0)

  
      
  1. 您需要放置由此Link生成的配置文件。

  2.   
  3. 然后,您需要从This获取配置文件并下载名为google.json的文件。

  4.   
  5. 然后,您需要将该文件放入您Android的app /或mobile /目录中的项目中。

  6.         

    因为您需要在apply plugin: 'com.google.gms.google-services'以下apply plugin: 'com.android.application'下方添加Build.Gradle,如同在MD的答案Build->Clean文件中一样。

之后<string name="google_maps_key">Your Api Key</string>您的项目。

  

并确保您的API_KEY字符串资源可用,名为<script> $(document).ready(function() { $('.howisthiscalculated').magnificPopup({ type: 'inline' }); }); </script>

相关问题