突然地图停止在我的应用中工作,只是在左下角显示一个带有Google徽标的空白屏幕。
我得到的错误是:
I/Google Maps Android API﹕ Google Play services package version: 4452038
I/ActivityManager﹕ Start proc com.google.android.gms.maps for service com.google.android.gms/.maps.auth.ApiTokenService:
I/Google Maps Android API﹕ Google Play services client version: 4452000
I/Google Maps Android API﹕ Failed to contact Google servers. Another attempt will be made when connectivity is established.
E/Google Maps Android API﹕ Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
我认为可能的唯一想法是身份验证错误。因为我尝试过不同的网络并且没有遇到麻烦。
问题可能出在build.gradle文件中吗?我想,因为问题在我搞砸了之后就开始了。
这是我的构建gradle:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
def versionPropsFile = file('version.properties')
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def value = 0
def runTasks = gradle.startParameter.taskNames
if ('assemble' in runTasks || 'assembleRelease' in runTasks || 'aR' in runTasks) {
value = 1;
}
def versionMajor = 1
def versionMinor = 3
def versionPatch = versionProps['VERSION_PATCH'].toInteger() + value
def versionBuild = versionProps['VERSION_BUILD'].toInteger() + 1
def version_Code = versionProps['VERSION_CODE'].toInteger() + value
versionProps['VERSION_PATCH'] = versionPatch.toString()
versionProps['VERSION_BUILD'] = versionBuild.toString()
versionProps['VERSION_CODE'] = version_Code.toString()
versionProps.store(versionPropsFile.newWriter(), null)
defaultConfig {
versionCode version_Code
versionName "${versionMajor}.${versionMinor}.${versionPatch} (${versionBuild})"
minSdkVersion 14
targetSdkVersion 19
}
} else {
throw new GradleException("Could not read version.properties!")
}
signingConfigs {
debug {
storeFile file("xxx.keystore")
storePassword "xxxx"
keyAlias "debug"
keyPassword "xxxx"
}
releaseKey {
storeFile file("xxx.keystore")
storePassword "xxxx"
keyAlias "release"
keyPassword "xxxx"
}
}
buildTypes {
debug {
debuggable true
packageNameSuffix ".debug"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.debug
}
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.releaseKey
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile project(':nineOldAndroids')
compile project(':expListViewLib')
compile project(':datetimepickerlibrary')
compile project(':volley')
compile 'com.android.support:support-v4:+'
compile 'com.google.android.gms:play-services:+'
compile files('libs/aws-android-sdk-1.7.1.1.jar')
compile files('libs/disklrucache-2.0.1.jar')
}
清单如下所示:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app" >
<permission
android:name="com.example.app.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.example.app.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
...
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="@string/config_com.google.android.maps.v2.api_key" />
</application>
</manifest>
我多次检查过packageName,sha1指纹和API是否正确。所有这些都是,但我仍然得到一张空地图。
我在那里看到过类似的问题,但没有找到我找到的解决方案。它只是拒绝为我工作。
有什么建议吗?
编辑: 我没有尝试过任何工作。但我确实找到了一个似乎有同样问题的人的类似问题:Google Maps Android API Authorization failure - has this service changed in the last few months?
答案 0 :(得分:3)
我有完全相同的问题,解决方案根本不明显。检查您是否使用以下命令更改DefaultSSLSocketFactory
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
删除此行并为所需连接设置套接字工厂使我的地图有效。