【问题标题】:Google play services library not copying into lib folder..in Android project on EclipseGoogle Play 服务库未复制到 lib 文件夹中。在 Eclipse 上的 Android 项目中
【发布时间】:2015-08-30 09:40:03
【问题描述】:

经过大量搜索为什么我的应用程序在设备上部署时崩溃,同时使用 Google Maps V2,我发现虽然我已将 Google Play 服务导入我的工作区并“添加”库,但 Google播放服务库没有出现在我项目的 lib 文件夹中。 任何人都知道为什么会发生这种情况,解决方案是什么? 非常感谢。

【问题讨论】:

  • 请发布您的 logcat 以防崩溃。

标签: android google-maps google-play-services


【解决方案1】:

按照以下步骤操作:

Create a new project

File -> New -> Android Application Project
You can leave all the options with their default values
Choose BlankActivity in the Create Activity screen

Ensure you have the latest version (v2) of the Google Play Services installed.

Select Window > Android SDK Manager or run android at the command line.
Scroll to the bottom of the package list and select Extras > Google Play services. The Google Play services SDK is downloaded to your computer and installed in your Android SDK environment at <android-sdk-folder>/extras/google/google_play_services/

Add the Google Play Services project into your Eclipse workspace.

Click File -> Import..., select Android -> Existing Android Code into Workspace
Browse to and select <android-sdk-folder>/extras/google/google_play_services/libproject/google-play-services_lib

To add the dependency to Google Play Services into your project

Project -> Properties -> Android -> Library, Add -> google-play-services_lib

Update MainActivity.java  to extend FragmentActivity instead of Activity
Check that Google Play Services is available on the device at runtime to protect against error cases

GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

Update res/layout/activity_main.xml and replace the entire contents with

android:id="@+id/map"

android:layout_width="match_parent"

android:layout_height="match_parent"

class="com.google.android.gms.maps.SupportMapFragment"/>

The map is controlled through the GoogleMap object, use findFragmentById to keep a reference to the GoogleMap from the layout.

GoogleMap 地图 = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))

           .getMap();

要使用 Google Maps API,您需要一个 API 密钥:

Go to the Google APIs Console
In Services enable ‘Google Maps Android API v2’ and agree to the terms
In the left navigation bar, click API Access.
Click Create New Android Key....
In the resulting dialog, enter the SHA-1 fingerprint, then a semicolon, then your application's package name. For example:

BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75;com.example.android.mapexample

If you have debug and production keys then add both in.

To obtain the SHA1 of your debug certificate use keytool:

keytool -list -alias androiddebugkey -keystore ~/.android/debug.keystore -storepass android -keypass android -v

For Windows computers the .android directory is in your user directory
Your new API key will be a 40 character string like AIzbSyBaEqeUpYvlsbUe0OqTPn1-ABVMHVbdNxo

Add the following tag into your AndroidManifest.xml just before the closing </application> tag

android:name="com.google.android.maps.v2.API_KEY"

android:value="your_api_key"/>

Your application now also needs the following permissions in the AndroidManifest.xml

     android:name="your_package_name.permission.MAPS_RECEIVE"

     android:protectionLevel="signature"/>

Optionally you can include one or both of these permissions to enable auto-location

Maps v2 uses OpenGl so the following uses-feature is also required

Test your application, checking the logcat output for any errors.
If it is working try out some of the other GoogleMap options:

mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
mMap.setMyLocationEnabled(true);
more details at

https://developers.google.com/maps/documentation/android/views

归属要求。如果您在应用程序中使用 Google Maps Android API,则必须将 Google Play 服务归属文本作为“法律声明”部分的一部分包含在您的应用程序中。建议将法律声明作为一个独立的菜单项,或作为“关于”菜单项的一部分。可通过调用 GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo 获得归属文本。

来源:HERE

【讨论】:

  • 谢谢 - 但我有一个 WORKING 地图应用程序是在大约 4 个月前创建的,使用了以上所有内容。
  • 我的问题是 google-play-services-lib 没有作为 jar 出现在较新的应用程序的 LIB 文件夹中,即使我在 Properties/Android/Libraries add-上..
猜你喜欢
  • 1970-01-01
  • 2016-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-03
  • 1970-01-01
相关资源
最近更新 更多