gpt4 book ai didi

android - GoogleService 初始化失败,状态 : 10

转载 作者:行者123 更新时间:2023-11-29 17:19:16 25 4
gpt4 key购买 nike

我在我的 Android 应用程序中使用谷歌地图。我已经创建了 key 并在 list 文件中添加了必要的权限:

list :

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

google-maps-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 上的步骤操作,但就我的情况而言,我可能会错过什么配置?

最佳答案

我觉得

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

apply plugin: 'com.google.gms.google-services'

  1. 将依赖项添加到您的项目级build.gradle:

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'
}

关于android - GoogleService 初始化失败,状态 : 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37210562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com