【问题标题】:Xamarin.Forms.Maps crashed on android 7+Xamarin.Forms.Maps 在 android 7+ 上崩溃
【发布时间】:2019-10-20 04:13:42
【问题描述】:

我是一名初学者 xamarin.forms 开发人员,我已经为我的城镇开发了一些带有谷歌地图的免费应用程序。

该应用程序可以在所有 Visual Studio (2019) 的 android 模拟器甚至我的旧手机 (android 4.3) 上完美运行。

申请发布也成功了。

但是,在他的手机 (android 9) 上安装该应用程序的第一个用户向我报告说该应用程序已崩溃。只是在显示(尝试)地图时崩溃,没有任何错误消息。但是应用程序的任何其他(没有地图)“ContentPage”都可以正常工作。仅当用户尝试使用地图控件打开 ContentPage 时才会发生崩溃。

因为我没有真正的 android 9 设备(并且在所有 Visual Studio 的 android 模拟器上该应用程序都可以工作),所以我安装了 Nox 播放器:
https://www.bignox.com/
并创建了 2 个可用的模拟器:android 5.1.1 和 android 7.1.2
结果: 该应用程序成功在 android 5 上运行 并在 android 7 上崩溃(与 android 7 模拟器一起 - 模拟器程序只是关闭而没有任何错误消息)。

好的。我创建了一个最简单的测试 xamarin 表单地图应用程序 - 仅显示地图,仅此而已。

MainPage.xaml:

<ContentPage.Content>
    <map:Map />
</ContentPage.Content>

同样的故事:适用于所有 Visual Studio 的 android 模拟器,适用于我的旧 android 4.3 设备,适用于 nox-player android 5 并在 nox android 7 上崩溃!

然后,我尝试从 microsoft 文档中编译示例。例如:
https://docs.microsoft.com/en-us/samples/browse/?products=xamarin&term=Xamarin.Forms.Maps
所有这些样品都放在这里:
https://github.com/xamarin/xamarin-forms-samples/tree/master/WorkingWithMaps
我刚刚下载了解决方案,将我的“com.google.android.maps.v2.API_KEY”替换为 AndroidManifest.xml 并编译它。没有更多的动作。
结果:完全相同的行为。

更准确地说,最初我使用了 Xamarin.Forms.GoogleMaps 包: https://github.com/amay077/Xamarin.Forms.GoogleMaps
相同结果。

在此页面上还有已编译的 apk 上的链接,其中包含示例: https://install.appcenter.ms/users/okuokuoku/apps/xfgooglemapsample/distribution_groups/trial
结果:一样。

请问,谁知道是什么原因?

更多信息:

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.comscreen.App1" android:installLocation="internalOnly">
    <uses-sdk android:minSdkVersion="22" android:targetSdkVersion="28" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <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_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:label="App1.Android" android:usesCleartextTraffic="true" android:icon="@mipmap/launcher_foreground">
        <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="MY_API_KEY_SORRY_FOR_HIDING" />
    </application>
</manifest>

【问题讨论】:

  • 导致崩溃的异常是什么?您是否尝试过捕捉它,或查看设备日志以获取与崩溃相关的信息?
  • 杰森,谢谢你的回答!不幸的是,我没有任何 android 7 或 9 真实设备。我只能在 android 7 Nox Player 模拟器上重现此崩溃(在所有 Visual Studio 的 android 模拟器上,该应用程序都可以正常工作)。所以我无法捕捉到这个崩溃/异常。当应用程序在 android 7 nox-emulator 上崩溃时,模拟器程序也崩溃并直接关闭,没有任何错误消息。
  • 尝试安装像 appcenter.ms 这样的崩溃报告工具,看看它是否可以为您捕获任何有用的信息

标签: xamarin.forms xamarin.forms.maps


【解决方案1】:

由于您没有提供任何错误代码,我只能怀疑两个原因:

  1. 也许map 在新版本的android 中需要某种权限?再次检查
  2. 在创建 APK 时,您是否检查了所有架构? 在 Android 选项 -> 高级 -> 支持的架构 -> 选择所有架构下。 更多信息在这里:https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/cpu-architectures?tabs=windows

【讨论】:

  • Bhavya Joshi,谢谢您的回答!这个问题的难点正是没有任何错误信息。正如我所写,带有 android 7 的 Nox 播放器模拟器(我唯一可用的,而不是真实设备)崩溃了(连同应用程序一起),并且在没有任何错误消息的情况下以静默方式关闭。
  • 而且,是的,在发布我的问题之前,我还建议新版本的 android 需要一些额外的权限。我什至创建了具有所有权限的简单应用程序版本 :) 不幸的是,该版本仅适用于 VS 模拟器 - 但在 Nox 模拟器上它崩溃了。要确认(或拒绝)此建议 - 需要迭代不同的权限组合变体。这是无聊的例行公事(不保证肯定的结果),我希望有现成的答案。
  • 真的,为什么没有人感兴趣 - 为什么示例(已经编译为 apk)在 android 7+ 上不起作用?任何人都可以安装演示应用并检查:github.com/amay077/Xamarin.Forms.GoogleMaps
  • googlemaps 演示应用上的直接链接:install.appcenter.ms/users/okuokuoku/apps/xfgooglemapsample/…
  • 我已在 Android 9.0 中安装了您的应用,并且运行良好。因此,一定只有某些设备存在问题。再说一遍,在 xamarin 中创建 APK 之前,您是否选择了所有架构?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-04
  • 1970-01-01
相关资源
最近更新 更多