Troubleshoot

Some common errors you might face in development when using Ionic 4 Full App

1. Google plus plugin - GooglePlus.java:151: error: cannot access AbstractSafeParcelable.addApi(Auth.GOOGLE_SIGN_IN_API, gso.build())

This error can appear because of a mismatch in versions of Google libraries. E.g. You might have a build.gradle file that looks like this

compile "com.google.android.gms:play-services-ads:16.0.0"
compile "com.android.support:support-v4:27.1.1"
compile "com.soundcloud.android:android-crop:1.0.0@aar"
compile "com.facebook.android:facebook-android-sdk:4.25.0"
compile "com.google.android.gms:play-services-auth:11.8.0"
compile "com.google.android.gms:play-services-identity:11.8.0"
compile "com.android.support:support-annotations:27+"

Here, play-services-ads , play-services-auth and play-services-identity do not have a common version, which can cause troubles in APK builds. Changes the versions of the libraries to a common version, and preferably to latest version.

To make this change, sometime changing versions in build.gradle or config.xml alone is not sufficient. You might have to change the dependency of all plugins which are using Google services to use the latest version. To do this,

  • Remove the platform e.g. Android.

  • Search for PLAY_SERVICES_VERSION in plugins folder of the app, and change all versions to a common latest one (in our case 16.0.0)

  • Re-build platform

If you are successful in changing all version of Google dependencies, you build.gradle should look like this

compile "com.google.android.gms:play-services-ads:16.0.0"
compile "com.android.support:support-v4:27.1.1"
compile "com.soundcloud.android:android-crop:1.0.0@aar"
compile "com.facebook.android:facebook-android-sdk:4.25.0"
compile "com.google.android.gms:play-services-auth:16.0.0"
compile "com.google.android.gms:play-services-identity:16.0.0"
compile "com.android.support:support-v4:27+"

Also, make sure platforms/android/project.properties has the same versions

2. Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'

This error is primarily caused by non-mergeable library versions of android support libraries.

  • In some cases , setting multidexenabled = true in build.gradle can fix the problem

  • In a severe case, you might need to change all support dependencies to same version, and a definite one E.g. In above build.gradle -- support-v4:27.1.1 and support-v4:27+ might look compatible, but they can resolve to different versions. You can check better if you open the gradle files in Android Studio. It will give you warnings related to different versions. To resolve this, look for ANDROID_SUPPORT_V4_VERSION in your plugins, config.xml and package.json and change that to a common, definite version like 27.0.1 After changing these versions, remove the platform and re-build.

3. class file for com.google.android.gms.internal.zzbfm not found

Solution same as #1

4. com.android.dex.DexException: Multiple dex files define Lcom/google/zxing/BarcodeFormat;

If this error exists (in addition or without #2), then this is likely caused by a conflict between Facebook Plugin and Barcode Scanner plugin, because both plugins provide scannig libraries.

In this case, changing Facebook plugin version to 4.25.0 resolves the issue at the time of writing.

As an alternative, you can also add the following at the end of build.gradle to fix the issues

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == "com.facebook.android") {
details.useVersion "4.25.0"
}
}
}

A detailed discussion can be found here

5. error: cannot find symbol AppEventsLogger.augmentWebView((WebView) this.webView.getView(), appContext);

This error happens in Facebook version 4.25.0 due to a clash with Barcode Scanner plugin

Make sure you have the following config

$ cordova -v
8.0.0
<plugin name="phonegap-plugin-barcodescanner" spec="^7.0.0">
<variable name="CAMERA_USAGE_DESCRIPTION" value=".." />
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="..." />
</plugin>
<plugin name="cordova-plugin-facebook4" spec="^4.0.0">
<variable name="APP_ID" value="..." />
<variable name="APP_NAME" value="..." />
<variable name="FACEBOOK_ANDROID_SDK_VERSION" value="4.25.0" />
</plugin>

Use cordova platform add android@6.4.0 --save.

Remove any cordova-*-gradle plugins if you have them installed (cordova-android-support-gradle-release).

An alternative is to comment out

AppEventsLogger.augmentWebView((WebView) this.webView.getView(), appContext);

at platforms/android/app/src/main/java/org/apache/cordova/facebook/ConnectPlugin.java:717

This will not affect the Facebook login process. The commented out line is relevant to Hybrid Mobile App Events

6. UnhandledPromiseRejectionWarning: Error: /Users/abhijeetrathore/Ionic4FullApp/platforms/android/gradlew: Command failed with exit code EACCES

This error can occur when you sync Gradle using android studio and a newer version is installed. In that case, the Gradle folder in not write accessible for ionic/cordova

Running following commands should resolve it

$ sudo chmod 777 /Applications/Android\ Studio.app/Contents/gradle/gradle-4.1/bin/gradle
sudo
$ chmod 777 /Users/abhijeetrathore/Ionic4FullApp/platforms/android/gradlew