Log In

Dependencies conflict (Android)

Symptom

You receive the following error message at compile time:

:transformClassesWithDexForDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzr;

Solution

MOCA Plugin for Cordova / PhoneGap requires the following dependencies on Android:

  • Google Play Services (GPSS) - Cloud Messaging (GCM)
  • GPSS - Location Services
  • GPSS - Ads
  • MessagePack

If you are using other plugins within your project, it is common that some of these plugins rely also on GPSS for some functionality. The problem arises when any of these libraries use a different version of GPSS.

MOCA Plugin expects at least GPSS version 8.3. We provide you the plugin with this version in the plugin configuration, so you can have predictable builds in the future.

In order to fix this issue, please use one of the following solutions:

Option A:

Change the mocabuild.gradle file within the plugin folder and change all the versions to the latest one, bear in mind that your other plugins should also use the same version.

Option B:

Create a file called build-extras.gradle in the following folder your_app_name > platforms > android and paste the following code there.

// When set, this function allows code to run at the end of `build.gradle`
ext.postBuildExtras = {
    configurations.all {
		resolutionStrategy {
      	//Google Cloud Messaging
    		force 'com.google.android.gms:play-services-gcm:+'
    		
      	//Google Location, Activity Recognition, and Places
   			force 'com.google.android.gms:play-services-location:+'

    		//Google Mobile Ads
   			force 'com.google.android.gms:play-services-ads:+'
		}
	}
}

If there is any other plugin that uses any part of GPSS, you should include it here as well, and remember: All GPSS dependencies must use the same version, otherwise you will get errors at Compile or at RunTime.

Below you will find a list of possible GPSS dependencies

# Google+
force 'com.google.android.gms:play-services-plus:+'
# Google Account Login
force 'com.google.android.gms:play-services-auth:+'
# Google Actions, Base Client Library
force 'com.google.android.gms:play-services-base:+'
# Google Address API
force 'com.google.android.gms:play-services-identity:+'
# Google App Indexing
force 'com.google.android.gms:play-services-appindexing:+'
# Google App Invites
force 'com.google.android.gms:play-services-appinvite:+'
# Google Analytics
force 'com.google.android.gms:play-services-analytics:+'
# Google Cast
force 'com.google.android.gms:play-services-cast:+'
# Google Cloud Messaging
force 'com.google.android.gms:play-services-gcm:+'
# Google Drive
force 'com.google.android.gms:play-services-drive:+'
# Google Fit
force 'com.google.android.gms:play-services-fitness:+'
# Google Location, Activity Recognition, and Places
force 'com.google.android.gms:play-services-location:+'
# Google Maps
force 'com.google.android.gms:play-services-maps:+'
# Google Mobile Ads
force 'com.google.android.gms:play-services-ads:+'
# Mobile Vision
force 'com.google.android.gms:play-services-vision:+'
# Google Nearby
force 'com.google.android.gms:play-services-nearby:+'
# Google Panorama Viewer
force 'com.google.android.gms:play-services-panorama:+'
# Google Play Game services
force 'com.google.android.gms:play-services-games:+'
# SafetyNet
force 'com.google.android.gms:play-services-safetynet:+'
# Android Pay
force 'com.google.android.gms:play-services-wallet:+'
# Android Wear
force 'com.google.android.gms:play-services-wearable:+'

Application crashes at startup

Symptom

Application crashes at startup with the following error message

java.lang.ClassCastException: android.app.Application cannot be cast to com.innoquant.moca.phonegap.MOCApp

Solution

MOCA Plugin works even if the app is not running, in order to achieve this functionality, it requires a class to be declared in your AndroidManifest.xml application tag. If the Android platform is already created when you installed MOCA Plugin, this is done automatically by the installation scripts, however it may not work if there is a conflict with other plugin that has the same requirement, or if the android platform is added afterwards.

Open your AndroidManifest.xml and check the application tag, you should observe something similar to this example (notice the android:name="com.innoquant.phonegap.MOCApp")

579

Case 1: There is no android:name tag.

Solution

  • Just add the tag as shown in the image above.

Case 2: There are two android:name tags, or the class declared is from another plugin.

Solution

  • In this case the solution is not as straightforward and will require some Java coding in the project.

If there are two plugins with this requirement within your project, you will need to merge these two classes manually. If you have experience coding Java, just go ahead, create a new class with a name of your preference, merge all functionality in a single class (or create a proxy class that instantiates both classes) and declare this new class in the application tag.

In any case, if you are in this particular case, please open a support ticket. We would like to study in detail any more conflicts that may arise with the 3rd party plugin.

Other Building errors

Symptom

You receive the following error at compile time.

.../HelloWorld/platforms/android/build/intermediates/res/debug/values-v23/values.xml:5: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse

...HelloWorld/platforms/android/build/intermediates/res/debug/values-v23/values.xml:20: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.

Solution

MOCA Plugin requires project to be compiled against Android API level 26 (Android Oreo). Please check you have included the min and target in your config.xml versions as follows:

<preference name="android-minSdkVersion" value="14" />
<preference name="android-targetSdkVersion" value="26" />

If problem persists, please check the following file:

YOUR_APP_FOLDER/platforms/android/project.properties

And change the configuration if needed:

target=android-26