【问题标题】:unable to import com.google.android.maps.* in android studio无法在 android studio 中导入 com.google.android.maps.*
【发布时间】:2016-06-09 04:52:06
【问题描述】:
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

我必须将上述包导入我的应用程序。我做不到。我尝试从 SDK 管理器安装 Google API。它仍然向我显示错误。 另外,我在 build.gradle 中添加了以下依赖项

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

我还是无法导入。

这是我的 build.grade 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'

    defaultConfig {
        applicationId "com.example.incrediblemachine.andhiv"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    compile 'com.google.android.gms:play-services:8.4.0'

}

我的清单文件如下:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.incrediblemachine.andhiv"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

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

        <!--  Add Google Map Library -->
        <uses-library android:name="com.google.android.maps" />

        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <!-- SinglePlaceActivity -->
        <activity android:name=".SinglePlaceActivity" android:label="Place Details">
        </activity>

        <!-- PlacesMapActivity -->
        <activity android:name=".PlacesMapActivity" android:label="Near Places Map View">

        </activity>
    </application>

    <!-- Internet Permissions -->
    <uses-permission android:name="android.permission.INTERNET" />

    <!-- Network State Permissions -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!-- Access Location -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-library android:name="com.google.android.maps" />

</manifest>

【问题讨论】:

  • 你的google play services更新了吗?
  • 尝试像compile 'com.google.android.gms:play-services:8.4.0' 那样指定它的确切版本。另外,检查Google repositories 是否已更新/安装
  • google 存储库已安装。这种依赖没有帮助
  • @BajiraoShinde 符号图无法解析
  • 在这里发布你的清单

标签: android google-maps android-studio import


【解决方案1】:

步骤 1. 将以下依赖项放入 build.gradle 中,位于应用程序模块目录中。

dependencies {
        compile 'com.google.android.gms:play-services-maps:8.4.0'
    }

第 2 步。保存更改并点击工具栏中的 Sync Project with Gradle Files。

【讨论】:

  • 在这种情况下,请发布您的完整 gradle 文件。
【解决方案2】:

改为手动添加该依赖项。执行以下步骤:

  1. 点击文件,然后点击项目结构
  2. modules 下,您会看到一个名为 app 的文件夹
  3. 在步骤 2 中访问所述文件夹,然后您将看到多个选项卡。去输入Dependencies
  4. 您将看到一个绿色的加号按钮,单击并选择Library Dependency

  5. 输入com.google.android.gms:play-services:+ 并单击ok。然后点击另一个ok,等待gradle重新编译

【讨论】:

  • 清理项目。重新打开 Android Studio。如果这些步骤失败,请尝试启动一个新项目,然后手动添加依赖项。这是为了确认该流程在 clean 项目中有效,但由于某些原因,它在您当前的项目中无效。
【解决方案3】:

符号映射无法解析

编译器找不到类。这意味着该类没有正确导入

不要

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

compile 'com.google.android.gms:play-services-maps:8.4.0'
or //compile 'com.google.android.gms:play-services-maps:7.8.0'

然后Clean-Rebuild-Sync你的项目。

<uses-permission android:name="com.example.incrediblemachine.andhiv.permission.MAPS_RECEIVE" />

【讨论】:

  • @JaganP 重启你的项目。
  • 仍然没有运气
  • 如何在 android studio 中为应用程序选择目标名称。这个问题的答案是 eclipse
  • @JaganP 首先添加import com.google.android.gms.maps.GoogleMap;
  • @JaganP 对于compile 'com.google.android.gms:play-services-maps:8.3.0' 有同样的问题?
猜你喜欢
  • 1970-01-01
  • 2012-04-25
  • 2015-11-15
  • 2014-03-20
  • 2015-07-08
  • 1970-01-01
  • 2016-01-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多