Сбой приложения при первом запуске из игрового магазина - PullRequest
0 голосов
/ 07 октября 2019

Приложение работает нормально, когда я устанавливаю его из 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 голосов
/ 07 октября 2019

Эта проблема может возникнуть, если на устройстве не установлена ​​программа Google Play Services или она устарела для требований вашего приложения.

Вы можете проверить, доступна ли минимальная версия Сервиса 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 - это минимальная apk-версия Сервиса Google Play, требуемая вашим приложением.

И вызовите этот метод в Splash Screen вашего приложения onResume():

@Override
protected void onResume() {
    super.onResume();
    if (checkPlayServices()) {
        startApp();
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...