【问题标题】:java.lang.SecurityException: invalid package name: com.google.android.gmsjava.lang.SecurityException:无效的包名:com.google.android.gms
【发布时间】:2013-12-09 15:51:08
【问题描述】:

在三星 Galaxy S2 (GT-i9100),Android 版本 4.3 上测试应用程序时,我得到了这个奇怪的堆栈跟踪。如果有帮助,Bugsense 还会报告 "log data" = {​​u'ms_from_start': u'19915', u'rooted': u'true'} ,所以我不太确定该设备是否已植根(客户端正在测试应用程序,而不是我)。 编辑:当我输入此内容时,客户确认我该设备具有自定义 ROM,如果重要的话。

总之,这是一个完整的堆栈跟踪:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackagename/com.mypackagename.activities.ARActivity}: 

java.lang.SecurityException: invalid package name: com.google.android.gms
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2355)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
    at android.app.ActivityThread.access$600(ActivityThread.java:156)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5303)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
    at dalvik.system.NativeStart.main(Native Method)

Caused by: java.lang.SecurityException: invalid package name: com.google.android.gms
    at android.os.Parcel.readException(Parcel.java:1431)
    at android.os.Parcel.readException(Parcel.java:1385)
    at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:540)
    at android.location.LocationManager.requestLocationUpdates(LocationManager.java:836)
    at android.location.LocationManager.requestLocationUpdates(LocationManager.java:430)
    at android.privacy.surrogate.PrivacyLocationManager.requestLocationUpdates(PrivacyLocationManager.java:290)
    at com.mypackagename.activities.ARActivity.onCreate(ARActivity.java:371)
    at android.app.Activity.performCreate(Activity.java:5259)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1098)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)

现在,ARActivity.java:371 正在调用

locationManager.requestLocationUpdates(GPS, gpsRefreshPeriod, 0, locListener);

在哪里

private String GPS = "gps";
private int gpsRefreshPeriod = 500;

而 locListener 是 locationListener。

现在,我不知道这里可能出了什么问题,而且我无法在我的测试设备(Samsung Galaxy Tab2、Motorola Atrix 4G、Samsung Note2、Galaxy Nexus)上重现此错误。

我想可能会以某种方式检查 com.google.android.gms,并且可能存在 Intent(或其他东西),如果丢失该包,用户会更新设备的组件。但我完全没有确定我是否会带着这种想法走向正确的方向。

对这次崩溃有什么想法或经验吗?

谢谢。

【问题讨论】:

    标签: java android gps locationmanager


    【解决方案1】:

    尝试使用

    <uses-library android:name="com.google.android.gms" />
    

    在应用程序标签下。示例

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <uses-library android:name="com.google.android.gms" />
    

    【讨论】:

      【解决方案2】:

      我用于测试的一些设备不具备支持 gps 和获取位置的功能,这就是我得到异常的原因

      “无效的包名:com.google.android.gms”

      我们必须添加所需的权限

      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>  
      

      非常重要的是为 GPS 添加 android:required=false"

        <uses-feature
               android:name="android.hardware.location.gps"
               android:required="false" />
      

      更多信息:uses-feature>

      【讨论】:

      • 感谢您分享您的经验。我的测试仪使用带有自定义 ROM 的根深蒂固的三星 Galaxy S2,但我无法获得有关那里安装了哪种自定义 ROM 的信息。我会尝试在您的建议中添加使用功能部分,因为到目前为止我只有这两个权限,假设它们对于 GPS 驱动的应用程序来说已经足够了。虽然我认为解决这个问题的机会非常渺茫,因为测试人员在启动我的应用程序之前已经启用了 GPS 并使用 fakeGPS 应用程序伪造了位置。
      • uses-feature 设置只会过滤您在 Google Play 商店中的应用程序。用户仍然可以旁加载应用程序,它仍然会崩溃。我们需要的是一个基于代码的解决方案,这样我们就可以检测并捕获这个错误。如果有人能确定是什么自定义 ROM 导致了这个问题,那将是最有帮助的。
      【解决方案3】:

      在我看来,这台设备根本没有安装 GoogleApps 应用程序。自定义 ROM 实际上可能是一个提示。例如,该设备的所有者可能已经安装了 Cyanogenmod,但他忘记了(或故意没有安装)Google Apps,它们由separately 提供。

      【讨论】:

        【解决方案4】:

        【讨论】:

        • 感谢您的建议。第一个链接也是唯一涵盖相同问题的链接。第三个链接非常有用,但我已经这样做了(忘了在问题中提及)。问题可能在那个 lib 项目的版本中,我发现我使用的是 3.2.x,只是将其更改为 4.x(最新可用),所以看看是否仍然存在问题。反正看来肯定是自定义ROM的问题。
        猜你喜欢
        • 2011-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-13
        • 1970-01-01
        • 2014-06-23
        • 1970-01-01
        相关资源
        最近更新 更多