【问题标题】:AVD Cannot test any application using AVDAVD 无法使用 AVD 测试任何应用程序
【发布时间】:2013-12-12 03:12:11
【问题描述】:

我有一个非常奇怪的问题,我使用运行 4.0.3 操作系统的 HTC One V 开发了我的应用程序。现在,该应用程序在我的和少数其他随机 2.2 和 2.3 和 4+ 设备上运行良好,但在某些设备上,尽管它们具有 GooglePlayStore,但应用程序启动并加载但不显示地图,尽管它们具有 GPStore 应用程序崩溃说 GPStore/Service 不存在。

我尝试在 AVD Devies 上测试该应用程序,但它们都没有安装 GooglePlayStore。我尝试了Google Play on Android 4.0 emulator 方法将 GPStore 推送给他们,但没有成功。

我的 droid SDK 已全面更新:

我编译我的应用程序

在我的主要活动中,我检查是否存在 Google Play 服务/商店以确定是否可以使用 GoogleMaps:

public class Map extends FragmentActivity implements Observer
{
  private MapAgent agent;
  private Locator  locator;
  private Spinner  spinner;
  private Button   gps;

  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);

    // Get a new instance of Locator agent
    locator = new Locator();

    // Register as Observer to Locator agent
    locator.addObserver(this);

    // Check if Internet connection is available
    if(Services.connectivityServiceState(this))
    {
      // We have a working Internet connection
      // Check if we have a GooglePS in operating mode
      if(Services.playServiceState(this))
      {
        // Load the map
        setContentView(R.layout.activity_map);

        // Fetch dropdown list & gps button reference
        spinner = (Spinner) findViewById(R.id.bankslist);
        gps     = (Button)  findViewById(R.id.gpsbttn);

        // Register event listener with gps button
        gps.setOnClickListener(new GpsAction(this));

        // Register event listener with spinner
        spinner.setOnItemSelectedListener(new SpinnerAction());

        // Fetch our map
        agent = new MapAgent(this);

        // Move map camera to initial position
        agent.initialPosition();



      } else {
        // GooglePS is not in operating mode
        Messages.playNotificationMessage(this);
      }

    } else {
      // No Internet connection
      // Prompt user to turn on WiFi or Mobile
      Messages.internetConnectionRequestMessage(this);
    }
  }

检查 GooglePlay 服务状态的方法位于我的 Services.java 中:

public class Services
{
  /**
   * OPERATING CODES
   */
  private static final int GPS_ERR_REQUEST = 9000;

  /**
   * Test device for GooglePlayServices, required for
   * GoogleMaps API V2.
   * 
   * @param  Activity
   * @result boolean
   */
  public static boolean playServiceState(Activity context)
  {
    // Fetch GooglePS operating code
    int code = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);

    // Check if GooglePS is operating
    if(code == ConnectionResult.SUCCESS)
    {
      // We have GooglePS in working condition
      return true;
    }

    // We have an error, check if it can be resolved by user
    /*if(GooglePlayServicesUtil.isUserRecoverableError(code))
    {
      // We can solve this error pull up GooglePS guide dialog
      Dialog guide = GooglePlayServicesUtil.getErrorDialog(code, context, GPS_ERR_REQUEST);

      // Show the guide dialog
      guide.show();

      // Dispose of our activity
      context.finish();
    }*/

    // We do not have GooglePS in operating mode
    // solve error and retry
    return false;
  }

  /**
   * Tests devices Wi-Fi and Mobile network for a
   * working Internet connection.
   * 
   * @param  Activity
   * @return boolean
   */
  public static boolean connectivityServiceState(Activity context)
  {
    // Fetch a CM instance
    ConnectivityManager con = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    // Test both carriers for a working Internet connection
    NetworkInfo wifi = con.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    NetworkInfo mobi = con.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

    // Check for Internet connection
    if(wifi.isConnected() || mobi.isConnected())
    {
      // We have a working internet connection
      return true;
    }

    // No internet connection
    return false;
  }

  /**
   * Test NETWORK service to determine if Google Location
   * services are enabled or not.
   */ 
  public static boolean networkServiceState(Activity context)
  {
    // Fetch a LM instance
    LocationManager provider = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

    // Return true for enabled GLS
    return provider.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
  }

  /**
   * Tests GPS service to determine if GPS
   * is enabled or not.
   * 
   * @param  Activity
   * @result boolean
   */
  public static boolean gpsServiceState(Activity context)
  {
    // Fetch a LM instance
    LocationManager provider = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

    // Return true for enabled GPS
    return provider.isProviderEnabled(LocationManager.GPS_PROVIDER);
  }

  /**
   * Checks if a GPS Radio is present
   * within the device.
   * 
   * @param  Activity
   * @return boolean
   */
  public static boolean hasGPS(Activity context)
  {
    // Refere to devices package manager for GPS service
    return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
  }
}

我的地图只是在我的 MapAgent 类中处理,仅处理标记就没有什么令人印象深刻的了。

  public MapAgent(FragmentActivity context)
  {
    // Fetch the map support fragment
    SupportMapFragment fragment = ((SupportMapFragment) context.getSupportFragmentManager().findFragmentById(R.id.map));

    // Fetch map and view
    map  = fragment.getMap();

    // Set initial zoom
    zoom = 7;

    // Check if this is the first run
    final SharedPreferences prefs = context.getSharedPreferences("slo.bankomati.core", Context.MODE_PRIVATE);

    if(prefs.getBoolean("firstrun", true))
    {
      // Check if database exists and delete it
      if(Database.exists(context))
      {
        Database.delete(context);
      } 
      prefs.edit().putBoolean("firstrun", false);
    }


    // Fetch all atms
    try {
      db = new Database(context);
      atms = db.getAtms();
      db.close();
    } catch (Exception e) {
      // TODO: Temporary solution
    }

    // Create an empty array for filtered results
    filtered = new ArrayList<Atm>();
    markers  = new HashMap<Marker, Atm>();

    // Reference the resources and context
    this.resources = context.getResources();
    this.context   = context;

    // Register camera & info window listener with the map
    map.setOnCameraChangeListener(this);
    //map.setOnInfoWindowClickListener(new ShowDetails(context, resources));
    map.setOnMarkerClickListener(new ShowDetails(context));
  }

我没有任何想法我无法在 AVD 2.2+ 上运行 GooglePlay 服务我尝试了 AVD 4.4 Google Play API 它带有 GPService 但不会显示地图。所以直接指出我的子问题:

1) 如果从 2.2 到 4.4 的所有 AVD 都没有运行 GooglePlay 服务,那么我们如何在没有多部手机的情况下测试多部手机和操作系统版本的应用程序。

2) 是否有确定的方式或更合适的方式在旧设备上显示 GoogleMap 我说的是 Android 2.2+ 我使用最简单的方式来显示我的地图我的布局 xml 中有一个 SupportMap Fragment 元素。我遇到的问题是,某些带有 GooglePlayStore 的 2.2 和 2.3 手机会或不会打开应用程序那些打开应用程序的手机不会显示地图,但它们会在底部显示地图缩放控件和 Google 徽标。

3) 我添加了我的布局文件,但我没有我的 android 手机,并且 AVD 不允许我测试需要 GooglePlayServices 的应用程序是否可能是由于覆盖布局而导致我的布局显示在下面的问题。

我基本上在背景中有一个框架布局,我有谷歌地图,在顶角我有一个微调器和一个按钮。当我上次测试这个应用程序时,它可以在我的手机 HTC One V Android 4.0.3 上运行。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/root_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />

    <Button
        android:id="@+id/gpsbttn"
        android:layout_width="28dp"
        android:layout_height="28dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/gps"
        android:minHeight="28dip"
        android:minWidth="28dip"
        android:text="" />

    <Spinner
        android:id="@+id/bankslist"
        android:layout_width="match_parent"
        android:layout_height="36dp"
        android:layout_marginLeft="48dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:entries="@array/banks_list"
        android:prompt="@string/banks_prompt" />

</FrameLayout>

最简单的解决方案:
对于遇到无法通过 AVD 完全测试您的应用程序的问题的所有朋友,请切换到 Genymotion Emulator,它可以挽救生命。它速度更快,错误更少,并且支持真实手机所做的每一项功能,并使自 2.2 以来的 Android 应用程序测试变得更加容易。

我去了 Genny,再也没有回头。

【问题讨论】:

  • 请注意不要将 Google Play 商店与 Google Play 服务混淆。两者真正共享的是名字;我认为您的问题主要是指 Google Play 服务。
  • 您在 LogCat 中是否有任何异常?我怀疑GooglePlayServicesUtil.isGooglePlayServicesAvailable(context) 会抛出ClassNotFoundException,因为设备中没有名为GooglePlayServicesUtil 的类。在这种情况下,您应该捕获异常并返回false

标签: java android google-maps


【解决方案1】:

根据对此问题的回答:Google Maps - "App won't run unless you update Google Play services",它引用了此 Google+ 帖子:https://plus.google.com/+AndroidDevelopers/posts/Tyz491d96Ci,模拟器不支持在您的应用中使用地图;那个帖子里有很多苦涩的回复。

其中一个回复引用了这个问题:This app won't run unless you update Google Play Services (via Bazaar),它描述了一些模拟器黑客攻击,如果没有其他方法,您可以尝试。

【讨论】:

  • 感谢您的回复,我完全忘记了这个问题。主要是因为我发现了 Genymotion 模拟器,它可以测试从 Android 2.2 到最新版本的 GP 服务相关应用程序。
【解决方案2】:

除了 Scott 提到的解决方法,根据 Play Services 文档,所有面向 4.2.2 或更高版本的 AVD 都将支持 Play Services。:http://developer.android.com/google/play-services/setup.html

还有一些人能够将 Play 服务安装到较旧的 AVD 上,但其合法性可能值得怀疑:

【讨论】:

    【解决方案3】:

    目前,Android Emulator 不允许使用 Google Maps,因为它不支持 Maps API 工作所需的 Google Play Services 应用程序(在 http://www.genymotion.com/ 提供了一个支持 Google Play 服务功能的模拟器。尝试,如果它不起作用,尝试获得一个真正的设备。在模拟器上测试地图应用程序对我来说没有多大意义。我建议在开发设备上投入一点钱。在处理这些类型的情况时,它会收回成本并减少您的头痛。

    更新

    尝试将您的 Android Target 切换为 Google API(相同的目标编号)

    我还从有根设备中提取了 google play services.apk,并通过模拟器上的命令行安装了它。这并不完全推荐,而且可能有点麻烦。

    在文档中,Scott 提供了一个链接,它告诉您要求是Google Play StoreGoogle Play Services.

    【讨论】:

    • 有些系统映像具有 Play Services APK 并支持它。他们都没有 Google Play 商店本身。我认为这里的问题是地图的最新更新不允许第三方应用程序在模拟运行时通过 API 显示地图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-11
    • 1970-01-01
    • 1970-01-01
    • 2014-06-30
    相关资源
    最近更新 更多