Android教程中Google地图的问题

时间:2014-01-20 03:41:02

标签: android google-maps gradle build-error

嘿伙计们,我一直在尝试按照谷歌在Android开发者网站上使用谷歌地图的教程。毋庸置疑,我无法使这个东西工作,它有多个错误。所以我从Youtube切换到一个,这也给了我错误。我想做的就是让地图出现。我无法使用的错误发布在下面。我真的希望你们能给我一个关于做什么的线索。非常感谢任何帮助。

另外人们注意到,每当我遇到问题时,我都会搜索它并尝试多次“修复”。因此,代码中的任何不一致都会由此产生。

错误:

  

Gradle:任务执行失败':GoogleMapsDemoV2:compileDebug'。

     
    

编译失败;有关详细信息,请参阅编译器错误输出。

  
     

C:\用户\ Josebz \ AndroidStudioProjects \ GoogleMapsDemoV2Project \ GoogleMapsDemoV2 \ SRC \主\的java \ COM \示例\ googlemapsdemov2 \ MainActivity.java

无论如何,这是我的所有代码......

主要活动

package com.example.googlemapsdemov2;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;

public class MainActivity extends ActionBarActivity {

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

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        switch (item.getItemId()) {
            case R.id.action_settings:
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

}

Android Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.googlemapsdemov2"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

    <permission
        android:name="com.example.googlemapsdemov2.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.googlemapsdemov2.permission.MAPS_RECEIVE"/>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <!-- The following two permissions are not required to use
         Google Maps Android API v2, but are recommended. -->
    <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"/>


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyAL5Xq8scMIHnWXITSOLN9QipVkri4A-lI"/>

        <activity
            android:name="com.example.googlemapsdemov2.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >


    <TextView
        android:id="@+id/header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_below="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
    />
</RelativeLayout>

的build.gradle

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

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.android.support:support-v13:13.0.+'
    compile 'com.google.android.gms:play-services:3.2.25'
}

3 个答案:

答案 0 :(得分:0)

在AndroidManifest.xml中的MAP_KEY行之前添加以下两行

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

答案 1 :(得分:0)

1-您必须首先确保您的SDK中安装了 GOOGLE PLAY SERVICES

对于这个开放的 Eclipse Winhows Androi SDK Manager ,并检查您是否已经下载了?

2-将其导入Eclipse

在Eclipse中转到文件导入 Android 现有Android代码进入工作区

并从

找到播放服务库项目

<强> Android的SDK窗口\额外\谷歌\ google_play_services \ libproject \谷歌播放-services_lib

谷歌地图获取谷歌地图密钥的三个非常重要的要点

为此转到Eclipse窗口选项卡&gt;偏好&gt; Android&gt;构建然后复制SHA-1指纹。

然后点击此link,然后转到Services标签,然后搜索Google Map API v2并将设置为,并与Goofle Play Android Dev API相同,然后转到API ACCESS标签,然后 Create new Android key..

由于

答案 2 :(得分:0)

首先尝试使用清单文件的应用部分下面提到..

<meta-data
 android:name="com.google.android.gms.version"
 android:value="@integer/google_play_services_version" />

对于Ex:您的清单文件..

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.googlemapsdemov2"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

    <permission
        android:name="com.example.googlemapsdemov2.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.googlemapsdemov2.permission.MAPS_RECEIVE"/>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <!-- The following two permissions are not required to use
         Google Maps Android API v2, but are recommended. -->
    <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"/>


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
       <!--Your Google API Key -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyAL5Xq8scMIHnWXITSOLN9QipVkri4A-lI"/>

        <activity
            android:name="com.example.googlemapsdemov2.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

其次,如果你在较低版本的android上测试相同,那么你需要使用SupportMapFragment。试试这个..

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_below="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
    />

希望它能解决您的问题并让我知道是否有任何疑虑..