0

I am trying Google's official PlacesPicker example. It runs and renders the first activity but when I click the button to "Pick a Place" it temporarily goes to the next activity but after showing the map for a very short time it goes back to the main activity.
When I looked at the log it has two issues that I cannot resolve one is

FIRST ISSUE

Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.zze.zzb

This I tried resolving by adding android.support.mulitdex.MultiDexApplication to my manifest

<application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:theme="@style/AppTheme"
        android:name="android.support.multidex.MultiDexApplication">

I also added this to the build.gradle

compile 'com.android.support:multidex:1.0.0'

Also other accepted solutions suggests that it might be related to the 65k limit error so I also selectiely added only the necessary google play services to the build.gradle

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'

SECOND ISSUE

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

I tried so many solutions suggested here in Stackoverflow but with no success. this , and this and this are just some of the accepted answers I have tried.

I am sure that the api key is valid because the calls are being registered on my google developer console. It is really frustrating that an official example cant be compiled and tested easily. Does anybody encountered this issues and how did you fix them? Also if you know or have a better much updated working example of Android Places API please share I will really appreciate it.

UPDATE 1 : MY MANIFEST FILE

 <?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>
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
TwoThumbSticks
  • 1,086
  • 3
  • 23
  • 38
  • is your application registered on developer console?? – Mustanser Iqbal Mar 21 '16 at 05:16
  • Yes I used the places api key and I can monitor the api calls from my developer console. – TwoThumbSticks Mar 21 '16 at 05:27
  • did you added the api key in manifest file?? – Mustanser Iqbal Mar 21 '16 at 05:31
  • I updated my question added my full manifest file. – TwoThumbSticks Mar 21 '16 at 05:44
  • where is the internet permission? try adding these permission and i am sure it will work – Mustanser Iqbal Mar 21 '16 at 06:00
  • I already have the access_fine_location . Now I added the INTERNET but still the two issues still exists. – TwoThumbSticks Mar 21 '16 at 06:14
  • if you have done all the steps then obviously your are doing something wrong on developer console. because that's all place need to work.. i have this issue last night.. and my mistake was my SHA1 was not correct. please recheck ur SHA1 and i think you are using the place picker api demo. try ti change the package name and then register it on console. and i am sure it will work – Mustanser Iqbal Mar 21 '16 at 06:18
  • also try adding this permission – Mustanser Iqbal Mar 21 '16 at 06:19
  • ok will try it again on the developer console. Am I doing it wrong if I am just using com.example as package name? or do i have to register all packages com.example.android.common, packages com.example.android.common.activities, packages com.example.android.common.logger etc? – TwoThumbSticks Mar 21 '16 at 06:55
  • you have register the whole name which is written in Manifest file. – Mustanser Iqbal Mar 21 '16 at 07:03
  • user this package name {com.example.google.playservices.placepicker} instead of {com.example} – Mustanser Iqbal Mar 21 '16 at 07:03
  • I updated my question with the screenshot of the google developer console. I did what you said used the com.example.google.playservices.placepicker – TwoThumbSticks Mar 21 '16 at 08:15
  • is the google place api is enabled? please make sure it is enabled. – Mustanser Iqbal Mar 21 '16 at 09:24
  • Thats it finally! I enabled the api on a different project inside the developer console. The developer console UI is a little confusing. If you can write an answer I will accept it sir. Basically what you helped me do is [1] add the appropriate user permissions [2] correct the package that I registered in google developer console [3] and double check if I correctly enabled the right api for the appropriate project – TwoThumbSticks Mar 21 '16 at 13:00
  • i think you major problem was the package name. right? if that is it i'll add the answer with the steps you mentioned.. because maybe it will be helpful for someone else – Mustanser Iqbal Mar 21 '16 at 13:06

2 Answers2

0

Same issue occured with me too. And i resolved it by providing correct google_maps_key inside strings.xml and also in google_maps_api.xml file.

Febi M Felix
  • 2,799
  • 1
  • 10
  • 13
0

Adding this answer because maybe someone else will find it helpful.

As you mention the steps in comment.

[1] add the appropriate user permissions

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

also add these line inside the application tag

<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

Mustanser Iqbal
  • 5,017
  • 4
  • 18
  • 36