【问题标题】:App crashing on first launch from play store应用程序在从 Play 商店首次启动时崩溃
【发布时间】:2020-02-04 13:23:34
【问题描述】:

当我从 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>

【问题讨论】:

    标签: android performance android-layout android-intent


    【解决方案1】:

    如果设备上未安装 Google Play 服务 apk,或者对于您的应用要求而言太旧,则可能会出现此问题。

    您可以通过以下方式检查是否有最低 Google Play Service 版本可用:

    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();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-19
      • 1970-01-01
      • 2014-10-24
      相关资源
      最近更新 更多