1

My Android application makes use of two APIs: Google Maps API v2 (identified by the package com.google.android.gms.maps) and Facebook API (com.facebook) (this last one has been solved thanks to @RINK)

Both the services were installed in my project by following their official tutorials and they worked fine until yesterday, where something in my code changed and I obviously can't figure out what. I'm pretty sure that the cause is related to the debug/release key that signs my application before being installed on my testing phone.

In particular, I'm working with the debug key that it's stored in my personal folder (I'm on Windows + Netbeans) by default and it's regenerated every time I delete it: C:\Users\Alessandro\.android\debug.keystore.

Both Maps and Facebook need to know the SHA-1 fingerprint of such key, I've retrived it using keytool. Having it, I put it on the dedicated API service pages:

  • Google's Console API in the form BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75;com.UpMap
  • and Facebook's App Dev page, Key Hashes field.

As I said, everything worked fine but suddenly the Maps in my application became blank and Facebook Login raises an error:

11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue   com.facebook.http.protocol.ApiException: remote_app_id does not match stored id 
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at com.facebook.http.protocol.ApiResponseChecker.b(ApiResponseChecker.java:74)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at com.facebook.http.protocol.ApiResponseChecker.a(ApiResponseChecker.java:103)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at com.facebook.http.protocol.ApiResponse.h(ApiResponse.java:208)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at com.facebook.katana.server.protocol.AuthorizeAppMethod.a(AuthorizeAppMethod.java:266)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at com.facebook.katana.server.protocol.AuthorizeAppMethod.a(AuthorizeAppMethod.java:27)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at com.facebook.http.protocol.SingleMethodRunnerImpl.a(SingleMethodRunnerImpl.java:141)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at com.facebook.http.protocol.AbstractSingleMethodRunner.a(AbstractSingleMethodRunner.java:16)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at com.facebook.katana.server.handler.PlatformOperationHandler.c(PlatformOperationHandler.java:284)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at com.facebook.katana.server.handler.PlatformOperationHandler.a(PlatformOperationHandler.java:185)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at com.facebook.fbservice.service.BlueServiceQueue.d(BlueServiceQueue.java:245)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at com.facebook.fbservice.service.BlueServiceQueue.d(BlueServiceQueue.java:51)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at com.facebook.fbservice.service.BlueServiceQueue$3.run(BlueServiceQueue.java:191)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at com.facebook.common.executors.HandlerExecutorServiceImpl$ListenableScheduledFuture.run(HandlerExecutorServiceImpl.java:268)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at android.os.Handler.handleCallback(Handler.java:587)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at android.os.Handler.dispatchMessage(Handler.java:92)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at android.os.Looper.loop(Looper.java:123)
11:24:51.064    1708    #1708   WARN    fb4a(:<default>):BlueServiceQueue       at android.os.HandlerThread.run(HandlerThread.java:60)

I readed the question Android Facebook SDK 3.0 gives "remote_app_id does not match stored id" while logging in and I should be in the same problem, but the fact is that the "Key Hash" which I generated using keytool is good.

I've tried to:

  • delete the stored debug key and regenerate it, updating it's SHA and saving it on Google and Facebook
  • check if the API Keys provided by Google and Facebook and written in my AndroidManifest.xml are correct
  • check if the package name of my app is correct
  • clean and rebuild the entire project, including Google and Facebook source libraries

This is my manifest:

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

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" />

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

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

    <application android:label="@string/app_name" android:allowBackup="true">
        <uses-library android:name="com.google.android.maps" />

        <activity 
            android:name="MainActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.AppCompat"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity 
            android:name="LevelActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.AppCompat"
            android:windowSoftInputMode="adjustPan|adjustResize"
            android:screenOrientation="portrait"
            uiOptions="splitActionBarWhenNarrow">
            <meta-data 
                android:name="android.support.UI_OPTIONS"
                android:value="splitActionBarWhenNarrow" />
        </activity>

        <activity 
            android:name="FacebookActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.AppCompat"
            android:windowSoftInputMode="adjustPan|adjustResize"
            android:screenOrientation="portrait">
        </activity>

         <activity android:name="com.facebook.LoginActivity"/>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="<HIDDEN_GOOGLE_KEY>"
        />

        <meta-data 
            android:name="com.facebook.sdk.ApplicationId" 
            android:value="@string/fb_app_id"/>

    </application>
</manifest> 

This is the code of the Activity that shows the Google Map:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/LevelLayout">

    <TextView  
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/where_is_it"
        android:textSize="28sp"
        android:layout_margin="5dp"
        android:layout_marginBottom="0dp"
    />

    <LinearLayout
            android:id="@+id/SolutionLayout"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_margin="5dp"
            android:background="#000000"
            android:gravity="center"
        >
    </LinearLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="300dp"
    >   
        <fragment 
            class="com.google.android.gms.maps.SupportMapFragment"
            xmlns:map="http://schemas.android.com/apk/res-auto"
            android:id="@+id/TheMap"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            map:mapType="satellite"
            map:uiRotateGestures="false"
            map:uiScrollGestures="false"
            map:uiTiltGestures="false"
            map:uiZoomControls="false"
            map:uiZoomGestures="false"
        />

        <LinearLayout
            android:id="@+id/MapOverlay"
            android:clickable = "true"
            android:onClick="mapOverlayClick"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="80dp"
            android:paddingBottom="80dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:background="#00000000"
        >   
            <TextView  
                android:id="@+id/HintView"
                android:layout_width="match_parent" 
                android:layout_height="match_parent"
                android:textSize="15sp"
                android:background="#AA000000"
                android:padding="10dp"
                android:gravity="center"
                android:visibility="invisible"
            />
        </LinearLayout>

    </FrameLayout>

</LinearLayout>

And I use this line to retrieve the GoogleMap object in the code:

GoogleMap theMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.TheMap)).getMap();

I can't figure out what the problem is, maybe I think I'm signing the application with the debug key specified above... but actually the real used key is in another path?

Community
  • 1
  • 1
TheUnexpected
  • 3,077
  • 6
  • 32
  • 62
  • Did you try to generate the hash from the debug key and put it on facebook/google api console? Location of the key can be found from Eclipse/ADTBundle as Windows->Preferances->Android->Build – Aman Gautam Aug 16 '13 at 09:45
  • Yes, I did, read the first bullet of the second list. For the record, I'm not using Eclipse but Netbeans. – TheUnexpected Aug 16 '13 at 09:48

2 Answers2

1

I have facing same issue like this ,My problem is solved by print out the key hash sent to Facebook. put this code for getting the keyhash

try {
    PackageInfo info = getPackageManager().getPackageInfo(
          "com.facebook.login", PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) 
        {
           MessageDigest md = MessageDigest.getInstance("SHA");
           md.update(signature.toByteArray());
           Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    }
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
RINK
  • 620
  • 5
  • 15
  • It raises an exception: `android.content.pm.PackageManager$NameNotFoundException: com.facebook.login` I tried also with com.facebook and com.facebook.Session – TheUnexpected Aug 16 '13 at 10:28
  • Replace "com.facebook.login" with your application pacakge name. – RINK Aug 16 '13 at 10:41
  • IT WORKS! It prints "o/+Atjbc8IUCIc8yPrG0ACf6dac=", that's not in the form I've expected. I thought I needed to put the SHA-1 hash like BB:0D:AC:74:D3:21:E1:43:<...>. I've updated it in the Facebook Dev page and now the login works. How about Google now? – TheUnexpected Aug 16 '13 at 10:47
  • read this link, its help you http://www.vogella.com/articles/AndroidGoogleMaps/article.html – RINK Aug 16 '13 at 10:58
0

I have also faced the same problem while implementing the Google Map. Please be notices that the key you have generated from keytool should not be the debug key. It should be the that you fetch from the keystore file generated while exporting the signed application package.

If you want to run the .apk over the client side, you need to follow the above mechanism else for debugging at your own end. please validate whether the API key you have provided must not be expired.

Check your manifest for correct entries.

  <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyA9oeVdgN9F-8VOAXmCj1-WlAEk" />
Anchit Mittal
  • 3,412
  • 4
  • 28
  • 48
  • "Please be notices that the key you have generated from keytool should not be the debug key. It should be the that you fetch from the keystore file generated while exporting the signed application package." Can't understand why, I've always used the debug's SHA-1 and it worked for days. Also the API key is valid. – TheUnexpected Aug 16 '13 at 10:30
  • 1
    it is because when you are developing anything and running on emulator or the device attached to it, is acceptable with Debug key. But while using the .apk installation over another device or system or at client side. they need a key which is generated at the time of creating the build. As if it differs it will generate an error that you have received – Anchit Mittal Aug 16 '13 at 10:37
  • I solved the problem with Facebook, not with Google. Now I've prepared a release key with the NBAndroid tool ("Export Signed Android Package"). It produces a release-key.keystore and I've retrieved it's SHA-1 for the Google's APIs Console dialog. It continues to show a blank map. – TheUnexpected Aug 16 '13 at 11:01
  • verify your new API key received from google API console that you have provided in manifest file. – Anchit Mittal Aug 16 '13 at 11:05
  • It's still valid, because changing the list of SHA-1s doesn't change the main API key. – TheUnexpected Aug 16 '13 at 11:10
  • This is what i want to explain you that it wud change everytime when you provide with the changed SHA-1 Key. Please visit - https://code.google.com/apis/console/ --> API Access and now here generate a new Android Key with new SHA-1 and update your manifest with the provided API key – Anchit Mittal Aug 16 '13 at 11:18
  • Done... and nope, same effect. Do you need some other information about my source code? – TheUnexpected Aug 16 '13 at 11:55
  • ya please provide me with the code where you tried to get Fragment Manager for Maps – Anchit Mittal Aug 16 '13 at 11:59
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/35594/discussion-between-anchit-and-alessandro-francesconi) – Anchit Mittal Aug 16 '13 at 12:14