应用程式在Play商店首次启动时当机

时间:2019-10-07 08:57:31

标签: android performance android-layout android-intent

当我从android studio安装它时,该应用程序运行正常,但是当我从playstore下载该应用程序时,该应用程序在首次启动时崩溃,此后运行正常。

这是我在崩溃日志中得到的。

Fatal Exception: java.lang.RuntimeException: Unable to instantiate receiver 
com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver:
java.lang.ClassNotFoundException: Didn't find class"com.google. android.gms.measurement.AppMeasurementInstallReferrerReceiver" 
on path: DexPathList[[zip file "/data/app/==/base.apk"],nativeLibraryDirectories =[/data/app==/lib/arm64, /==/base.apk!/lib/arm64-v8a, /system/lib64, /product/lib64]]

我对此进行了搜索,并更新了gradle文件,但是崩溃仍然存在。

  force 'com.google.firebase:firebase-analytics-impl:16.0.0'
  force 'com.google.android.gms:play-services-measurement-base:16.0.0'
  force 'com.google.android.gms:play-services-measurement-sdk:16.0.1'
  force 'com.google.android.gms:play-services-measurement-sdk-api:16.0.1'
  force 'com.google.android.gms:play-services-measurement-impl:16.0.0'

我还在清单文件中添加了以下内容,以避免崩溃。

<receiver
        android:name="com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver"
        android:permission="android.permission.INSTALL_PACKAGES"
        android:enabled="true">
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER"/>
        </intent-filter>
    </receiver>

1 个答案:

答案 0 :(得分:0)

如果未在设备上安装Google Play服务apk,或者对于您的应用程序要求而言它太旧,则会发生此问题。

您可以按照以下步骤检查是否可以使用最低的Google Play服务版本:

Dialog errorDialog;

private boolean checkPlayServices() {

        GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();

        int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(this, minApkVersion);

        if (resultCode != ConnectionResult.SUCCESS) {
            if (googleApiAvailability.isUserResolvableError(resultCode)) {

                if (errorDialog == null) {
                    errorDialog = googleApiAvailability.getErrorDialog(this, resultCode, 2404);
                    errorDialog.setCancelable(false);
                }

                if (!errorDialog.isShowing())
                    errorDialog.show();

            }
        }

        return resultCode == ConnectionResult.SUCCESS;
}

minApkVersion是您的应用所需的最低Google Play服务apk版本。

并在应用程序的启动画面的onResume()中调用此方法:

@Override
protected void onResume() {
    super.onResume();
    if (checkPlayServices()) {
        startApp();
    }
}
相关问题