无法设置Google Play服务

索南斯·凯尔(Somnath Kayal)

我被困一天以上才能使用Google Play服务。这是Google创建的非常糟糕的过程。为什么这么难?我想使用Google Play服务来开发一些依赖于Map的应用程序。我已经一步步尝试了一切,在许多站点上都进行了讨论,但仍然无法实现。我认为只有StackOverflow可以在这种情况下提供帮助。我无法提供所有参考网站的链接,但我提供了其中一些参考网站-http:
//developer.android.com/google/play-services/setup.html#Setup
http://www.vogella.com /tutorials/AndroidGoogleMaps/article.html#installmaps
设置Google Play游戏服务
我正在使用Eclipse ADT Bundle。Google Play服务在Android SDK中带有带勾号的标记,表明已安装。它也位于正确的目录中。我正在提供我的项目的快照-在此处输入图片说明


上面的快照显示了activity_main.xml,启动应用程序时的错误和项目树结构。它还显示google_play_service_lib已导入。

public class MainActivity extends ActionBarActivity {

static final LatLng HAMBURG = new LatLng(53.558, 9.927);
  static final LatLng KIEL = new LatLng(53.551, 9.993);
  private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

     map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap();
        Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
            .title("Hamburg"));
        Marker kiel = map.addMarker(new MarkerOptions()
            .position(KIEL)
            .title("Kiel")
            .snippet("Kiel is cool")
            .icon(BitmapDescriptorFactory
                .fromResource(R.drawable.ic_launcher)));

        // Move the camera instantly to hamburg with a zoom of 15.
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

        // Zoom in, animating the camera.
        map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}

该项目没有任何错误。我还将代码添加到proguard-project.txt中,并且android-manifest.xml是

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.latlongfrommap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="17"
    android:targetSdkVersion="19" />

<uses-permission android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.latlongfrommap.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

     <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyAQXXXXXXXXXXXXXXpADfMsO4fF0eEXdRE" />
</application>

我也从控制台生成了API密钥。activity-main的图形布局也有警告。在此处输入图片说明 在此处输入图片说明

Please Help me out by your valuable advise. Thanking you.
EDIT:
In the official set up guide, they didn't mention that jar file should be added to the library.. I did that because I found it in many websites.. is It correct??.. The fragment tag is not detected by the activity_main.xml.. is there any problem with that??
Yes, I was right about the jar file. It should not be added. It was creating some kind of conflict. But I still have errors

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.latlongfrommap/com.example.latlongfrommap.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2314)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
at android.app.ActivityThread.access$800(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
at android.app.Activity.setContentView(Activity.java:2154)
at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
at com.example.latlongfrommap.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:5953)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1128)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
... 10 more
Caused by: java.lang.SecurityException: The Maps API requires the additional following permissions to be set in the AndroidManifest.xml to ensure a correct behavior:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
at com.google.maps.api.android.lib6.c.ck.a(Unknown Source)
at com.google.maps.api.android.lib6.c.i.a(Unknown Source)
at com.google.maps.api.android.lib6.c.el.a(Unknown Source)
at com.google.maps.api.android.lib6.c.ab.a(Unknown Source)
at com.google.maps.api.android.lib6.c.aa.a(Unknown Source)
at com.google.android.gms.maps.internal.x.onTransact(SourceFile:107)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
at com.google.android.gms.maps.MapFragment$a.onCreateView(Unknown Source)
at com.google.android.gms.dynamic.a$4.b(Unknown Source)
at com.google.android.gms.dynamic.a.a(Unknown Source)
at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
at android.app.Fragment.performCreateView(Fragment.java:2053)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1045)
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1147)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2118)
at android.app.Activity.onCreateView(Activity.java:5302)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
... 23 more
Somnath Kayal

Thank God. Finally it's done. Many websites said that, after doing all the stuff describing at the official tutorial site you need to do some extra things. Some of them are really helpful and some are not. Before you waste your complete day like me, remember the below things-

  1. "you have to add the google-play-services.jar externally to the library". That's entirely NOT TRUE. If you have already imported the google-play-services_lib project which is the first step of the official guide and again adding the jar, it will create a conflict to your program. So either you add the jar or import the google-play-services_lib project.
  2. Generate API Key using Google Developers Console. This step is really important and make sure the key has been attached to your manifest using meta tag.

    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyAQ8XXXXXXXXXXXXXXXXXxxxxxxeEXdRE" />

To generate the key you'll need to know the package name of the project and SHA1 fringerprint which can be found by clicking the window -> Preferences -> Android -> Build.
    3. You have to add some permissions

<uses-permission android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  1. 在你做官方指导的步骤4中,您需要将值添加到string.xml其可以在这里找到res/values你的项目树的目录。

    <integer name="google_play_services_version">5089000</integer>

    可以在其中找到版本号的位置 sdk\extras\google\google_play_services\libproject\google-play-services_lib\res\values\version.xml

  2. <fragment>标签activity-main.xml可能会向您显示一些尴尬的警告。不用担心

  3. 确保选中“订单和导出”中的“ Android私人图书馆”选项它实际上链接了包含所有库项目。要做到这一点:google-play-services_libProperties -> Build Path -> Order and Export -> check Android Private Libraries

  4. 最后但并非最不重要的一点是,在执行任何操作之前,您必须先清理项目。为此,请转到project-> clean并确保Build Automatically已选中。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章