导入 com.google.android.gms 无法解析 [英] The import com.google.android.gms cannot be resolved

查看:46
本文介绍了导入 com.google.android.gms 无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Android 开发的新手.按照本教程,我遇到了错误导入com.google.android.gms 无法解析 当我将代码写入MainActivity.java 时:

I am new to Android development. By following this tutorial I got errors The import com.google.android.gms cannot be resolved when I wrote the code into the MainActivity.java:

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

通过搜索各种修复,我确保尝试了这些:

By searching for various fixes I made sure to try these out:

  • 我已通过以下方式下载了特定 API 级别的 Google APIAndroid SDK 管理器.
  • 我检查了 Google API 作为项目构建目标.
  • 我添加了 <uses-library android:name="com.google.android.maps"/>AndroidManifest.xml 作为 <application> 标记的子行添加到 AndroidManifest.xml 中.
  • 我通过选择 Project->Clean... 来清理项目并构建它从头开始.
  • 我通过右键单击我的项目为地图添加了 .jar 文件,然后在我的 SDK 中构建路径并添加外部存档:android-sdk-windowsadd-onsaddon_google_apis_google_inc_8libsmaps
  • I have downloaded Google API's for a particular API level through Android SDK manager.
  • I checked off Google API as project build target.
  • I have added <uses-library android:name="com.google.android.maps" /> line into the AndroidManifest.xml as a child of <application> tag.
  • I cleaned the project by selecting Project->Clean... and built it from scratch.
  • I included .jar file for maps by right-clicking on my project, went to build path and added external archive locating it in my SDK: android-sdk-windowsadd-onsaddon_google_apis_google_inc_8libsmaps

不幸的是,以上都没有帮助.

Unfortunately, none of the above have helped.

推荐答案

我检查了 Google API 作为项目构建目标.

I checked off Google API as project build target.

这无关紧要,因为这适用于 Maps V1,而您正在尝试使用 Maps V2.

That is irrelevant, as that is for Maps V1, and you are trying to use Maps V2.

我通过右键单击我的项目包含地图的 .jar 文件,转到构建路径并添加外部存档以将其定位在我的 SDK 中:android-sdk-windowsadd-onsaddon_google_apis_google_inc_8libsmaps

I included .jar file for maps by right-clicking on my project, went to build path and added external archive locating it in my SDK: android-sdk-windowsadd-onsaddon_google_apis_google_inc_8libsmaps

这是双重错误.

首先,切勿在 Android 项目中手动修改构建路径.如果您这样做,充其量会在运行时崩溃,因为您认为放入项目(通过手动构建路径更改)的 JAR 不在您的 APK 中.对于普通的第三方JAR,把它放在你项目的libs/目录下,它会自动将它添加到你的构建路径中将它的内容添加到你的APK文件中.

First, never manually modify the build path in an Android project. If you are doing that, at best, you will crash at runtime, because the JAR you think you put in your project (via the manual build path change) is not in your APK. For an ordinary third-party JAR, put it in the libs/ directory of your project, which will add it to your build path automatically and add its contents to your APK file.

但是,Maps V2 不是 JAR.它是一个包含 JAR 的 Android 库项目.您需要整个库项目.

However, Maps V2 is not a JAR. It is an Android library project that contains a JAR. You need the whole library project.

您需要将 android-sdk-windowsadd-onsaddon_google_apis_google_inc_8 项目导入 Eclipse,然后将其添加到您的应用程序 作为对 Android 库项目的引用.

You need to import the android-sdk-windowsadd-onsaddon_google_apis_google_inc_8 project into Eclipse, then add it to your app as a reference to an Android library project.

这篇关于导入 com.google.android.gms 无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆