Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在android studio上解析符号“android”_Android_Import_Android Studio_Android Gradle Plugin_Build.gradle - Fatal编程技术网

无法在android studio上解析符号“android”

无法在android studio上解析符号“android”,android,import,android-studio,android-gradle-plugin,build.gradle,Android,Import,Android Studio,Android Gradle Plugin,Build.gradle,我一直在制作一个显示MapView的应用程序,它得到了构建,我甚至在我的设备上使用它 现在我想添加更多的功能,但突然studio给出了错误,无法解析符号“android” 我将studio更新为0.8.6最新版本。。。。但是该死的。。!!没有什么变化 错误: package com.androidhive.googleplacesandmaps; import java.util.List; import android.content.Intent; import android.grap

我一直在制作一个显示MapView的应用程序,它得到了构建,我甚至在我的设备上使用它 现在我想添加更多的功能,但突然studio给出了错误,无法解析符号“android”

我将studio更新为0.8.6最新版本。。。。但是该死的。。!!没有什么变化

错误:

package com.androidhive.googleplacesandmaps;

import java.util.List;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class PlacesMapActivity extends MapActivity {
    // Nearest places
    PlacesList nearPlaces;

    // Map view
    MapView mapView;

    // Map overlay items
    List<Overlay> mapOverlays;

    AddItemizedOverlay itemizedOverlay;

    GeoPoint geoPoint;
    // Map controllers
    MapController mc;

    double latitude;
    double longitude;
    OverlayItem overlayitem;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_places);

        // Getting intent data
        Intent i = getIntent();

        // Users current geo location
        String user_latitude = i.getStringExtra("user_latitude");
        String user_longitude = i.getStringExtra("user_longitude");

        // Nearplaces list
        nearPlaces = (PlacesList) i.getSerializableExtra("near_places");

        mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);

        mapOverlays = mapView.getOverlays();

        // Geopoint to place on map
        geoPoint = new GeoPoint((int) (Double.parseDouble(user_latitude) * 1E6),
                (int) (Double.parseDouble(user_longitude) * 1E6));

        // Drawable marker icon
        Drawable drawable_user = this.getResources()
                .getDrawable(R.drawable.mark_red);

        itemizedOverlay = new AddItemizedOverlay(drawable_user, this);

        // Map overlay item
        overlayitem = new OverlayItem(geoPoint, "Your Location",
                "That is you!");

        itemizedOverlay.addOverlay(overlayitem);

        mapOverlays.add(itemizedOverlay);
        itemizedOverlay.populateNow();

        // Drawable marker icon
        Drawable drawable = this.getResources()
                .getDrawable(R.drawable.mark_blue);

        itemizedOverlay = new AddItemizedOverlay(drawable, this);

        mc = mapView.getController();

        // These values are used to get map boundary area
        // The area where you can see all the markers on screen
        int minLat = Integer.MAX_VALUE;
        int minLong = Integer.MAX_VALUE;
        int maxLat = Integer.MIN_VALUE;
        int maxLong = Integer.MIN_VALUE;

        // check for null in case it is null
        if (nearPlaces.results != null) {
            // loop through all the places
            for (Place place : nearPlaces.results) {
                latitude = place.geometry.location.lat; // latitude
                longitude = place.geometry.location.lng; // longitude

                // Geopoint to place on map
                geoPoint = new GeoPoint((int) (latitude * 1E6),
                        (int) (longitude * 1E6));

                // Map overlay item
                overlayitem = new OverlayItem(geoPoint, place.name,
                        place.vicinity);

                itemizedOverlay.addOverlay(overlayitem);


                // calculating map boundary area
                minLat  = (int) Math.min( geoPoint.getLatitudeE6(), minLat );
                minLong = (int) Math.min( geoPoint.getLongitudeE6(), minLong);
                maxLat  = (int) Math.max( geoPoint.getLatitudeE6(), maxLat );
                maxLong = (int) Math.max( geoPoint.getLongitudeE6(), maxLong );
            }
            mapOverlays.add(itemizedOverlay);

            // showing all overlay items
            itemizedOverlay.populateNow();
        }

        // Adjusting the zoom level so that you can see all the markers on map
        mapView.getController().zoomToSpan(Math.abs( minLat - maxLat ), Math.abs( minLong - maxLong ));

        // Showing the center of the map
        mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLong + minLong)/2 ));
        mapView.postInvalidate();

    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

}
build.gradle文件:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        compile 'com.google.android.gms:play-services:5.0.77'
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}
apply plugin: 'android'

dependencies {

    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 12
    buildToolsVersion "20.0.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

请帮忙。。
提前感谢

建议使用新的Maps v2 API

要使用它,请将以下依赖项添加到build.gradle:

然后按照谷歌的指南进行设置

编辑:为了详细说明build.gradle文件,下面是我的文件

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '20'
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName '1.0'

        applicationId '<package_name>'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        debug {
            debuggable true
            runProguard false
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.+'
    compile 'com.android.support:support-annotations:+'
    compile 'com.google.android.gms:play-services:5.0.77'
}
重要提示:每个项目中都有两个build.gradle文件。将其放入相应模块文件夹内的文件夹中。如果您尚未重命名该模块,则该模块通常称为app


添加后,请确保单击顶部的“使用Gradle文件同步项目”按钮,这样它将下载所需的依赖项

能否显示错误代码。我已发布了我的code@NeverBackDown我担心您将依赖项放在了错误的build.gradle文件中。将其放入模块文件夹中的一个文件夹中。它不应该有类路径'com.android.tools.build:gradle:0.12.+'行。
apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '20'
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName '1.0'

        applicationId '<package_name>'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        debug {
            debuggable true
            runProguard false
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.+'
    compile 'com.android.support:support-annotations:+'
    compile 'com.google.android.gms:play-services:5.0.77'
}