4

I wrote a basic map application, the one that an be easily instantiated with AndroidStudio. The only difference the fragment is loaded inside another custom layout.

package com.wayl.activities;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import com.wayl.R;

public class MapsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);

        FragmentManager myFragmentManager = getSupportFragmentManager();
        SupportMapFragment mapFragment = (SupportMapFragment) myFragmentManager.findFragmentById(R.id.map);
        GoogleMap mMap = mapFragment.getMap();

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-35, 152);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker near Sidney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
[...]

As said above, the app works perfectly in the AVD, but no way to make it work on a real device. It shows just an empty map placeholder, and also the colourful Google logo is there. But no markers, no grid, no buttons, nothing else.

Why I think it should work:

  • Network, wifi, are ok, both on the phone as in the AVD

  • The OpenGL version shouldn't be a problem, I'm running the apk both on a Galaxy Samsung S3, and on a Galaxy Note 4.

  • I placed my fingerprints both for debug and release version retrieved with keytool and connected with my keystore, so key it's OK, you can also see the reference image, even if it said this is optional. I put both the base package and the package containing the Maps activity just for being sure.

  • I waited enough time for the app to fetch the location, and for the fingerprint to propagate in case this would be needed.

  • Manifest has all the correct permission to retrieve coarse and fine location (remember in the AVD everything works perfectly)

I already succeed in the past to develop a map on Android. I remember each time after 4 or 5 trial and errors on the frustrating process I could achieve it. This time I don't know what to do more. I'm exploting S.O. to understand where I am mistaking.

Community
  • 1
  • 1
Sandor Mezil
  • 390
  • 1
  • 4
  • 16

2 Answers2

8

I finally came to a solution.

In the new AndroidStudio sample, the file with the key (google_maps_api.xml) has been placed to the folder app\src\debug\res\values, and another one in app\src\release\res\values!

While AndroidStudio show you all layouts, all values files, and so on, there is just one value file with the key, so I couldn't notice there were actually two files in the file system, one with the key not setup! I didn't even now there could be different folder for that.

I struggled few days on this. It happens every time I try to create a simple maps, something is changed, pop ups and make me lose time. When you catch the solution everything seems so obvious, but in the meanwhile it's really frustrating.

Thank you to everybody helped! I really appreciated.

Sandor Mezil
  • 390
  • 1
  • 4
  • 16
1

You have to check app that you're trying to install on a device. It should be signed with release key (while emulator uses debug key)!

Ksenia
  • 3,453
  • 7
  • 31
  • 63
  • Hello @ksenia. Thank you for the answer, but, the app for the release is already signed with the release key (i.e., from AndroidStudio: Build>Generate Signed APK). The release key has been used to retrieve the SHA fingerprint as in the image (the second pair). I also let you note that I deactivate proguard (set to false) just to remove some possible cause of error. – Sandor Mezil Dec 15 '15 at 15:02
  • did you add release key fingerprint to your google developers account and changed it in your project? – RexSplode Dec 15 '15 at 15:08
  • @SandroScarano, are you sure that (in AndroidStudio: Build>Generate Signed APK) in drop-down list "Build Type" the value is "release", not "debug"? – Ksenia Dec 15 '15 at 15:11
  • @RexSplode yes, unless I am missing something is what I did, as in the steps explained in the third point of the answer and in the comment above. – Sandor Mezil Dec 15 '15 at 15:25
  • @Ksenia Yes, it is built as "release" I always do those steps to try the app on my phone, also before the release on the store. I double checked anyway. – Sandor Mezil Dec 15 '15 at 15:26