17

I'm really stuck here. So, I follow this tutorial step by step: but it still doesn't work.

I've done all steps from tutorial and find out what new module(GooglePlayServices) not in modules, if open run->edit configurations in general->module i don't see GooglePlayServices, I suppose this is the problem, but I can't find what I have to do to fix it.

Day early I tried same, but in this case (I actually don't remember what I did) GooglePlayServices in modules and I don't have anymore problem with cannot resolve symbol 'maps', but it still doesn't work, fires error Error inflating class fragment

my activity extends FragmentActivity

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class MainActivity extends FragmentActivity {

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

}

in both case build.gradle just like in tutorial:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
    compile project(':GooglePlayServices')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 17
    }
}

and settings.gradle:

include ':Roadatus', ':GooglePlayServices'

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.SupportMapFragment"/>
Naitro
  • 458
  • 1
  • 3
  • 11

3 Answers3

28

try to avoid including entire google play services, it will force you to enable multidex due to the package size. instead, include them individually, eg:

compile 'com.google.android.gms:play-services-maps:8.3.0'

if you wish to include other services, please refer here:

https://developers.google.com/android/guides/setup (scroll down)

James Tan
  • 1,336
  • 1
  • 14
  • 32
  • if you were forced to use multidex, here is an article on how to speed up multidex development http://stackoverflow.com/questions/30177495/gradle-android-studio-build-too-slow-multidex-application – James Tan Dec 31 '15 at 04:35
  • 1
    This answer helped me lot understanding the issue, but the actual `compile 'com.google.android.gms:play-services-maps:8.3.0'` causing a crash that `Error inflating class fragment crash`. While i update the play service version to latest one like `implementation 'com.google.android.gms:play-services-maps:15.0.1'` the crash was resolved and finally i see my map <3 – Ratul Sharker Jul 23 '18 at 15:37
  • @RatulSharker there has been update, your version should be the right one – James Tan Jul 26 '18 at 04:40
16

I have tried and failed many a tutorial on this, but finally find a simple solution that seem to work.

I just installed Android Studio 0.2.3 on my mac, and these are the steps that made me view a maps fragment on a fresh hello world project template:

1) Click the SDK manager button in the toolbar in Android Studio.

2) Under 'Extras' locate 'Google play services' and download it.

3) in your build.gradle file in your src directory, add this line to dependencies:

compile 'com.google.android.gms:play-services:3.1.36'

4) order and install your API-key following this tutorial: https://developers.google.com/maps/documentation/android/start#the_google_maps_api_key

5) add the fragment to your layout xml:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"/>

6) you should now be able to run your project on your device.

monopoint
  • 719
  • 1
  • 6
  • 12
  • 2
    Please mind that the fragment must be `com.google.android.gms.maps.SupportMapFragment` if you support older versions. – JJD Sep 16 '13 at 20:40
1

In SDK manager install these from Extras:

  • Android Support Repository
  • Google Repository
  • Google Play services

Then build.gradle should look like this:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.0'
    }
}
apply plugin: 'android'

dependencies {
    //compile files('libs/android-support-v4.jar')
    compile 'com.google.android.gms:play-services:3.1.36'

}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 14
    }
}

I also had to comment this line in build.gradle:

//compile files('libs/android-support-v4.jar')

More on this: https://plus.google.com/+AndroidDevelopers/posts/4Yhpn6p9icf

Igor Benko
  • 1,236
  • 7
  • 12