带有gradle和Google Maps v2的Android Studio

Nai*_*tro 17 android google-maps gradle android-studio

我真的被困在这里了.所以,我一步一步地遵循本教程:但它仍然不起作用.

我已完成教程中的所有步骤,并找出哪些新模块(GooglePlayServices)不在模块中,如果我看不到打开run->edit配置,我想这是问题,但我找不到我要做的事情修理它.general->moduleGooglePlayServices

一天早我尝试了同样的,但在这种情况下(我实际上不记得我做了什么)GooglePlayServices在模块中我没有任何问题cannot resolve symbol 'maps',但它仍然无法正常工作,触发错误Error inflating class fragment

我的活动延伸了 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);
    }

}
Run Code Online (Sandbox Code Playgroud)

在这两种情况下build.gradle就像在教程中一样:

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
    }
}
Run Code Online (Sandbox Code Playgroud)

并且settings.gradle:

include ':Roadatus', ':GooglePlayServices'
Run Code Online (Sandbox Code Playgroud)

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"/>
Run Code Online (Sandbox Code Playgroud)

Jam*_*Tan 28

尽量避免包含整个Google Play服务,但由于包装尺寸的原因,它会强制您启用multidex.相反,单独包括它们,例如:

compile 'com.google.android.gms:play-services-maps:8.3.0'
Run Code Online (Sandbox Code Playgroud)

如果您希望包含其他服务,请参阅此处:

https://developers.google.com/android/guides/setup (向下滚动)


mon*_*int 16

我已经尝试过很多关于此的教程,但最终找到了一个似乎有用的简单解决方案.

我刚刚在我的mac上安装了Android Studio 0.2.3,这些是让我在新的hello world项目模板上查看地图片段的步骤:

1)单击Android Studio工具栏中的SDK管理器按钮.

2)在'Extras'下找到'Google Play服务'并下载它.

3)在src目录的build.gradle文件中,将此行添加到依赖项:

compile 'com.google.android.gms:play-services:3.1.36'
Run Code Online (Sandbox Code Playgroud)

4)按照本教程订购并安装API密钥:https://developers.google.com/maps/documentation/android/start#the_google_maps_api_key

5)将片段添加到布局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"/>
Run Code Online (Sandbox Code Playgroud)

6)您现在应该能够在您的设备上运行您的项目.

  • 请注意,如果您支持旧版本,则片段必须为"com.google.android.gms.maps.SupportMapFragment". (2认同)