这个应用程序需要更新Google Play服务(通过Bazaar),否则无法运行。

102

我正在测试新的Google Maps API V2 for Android,当应用程序启动时出现以下消息:

MainActivity showing error message

这是在一个4.1模拟器上运行。

这是我的AndroidManifest.xml文件:

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

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

    <permission
        android:name="com.example.maptest.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.maptest.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <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"/>

    <!-- Require OpenGL ES version 2 -->
    <uses-feature
          android:glEsVersion="0x00020000"
          android:required="true"/>

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

        <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>

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

    </application>
</manifest>

文件 MainActivity.java:

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

文件 activity_main.xml 的操作

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.MapFragment"/>
</RelativeLayout>

点击“更新”会导致应用程序崩溃并显示以下堆栈跟踪:

E/Trace(1034): error opening trace file: No such file or directory (2)
W/GooglePlayServicesUtil(1034): Google Play services out of date.  Requires 2010100 but found 1
W/GooglePlayServicesUtil(1034): Google Play services out of date.  Requires 2010100 but found 1
W/GooglePlayServicesUtil(1034): Google Play services out of date.  Requires 2010100 but found 1
W/GooglePlayServicesUtil(1034): Google Play services out of date.  Requires 2010100 but found 1
W/GooglePlayServicesUtil(1034): Google Play services out of date.  Requires 2010100 but found 1
W/GooglePlayServicesUtil(1034): Google Play services out of date.  Requires 2010100 but found 1
D/gralloc_goldfish(1034): Emulator without GPU emulation detected.
D/AndroidRuntime(1034): Shutting down VM
W/dalvikvm(1034): threadid=1: thread exiting with uncaught exception (group=0x40a13300)

E/AndroidRuntime(1034): FATAL EXCEPTION: main
E/AndroidRuntime(1034): android.content.ActivityNotFoundException: No Activity found to handle Intent
  { act=android.intent.action.VIEW dat=http://play.google.com/store/apps/details? \
  id=com.google.android.apps.bazaar flg=0x80000 pkg=com.android.vending }
E/AndroidRuntime(1034):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
E/AndroidRuntime(1034):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
E/AndroidRuntime(1034):     at android.app.Activity.startActivityForResult(Activity.java:3351)
E/AndroidRuntime(1034):     at android.app.Activity.startActivityForResult(Activity.java:3312)
E/AndroidRuntime(1034):     at android.app.Activity.startActivity(Activity.java:3522)
E/AndroidRuntime(1034):     at android.app.Activity.startActivity(Activity.java:3490)
E/AndroidRuntime(1034):     at com.google.android.gms.internal.c$2.onClick(Unknown Source)
E/AndroidRuntime(1034):     at android.view.View.performClick(View.java:4084)
E/AndroidRuntime(1034):     at android.view.View$PerformClick.run(View.java:16966)
E/AndroidRuntime(1034):     at android.os.Handler.handleCallback(Handler.java:615)
E/AndroidRuntime(1034):     at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(1034):     at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(1034):     at android.app.ActivityThread.main(ActivityThread.java:4745)
E/AndroidRuntime(1034):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(1034):     at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(1034):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime(1034):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime(1034):     at dalvik.system.NativeStart.main(Native Method)

我还参考了Google Play服务项目。我做错了什么?

更新

在Google问题跟踪器中相应的bug (https://issuetracker.google.com/issues/35822258) 一段时间前已经被解决。

现在,您可以像这个答案中所述那样,在模拟器中使用Google Maps Android API并创建具有Play服务的虚拟设备:

https://dev59.com/YWUq5IYBdhLWcg3wY_ga#46246782


你是使用带有Google API的AVD还是纯Android? - Selvin
纯Android,虽然我刚尝试切换到4.1的Google API,但是情况一样。 - soren.qvist
包含的示例MapDemo怎么样?它对你来说可以吗?我的在同一模拟器上崩溃并出现ExceptionInInitializationError。 - soren.qvist
2
提出 - http://code.google.com/p/gmaps-api-issues/issues/detail?id=4627 - gazreese
显示剩余9条评论
12个回答

56

更新:

谷歌地图API v2现已安装在最新的谷歌系统镜像(api:19 ARM或x86)上。
因此,您的应用程序应该可以与新镜像一起正常工作。不需要安装这些文件。

我一直在尝试在模拟器下运行Android Google Maps V2应用程序,当我终于成功运行Google Play服务后,我将我的SDK更新到了Google Play服务版本4,但是我的模拟器无法再运行我的应用程序。

我现在已经找出如何从我的Transformer平板电脑更新模拟器的方法。(您不需要平板电脑,因为您可以下载下面的文件。)

我使用钛备份来备份我的Asus Eee Pad Transformer(TF101),然后从备份中取出了com.android.vending和com.google.android.gmsAPK文件。

我将它们安装在配置有平台:4.1.2、API级别:16、CPU Intel/Atom x86的模拟器上,我的Google Maps V2应用程序又可以工作了。

那就是全部内容...不需要其他涉及/system/app的步骤。

我的应用程序只使用Google Maps API,如果您使用其他的Google Play服务,则需要更多步骤。

最新的Google Play服务文件:

与之前相同的说明:创建一个带有任何CPU/ABI、非Google API目标(版本为10-19)和开启或关闭GPU仿真的新模拟器,然后安装这些文件:

adb install com.android.vending-20140218.apk
adb install com.google.android.gms-20140218.apk
如果您正在升级现有的模拟器,则可能需要通过以下方式卸载先前的版本:
adb uninstall com.android.vending
adb uninstall com.google.android.gms

就这些。


1
根据http://developer.android.com/google/play-services/index.html。只要设备还具有GL ES版本2,那么安卓2.2(即API级别8)的设备就足够了。 - Jarl
1
我尝试安装这些文件,但adb向我显示了安装失败的消息,说这些文件已经安装过了。我尝试重新安装,然后它又说证书不一致。那我该怎么办呢? - huong
@Martynas 我也有“EGL_emulation: eglSurfaceAttrib未实现”,但地图仍然可以正常工作。 - Dan Brough
我发现谷歌的ARM镜像API:19修订版:3只适用于maps-v2。但是x86的不行..很奇怪。 - Dan Brough
请查看http://stackoverflow.com/q/25685873/968532,你有任何想法吗? - Kalpesh
显示剩余7条评论

42

根据Google+上与Android开发者的讨论,目前无法在模拟器上运行新版地图API。

(该评论来自Zhelyazko Atanasov于昨天23:18,我不知道如何直接链接到它)

此外,在实际设备上运行时,您看不到“(通过Bazaar)”部分,更新按钮会打开Play商店。我假设Bazaar旨在为Android模拟器提供Google Play服务,但目前尚未准备好……


我尝试直接将最新的GmsCore.apk复制到模拟器中,但这也不起作用。如果我确切地知道从我的root设备中复制哪些APK文件,那么它可能会起作用。 - James Wald

39

我花了一整天的时间在Android模拟器上配置新的gmaps API(Google Maps Android API v2)。我在网上找到的所有方法都不能正常工作。但最终我还是成功了。以下是我的步骤:

  1. 创建一个具有以下配置的新模拟器:

Enter image description here

在其他版本中,由于安装必要应用程序时出现各种错误,我无法进行配置。
2)启动模拟器并安装以下应用程序:
  • GoogleLoginService.apk
  • GoogleServicesFramework.apk
  • Phonesky.apk
您可以使用以下命令进行操作:
2.1) adb shell mount -o remount,rw -t yaffs2 /dev/block/mtdblock0 /system
2.2) adb shell chmod 777 /system/app
2.3-2.5) adb push Each_of_the_3_apk_files.apk /system/app/

链接下载APK文件。我已从我的rooted Android设备中复制它们。

3) 在模拟器上安装Google Play服务Google地图。如果我从Google Play商店安装它们,会出现错误491。我将应用程序上传到模拟器并在本地运行安装(您可以使用 adb 来安装此应用程序)。以下是这些应用程序的链接:

4) 经过这些步骤后,我成功在模拟器上运行了一个演示样例。这是一个截图:

Google Maps


我认为这个方法有一些不必要的步骤。尝试一下其他答案中提到的只需要安装两个 APK 的方法吧... - Nemanja Kovacevic
我尝试了你的方法,但是在将应用程序加载到system/app目录时,adb生成了一个错误,说没有足够的可用空间。使用大量内存创建新的模拟器也没有帮助。在其他版本的模拟器上,你的方法也不起作用。 - Paha
1
在第三步中,安装命令为 adb install com.google.android.apps.maps-1.apkadb install com.google.android.gms-2.apk - sulai
请确保获取适合您需求的Google Play服务版本。您可以从http://www.papktop.com/tag/google-play-services-apk下载它们。 - sulai
请确保您始终安装最新的Google Play APK版本,因为当前版本的Google Play v2不允许您安装更新(会出现错误491),而这个更新是运行Google Maps应用程序所必需的。 - Serhiy

29

我正在回答这个问题,因为我尝试过但一开始不起作用的解决方案现在已经起作用了,我可以重新创建步骤以使其有效 :)

我也有一种感觉,缺少Google Play商店是罪魁祸首,所以我尝试按照这个链接这个链接的建议安装Google Play商店到模拟器中。我遇到了一些困难,但最终成功安装了Google Play商店,并通过下载一些随机应用程序进行了测试。但是,地图活动仍然显示带有“更新”按钮的消息。该按钮会将我带到商店,但在那里我会收到“未找到项目”的消息,地图仍然不能正常工作。此时我放弃了。

昨天,我无意中启动了同样的测试应用程序,它却起作用了!我很困惑,但很快从能够工作的模拟器和新的干净模拟器中进行了比较,并确定了/data/app/目录中工作模拟器上的两个应用程序:com.android.vending-1.apk和com.google.android.gms-1.apk。这很奇怪,因为当我按照那些网站的说明安装Google Play商店时,我是将Phonesky.apk、GoogleServicesFramework.apk和GoogleLoginService.apk推送到不同的/system/app文件夹中。

无论如何,现在我的模拟器上可以使用Android Google Maps API v2了。以下是实现此目标的步骤:


创建一个新的模拟器

  • 对于device,选择“5.1'' WVGA(480 x 800: mdpi)”
  • 对于target,选择“Android 4.1.2 - API level 16”
  • 对于“CPU/ABI”,选择“ARM”
  • 其余保留默认设置

以下是适用于我的设置。我不知道其他设置是否适用。


开始运行模拟器


通过ADB install命令安装com.android.vending-1.apkcom.google.android.gms-1.apk


现在,您的模拟器应该可以使用Google Maps了。


这是我的博客链接,里面有关于我尝试使这个工作正常的描述:http://nemanjakovacevic.net/blog/2012/12/how-to-make-android-google-maps-v2-work-in-android-emulator/ - Nemanja Kovacevic
很不幸,Google Play服务修订版4出现了新错误:Google Play服务已过期。需要2012100但找到的是2010110。 - Ilja S.
3
如果您使用的是Play服务第四版,请参考@danbrough的回答,并下载评论中指定的APK文件:链接 - Ilja S.
1
请注意,这也适用于x86,使模拟器更加流畅! - Caffeine

3

我已经创建了一个(德语)说明如何使其工作。 你需要一个至少API级别为9且没有Google API的模拟器。然后你需要从一个已root的设备获取APK文件:

adb -d pull /data/app/com.android.vending-2.apk
adb -d pull /data/app/com.google.android.gms-2.apk

并在模拟器中安装它们:

adb -e install com.android.vending-2.apk
adb -e install com.google.android.gms-2.apk

如果您拥有至少API 14的模拟器并且安装了com.google.android.apps.maps-1.apk,则甚至可以运行原生Google Maps应用程序。

祝您玩得开心。


2

除非您更新Google Play服务,否则此应用程序将无法运行。我已经尝试了很长时间,但仍然没有得到地图...即使我修改了下面评论中提供的我的Google Play服务,仍然只出现空白屏幕。


检查您的Play服务清单文件,并检查APK文件com.google.android.gms的版本代码。在下面的示例中,它是“3136110”。从DOS提示符下载这些APK文件并安装,但在安装之前请运行目标模拟器。

package="com.google.android.gms"
android:versionCode="3136110"
android:versionName="3.1.36 (673201-10)

我从这个链接获取了这些APK文件。


2
我一直在尝试在模拟器上运行Android Google Maps v2,我找到了很多方法,但都没有成功。我总是在Logcat中看到这个警告:Google Play服务过期。需要3025100,但只有2010110,当我想要在模拟器上更新Google Play服务时,什么也没发生。问题在于,com.google.android.gms APK与我的Android SDK库版本不兼容。
我在模拟器上安装了这些文件“com.google.android.gms.apk”、“com.android.vending.apk”,我的应用程序Google Maps v2运行良好。没有其他关于/system/app的步骤是必需的。

1
这些是需要安装的文件:vending.apkgms.apk - Adil

2
我通过以下步骤解决了这些问题:
  • 在模拟器中:

    您必须使用最新的API Google APIs(Google Inc.)- API Level 19

    其余的步骤如截图所示。

    enter image description here

  • API密钥:

    创建新的API密钥,并仔细检查Google地图API密钥和SHA密钥。

  • Google Play服务:

    您必须下载最新的Google Play服务 com.android.vending-4.8.20.apk。如果该网站的Google Play服务无法正常工作,那么您可以在互联网上找到许多名为com.android.vending 4.8.20.apk的网站。

    您可以使用命令提示符运行Google Play服务 adb install com.android.vending 4.8.20.apk

    注意:您必须下载最新的Google Play服务,因为每年都会在互联网上更新最新版本。

    输出结果

    enter image description here


1
@JJD 我已经进行了编辑,请检查一下。这样就可以工作了。感谢你的指出。 - Stephen

0

在更新到ADT 22.0.1之后,由于Android私有库的原因,Google Maps服务出现了一些错误并导致应用程序崩溃。所以我最终找到了解决方案,并且它对我起作用了。

只需安装Google Play服务库,然后从https://www.dropbox.com/sh/2ok76ep7lmav0qf/9XVlv61D2b进入google-play-service/libproject/google-play-services_lib。将其导入您的工作区。清理您想要使用gogole-play-services-lib的项目,然后重新构建它,进入Project -> Properties -> Java BuildPath -> 选择"Android Private Libraries, Android Dependencies, google-play-service"

在属性中,转到Android,然后选择任何版本,然后选择添加并选择google-play-service-lib,然后按应用并最后确定。

最后,进入项目 -> Android工具 -> Android支持库。接受许可证并安装后运行您的项目。

它会正常工作。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接