谷歌播放服务库没有复制到Eclipse上的Android项目中的lib文件夹..

时间:2015-08-30 09:40:03

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

在使用谷歌地图V2进行大量搜索,为什么我的应用程序在部署在设备上时崩溃,我发现虽然我已将Google Play服务导入我的工作区,并且&# 34;添加"库,Google Play服务库没有出现在我项目的lib文件夹中。 任何人都知道为什么会这样,解决方案是什么? 非常感谢提前。

1 个答案:

答案 0 :(得分:0)

请按照以下步骤操作:

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

机器人:ID = “@ + ID /地图”

机器人:layout_width = “match_parent”

机器人:layout_height = “match_parent”

类= “com.google.android.gms.maps.SupportMapFragment”/&GT;

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

GoogleMap map =((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

机器人:名称= “com.google.android.maps.v2.API_KEY”

机器人:值= “YOUR_API_KEY”/&GT;

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