1. Download our Official Android App: Forums for Android!

Apps Cannot Import com.google.android.gms.GoogleMap

Discussion in 'Android Development' started by ac4android, Mar 7, 2016.

  1. ac4android

    ac4android Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    53
    Posts:
    198
    Joined:
    Nov 3, 2015

    Nov 3, 2015
    198
    29
    53
    Hi.

    I have re-factored my codes to use a fragment instead of an activity, but now I cannot import anything from com.google.android. There are no error messages, just android highlighted in red.

    I am on Android Studio 1.5.1 (not Eclipse! ) and I've used its SDK-Manager to install everything related to Google from API17 upward (4.2.2)

    Can someone point me in the right direction please?

    This is my ShowMapFragment.java
    Code (Text):
    1.  
    2. import android.content.Context;
    3. import android.os.Bundle;
    4. import android.support.v4.app.Fragment;
    5. import android.view.LayoutInflater;
    6. import android.view.View;
    7. import android.view.ViewGroup;
    8. import android.support.v4.app.FragmentActivity;
    9.  
    10. // cannot import any of the following after refactoring my codes,
    11. // they were OK in the activity that I have replaced.
    12. import com.google.android.gms.maps.MapView;
    13. import com.google.android.gms.maps.CameraPosition;
    14. import com.google.android.gms.maps.CameraUpdate;
    15. import com.google.android.gms.maps.CameraUpdateFactory;
    16. import com.google.android.gms.maps.GoogleMap;
    17. import com.google.android.gms.maps.OnMapReadyCallback;
    18. import com.google.android.gms.maps.SupportMapFragment;
    19. import com.google.android.gms.maps.model.LatLng;
    20. import com.google.android.gms.maps.model.MarkerOptions;
    21.  
    22. public class ShowMapFragment extends Fragment implements OnMapReadyCallback {
    23.  
    24.     private GoogleMap gMap;
    25.     MapView mapView;
    26.     double SITE_LATITUDE = 34.092809;
    27.     double SITE_LONGITUDE = -118.328661;
    28.     // private final LatLng frLatLng = new LatLng(36.778261,-119.41793);
    29.     @Override
    30.     public View onCreateView(LayoutInflater inflater,
    31.                 ViewGroup container,
    32.                 Bundle savedInstanceState) {
    33.         View view = inflater.inflate(R.layout.fragment_show_map,
    34.                 container,
    35.                 false);
    36. // etc...
    37.  
    This is my simple fragment_show_map.xml
    Code (Text):
    1.  
    2.  
    3. <?xml version="1.0" encoding="utf-8"?>
    4. <com.google.android.gms.maps.MapView
    5.     xmlns:android="http://schemas.android.com/apk/res/android"
    6.     android:id="@+id/mapView"
    7.     android:layout_width="match_parent"
    8.     android:layout_height="match_parent" />
    9.  
    10.  

    This is my manifest.xml
    Code (Text):
    1.  
    2.  
    3. <?xml version="1.0" encoding="utf-8"?>
    4. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    5.     package="com.mytestproject.android101">
    6.  
    7.  
    8.     <permission
    9.         android:name="com.mytestproject.android101.permission.MAPS_RECEIVE"
    10.         android:protectionLevel="signature" />
    11.     <uses-permission android:name="com.mytestproject.android101.permission.MAPS_RECEIVE" />
    12.     <uses-permission android:name="android.permission.INTERNET" />
    13.     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    14.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    15.     <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSSERVICES" />
    16.     <!-- The following 2 permissions are not required to use Google Maps Android API v2, but are recommended. -->
    17.     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    18.     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    19.     <!--
    20.          Because version 2 of the Google Maps Android API requires OpenGL ES version 2,
    21.         you must add a <uses-feature> element as a child of the manifest element in AndroidManifest.xml
    22.     -->
    23.     <uses-feature
    24.         android:glEsVersion="0x00020000"
    25.         android:required="true" />
    26.  
    27.     <application
    28.         android:allowBackup="true"
    29.         android:icon="@mipmap/ic_launcher"
    30.         android:label="@string/app_name"
    31.         android:supportsRtl="true"
    32.         android:theme="@style/AppTheme">
    33.  
    34.         <uses-library android:name="com.google.android.maps" />
    35.  
    36.         <meta-data
    37.             android:name="com.google.android.maps.v2.API_KEY"
    38.             android:value=" Google gave me an API " />
    39.  
    40.  
    41.         <activity
    42.             android:name=".TopLevelActivity"
    43.             android:label="@string/app_name"
    44.             android:theme="@style/AppTheme.NoActionBar">
    45.             <intent-filter>
    46.                 <action android:name="android.intent.action.MAIN" />
    47.  
    48.                 <category android:name="android.intent.category.LAUNCHER" />
    49.             </intent-filter>
    50.         </activity>
    51.  
    52.         <activity
    53.             android:name=".ListProjectsActivity"
    54.             android:label="@string/title_activity_list_projects"
    55.             android:theme="@style/AppTheme.NoActionBar" />
    56.  
    57.         <activity
    58.             android:name=".ListDeliveriesActivity"
    59.             android:label="@string/title_activity_list_deliveries"
    60.             android:theme="@style/AppTheme.NoActionBar"></activity>
    61.     </application>
    62.  
    63. </manifest>
    64.  
    65.  
    66.  
     

    Advertisement

    #1 ac4android, Mar 7, 2016
    Last edited: Mar 7, 2016
  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Recognized Developer
    Rank:
     #12
    Points:
    1,988
    Posts:
    9,176
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    9,176
    13,681
    1,988
    Male
    Software developer
    South West of England
    Sounds like you got a jar library missing, or have you changed the Gradle build file recently and removed a dependency you shouldn't have?
     
  3. ac4android

    ac4android Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    53
    Posts:
    198
    Joined:
    Nov 3, 2015

    Nov 3, 2015
    198
    29
    53
    U r spot on and absolutely right... again.

    I forgot to update my build.gridle :rolleyes:
     
    LV426 likes this.

Share This Page

Loading...