解决 Google 的官方 PlacesPicker 示例中的错误
Resolve errors from Google's official PlacesPicker example
我正在尝试 Google 的官方 PlacesPicker 示例。它运行并呈现第一个 activity 但是当我单击按钮“选择一个地方”时它暂时转到下一个 activity 但是在显示地图很短的时间后它回到主activity.
当我查看日志时,它有两个我无法解决的问题,一个是
第一期
Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.zze.zzb
我尝试通过将 android.support.mulitdex.MultiDexApplication 添加到我的清单
来解决这个问题
<application
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
android:name="android.support.multidex.MultiDexApplication">
我也把这个添加到 build.gradle
compile 'com.android.support:multidex:1.0.0'
此外,其他已接受的解决方案表明它可能与 65k 限制错误有关,因此我也有选择地仅向 build.gradle
添加了必要的 google 播放服务
compile 'com.google.android.gms:play-services-measurement:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.android.gms:play-services-plus:8.4.0'
第二期
12934/com.example.google.playservices.placepicker E/GMPM: 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.
03-21 11:29:02.583 12934-12934/com.example.google.playservices.placepicker E/GMPM: Scheduler not set. Not logging error/warn.
03-21 11:29:02.653 12934-13065/com.example.google.playservices.placepicker E/GMPM: Uploading is not possible. App measurement disabled
我尝试了很多 Whosebug 中建议的解决方案,但没有成功。
, and and 只是我尝试过的一些被接受的答案。
我确定 api 密钥有效,因为调用已在我的 google 开发者控制台上注册。一个官方的例子竟然不能轻易编译和测试,真是令人沮丧。有没有人遇到过这个问题,你是如何解决的?另外,如果您知道或有更好的 Android Places API 更新工作示例,请分享,我将非常感激。
更新 1:我的清单文件
<?xml version="1.0" encoding="UTF-8"?><!--
Copyright 2013 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.google.playservices.placepicker"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<!-- PlacePicker requires the ACCESS_FINE_LOCATION permission and a geo API key.
See this page for more information on how to obtain an API key:
https://developers.google.com/places/documentation/android/start
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- PlacePicker also requires OpenGL ES version 2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
android:name="android.support.multidex.MultiDexApplication"
>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIza..xxx...key.from.google" />
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我也遇到了同样的问题。我通过在 strings.xml 中提供正确的 google_maps_key 来解决它
也在 google_maps_api.xml 文件中。
添加这个答案是因为也许其他人会觉得它有帮助。
正如你在评论中提到的步骤。
[1] add the appropriate user permissions
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
还在应用程序标签中添加这些行
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
[2] Register the correct package name in google developer console. The package name defined in manifest file. e.g!
package="com.example.xyz"
[3] Double check if the place api are correctly enabled the for the
appropriate project
我正在尝试 Google 的官方 PlacesPicker 示例。它运行并呈现第一个 activity 但是当我单击按钮“选择一个地方”时它暂时转到下一个 activity 但是在显示地图很短的时间后它回到主activity.
当我查看日志时,它有两个我无法解决的问题,一个是
第一期
Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.zze.zzb
我尝试通过将 android.support.mulitdex.MultiDexApplication 添加到我的清单
来解决这个问题<application
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
android:name="android.support.multidex.MultiDexApplication">
我也把这个添加到 build.gradle
compile 'com.android.support:multidex:1.0.0'
此外,其他已接受的解决方案表明它可能与 65k 限制错误有关,因此我也有选择地仅向 build.gradle
添加了必要的 google 播放服务compile 'com.google.android.gms:play-services-measurement:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.android.gms:play-services-plus:8.4.0'
第二期
12934/com.example.google.playservices.placepicker E/GMPM: 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.
03-21 11:29:02.583 12934-12934/com.example.google.playservices.placepicker E/GMPM: Scheduler not set. Not logging error/warn.
03-21 11:29:02.653 12934-13065/com.example.google.playservices.placepicker E/GMPM: Uploading is not possible. App measurement disabled
我尝试了很多 Whosebug 中建议的解决方案,但没有成功。
我确定 api 密钥有效,因为调用已在我的 google 开发者控制台上注册。一个官方的例子竟然不能轻易编译和测试,真是令人沮丧。有没有人遇到过这个问题,你是如何解决的?另外,如果您知道或有更好的 Android Places API 更新工作示例,请分享,我将非常感激。
更新 1:我的清单文件
<?xml version="1.0" encoding="UTF-8"?><!--
Copyright 2013 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.google.playservices.placepicker"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<!-- PlacePicker requires the ACCESS_FINE_LOCATION permission and a geo API key.
See this page for more information on how to obtain an API key:
https://developers.google.com/places/documentation/android/start
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- PlacePicker also requires OpenGL ES version 2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
android:name="android.support.multidex.MultiDexApplication"
>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIza..xxx...key.from.google" />
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我也遇到了同样的问题。我通过在 strings.xml 中提供正确的 google_maps_key 来解决它 也在 google_maps_api.xml 文件中。
添加这个答案是因为也许其他人会觉得它有帮助。
正如你在评论中提到的步骤。
[1] add the appropriate user permissions
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
还在应用程序标签中添加这些行
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
[2] Register the correct package name in google developer console. The package name defined in manifest file. e.g!
package="com.example.xyz"
[3] Double check if the place api are correctly enabled the for the appropriate project