5

I have an activity class with several imports but some of them are not recognized in Eclipse. I see the error import class name cannot be resolved.

That is my code:

package com.ap.mapa;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;


public class MapaLugaresActivity extends Activity {

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


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.mapa_lugares, menu);
    return true;
}

}

The errors are in every import com.google.android.gms.maps. If I type another class as import android.content.Context; there are no errors.

How can I fix them?

Thanks.

axmug
  • 476
  • 2
  • 10
  • 26

4 Answers4

28

Make sure you have the api version you are using is a Google API as well as having google play services installed

Google Play Services

  • Open up SDK Manager, scroll to the bottom, expand "Extras", select "Google Play Services", accept and download.

  • After this is installed, import it into the Workspace

    • Import -> Project -> Android -> Existing Android Code into Workspace , check copy to workspace and browse to where your android sdk folder is located: < android sdk folder>/extras/google/google_play_services/libproject/google-play-services_lib
    • Hit Finish

Project

  • Go to project properties, click on Android, click on Google APIs
  • Modify build path to include the recently added jar (google-play-services-lib.jar) [ located under the bin dir of the google-play-service-lib project]
  • You need to make sure that your app is registered with Google
    • Note your package name for this app
    • In order to get this registered with google, you need to verify your SHA1 certificate fingerprint under < android_sdk>.android as debug.keystore
    • Open a cmd window (Im assuming you are working on windows) browse to C:\Program Files\Java\< JDK version> or where ever java is installed type this as a command to get the SHA1 fingerprint:
    • keytool -list -v -keystore "C:\Program Files (x86)\Android\android-sdk.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
      • Where the quoted path (need quotes) is the path to your keystore
      • Right click hit "mark" highlight the text after "SHA1:" hit enter to copy

Google APIs Console So with the SHA1 fingerprint copied, you will need to go to https:\code.google.com/apis/console

  • Under "Google apis", click the drop down and hit "Create", name the API project whatever you want.
    • Services should pop up now, scroll down to "Google Maps API v2 or v3" and "Google Maps Android API v2", click the switch for one of them
    • Click on API Access on the left hand side, bringing you to a screen to "Create new Android key"
    • Remember that SHA1: fingerprint you copied? paste it in the both that comes up then < SHA1 fingerprint text>;< package_name as noted before>

Go back to the project

Back in Project

  • Go to the AndroidManifest.xml

    • Add these permissions to your manifest:

    • Make sure instead of com.example.androidmapsv2, you match your own package name <permission android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE" android:protectionLevel="signature"></permission> <uses-permission android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"/> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-feature android:glEsVersion="0x00020000" android:required="true"/>

    • Under the <application > tag, add this under it:

    • <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="PASTE YOUR SHA1 CERTIFICATE KEY HERE"/>

      • Where the values is from the api console above your SHA1 fingerprint

Its a lot, i realized that, but that is how I used the maps

Vnge
  • 1,295
  • 25
  • 49
  • Yes. I have every step done. But errors are not fixed. When I see Project Properties in Android tab, I can see a red cross on the left reference of the library. Is it normal? – axmug Mar 25 '13 at 20:32
  • 1
    that shouldnt be normal... in referencing this: http://stackoverflow.com/a/14735711/1888585 where you could try to copy the lib next to your project's dir, hit remove and then try to re add it – Vnge Mar 25 '13 at 21:48
  • 1
    Ok. Now it works. The issue was the Google Services library that has an error link. I linked it again and now everything works. Thanks for answering. – axmug Mar 26 '13 at 19:34
1

Try this answer:

The import com.google.android.gms cannot be resolved

  1. Making a library project using the Google Play jar (in the answer above it uses the maps.jar). I used the same jar as used in the @Vnge's reply i.e < android sdk folder>/extras/google/google_play_services/libproject/google-play-services_lib

  2. After that library project is in the workspace, refer to that project from your current one i.e which is giving errors. The way to do this is provided in the link in my answer. And also @Alex answer in the link.

hope it helps you.

Community
  • 1
  • 1
user_3068807
  • 397
  • 3
  • 13
0

@axmug. You need to add the Google Maps API using Android SDK Manager.

  1. Open the Android SDK Manager.
  2. Check the Google Map API for the particular Android version used in the project:
  3. Install and restart eclipse.

Hope this helps!

0

In Project properties - Android check if library google-play-services_lib.jar has correct path.

Vlad
  • 3,465
  • 1
  • 31
  • 24