2

In attempting to compile a previously working Android app with Android Studio 3.5.2, Android SDK 28 and the cordova-plugin-firebase I read here that I should install cordova-plugin-firebasex as a working and currently maintained fork that works on Androidx.

First issue, removing the cordova-plugin-firebase, I resolved as follows:

You cannot remove this plugin with the conventional method

cordova plugin remove cordova.plugin.firebase --save

This removes the entire /main directory due to a bug in the plugin.xml file:

 <resource-file src="src/android/google-services.json" target="."/> 

and the uninstall fails.

I removed that line from the XML file and again attempted to remove the plugin via the cli.

That results in this message:

Using "requireCordovaModule" to load non-cordova module "xcode" is not supported. Instead, add this module to your dependencies and use regular "require" to load it.

Following instructions here I edited plugins/cordova-plugin-firebase/scripts/ios/helper.js

I added

var xcode = require("xcode"); 

at the top of the file and remove two instances of

var xcode = context.requireCordovaModule("xcode");

Again attempt removal of plugin and got

Uninstalling cordova-plugin-firebase from ios Uninstalling cordova-plugin-firebase from osx Removing "cordova-plugin-firebase" Cannot find plugin.xml for plugin "cordova-plugin-google-analytics".

I removed and reinstalled the google analytics plugin, and the firebase plugin successfully uninstalled.

I've then added Firebasex and the recommended version wranglers for play services and firebase:

cordova plugin add cordova-plugin-firebasex
cordova plugin add cordova-android-play-services-gradle-release 
cordova-android-firebase-gradle-release

I get the following compile errors:

Could not determine the dependencies of task ':app:compileReleaseJavaWithJavac'. In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[15.0. 1]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown. Dependency failing: com.google.android.gms:play-services-flags:15.0.1 -> com.google.android.gms:play-services-basement@[ 15.0.1], but play-services-basement version was 17.0.0.

I've tried grepping my entire directory for ':15.0.1' and '@15.0.1' but I cannot find the culprit. I tried uninstalling a reinstalling the plugin with the following version specifiers:

 cordova plugin add cordova-plugin-firebasex \
     --variable ANDROID_PLAY_SERVICES_TAGMANAGER_VERSION=17.0.0 \
     --variable ANDROID_FIREBASE_CORE_VERSION=17.0.0 \
     --variable ANDROID_FIREBASE_MESSAGING_VERSION=19.0.0 \
     --variable ANDROID_FIREBASE_CONFIG_VERSION=18.0.0 \
     --variable ANDROID_FIREBASE_PERF_VERSION=18.0.0 \
     --variable ANDROID_FIREBASE_AUTH_VERSION=18.0.0 \
     --variable ANDROID_CRASHLYTICS_VERSION=2.10.1 \
     --variable ANDROID_CRASHLYTICS_NDK_VERSION=2.1.0 \

and that spits up a new dependency mismatch:

Could not determine the dependencies of task ':app:preReleaseBuild'.

In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[11.0. 1]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown. Dependency failing: com.google.android.gms:play-services-tagmanager-v4-impl:11.0.1 -> com.google.android.gms:play-servic es-basement@[11.0.1], but play-services-basement version was 17.0.0.

So I've also tried pushing all libraries to their most recent versions, resulting in the following build.gradle for the app:

dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    implementation(project(path: ":CordovaLib"))
    implementation 'com.google.android.gms:play-services-auth:17.0.0'
    implementation 'com.google.android.gms:play-services-identity:17.0.0'
    implementation "androidx.legacy:legacy-support-v4:1.0.0"
    implementation 'com.google.firebase:firebase-core:17.2.1'
    implementation 'com.google.firebase:firebase-messaging:20.0.0'
    implementation 'com.google.firebase:firebase-config:19.0.3'
    implementation 'com.google.firebase:firebase-perf:19.0.1'
    implementation 'com.google.android.gms:play-services-analytics:17.0.0'
    implementation "com.google.android.gms:play-services-tagmanager:17.0.0"
    implementation "com.google.firebase:firebase-core:17.2.1"
    implementation 'com.google.firebase:firebase-messaging:20.0.0'
    implementation 'com.google.firebase:firebase-config:19.0.3'
    implementation 'com.google.firebase:firebase-perf:19.0.1'
    implementation 'com.google.firebase:firebase-auth:19.1.0'
    implementation "com.crashlytics.sdk.android:crashlytics:2.10.1"
    implementation 'com.crashlytics.sdk.android:crashlytics-ndk:2.1.1'
    implementation "me.leolin:ShortcutBadger:1.1.22"
    // SUB-PROJECT DEPENDENCIES END }

Which spits me back to

Dependency failing: com.google.android.gms:play-services-flags:15.0.1 -> com.google.android.gms:play-services-basement@[ 15.0.1], but play-services-basement version was 17.0.0.

I'm still a noob at Library dependencies (though I've been hiking up the learning curve for the last three days to the point I need oxygen) -- how can I find the culprit here, and why are the plugins that are supposed to do that for me failing?

brianfit
  • 1,829
  • 1
  • 19
  • 34

1 Answers1

3

I've managed to arrive at a solution which builds a working APK. HOWEVER,

  • I can no longer simply rebuild the app after code changes, but have to remove the platform add it again and follow the following steps.

  • I have had to remove the Firebase messaging functionality (I don't
    use it anyway)

But in case this may be of service to someone else who has spent far too many hours trying to get Firebase functional, here's my process:

Remove the Firebasex plugin and the cordova-android-play-services-gradle-release plugin and the cordova-android-firebase-gradle-release if they are installed. (If you have FIREBASE and not FIREBASEX installed, see my question above for removal method.) Then:

cordova plugin add cordova-plugin-firebasex 
cordova plugin add cordova-android-play-services-gradle-release  --variable  PLAY_SERVICES_VERSION=17.0.0
cordova plugin add cordova-android-firebase-gradle-release  --variable FIREBASE_VERSION=17.0.0


cordova platform rm android

cordova platform add android

cordova build android

rm platforms/android/app/libs/google-play-services.jar 

Import into Android Studio.

It will warn you upgrade your gradle release. Don’t do it.

The Sync will now succeed, but the run will fail with error message:

Installation did not succeed. The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED Installation failed due to: 'null' Retry

In your AndroidManfiest.xml, add: ignore GoogleAppIndexingWarning to the application tag:

<application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true"
    tools:ignore="GoogleAppIndexingWarning">

Remove:

<service android:name="org.apache.cordova.firebase.FirebasePluginMessagingService"
    android:permission="TODO">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

Remove:

<meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/accent" />
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id" />

If you run the app at this point, you'll get a message like:

java.lang.RuntimeException: Manifest merger failed : Attribute meta-data#com.google.android.gms.version@value value=(59056789) from AndroidManifest.xml:31:66-90 is also present at [com.google.android.gms:play-services-basement:17.0.0] AndroidManifest.xml:25:13-66 value=(@integer/google_play_services_version). Suggestion: add 'tools:replace="android:value"' to element at AndroidManifest.xml:31:9-94 to override.

Add to Manifest.xml:

<meta-data android:name="com.google.android.gms.version" android:value="12451000" tools:replace="android:value" />

The app now compiles, runs, and reports Firebase events properly.

brianfit
  • 1,829
  • 1
  • 19
  • 34