Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Google Play Service dependencies #9

Open
Daz66 opened this issue Oct 18, 2018 · 20 comments
Open

Problem with Google Play Service dependencies #9

Daz66 opened this issue Oct 18, 2018 · 20 comments

Comments

@Daz66
Copy link

Daz66 commented Oct 18, 2018

HI,

I'm having a terrible problem trying to build an Android app using this plugin in conjunction with cordova-plugin-firebase-authentication. I'm hoping that someone can help!

To keep it simple I just do the following test from the CLI:

cordova create test com.test.app test
cd test
cordova platform add android
cordova plugin add cordova-plugin-firebase-authentication
cordova plugin add cordova-plugin-firestore
cordova build

And the output goes like this:

Android Studio project detected
ANDROID_HOME=S:\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8
studio
:wrapper

BUILD SUCCESSFUL

Total time: 21.782 secs
Subproject Path: CordovaLib
Subproject Path: app
publishNonDefault is deprecated and has no effect anymore. All variants are now published.
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
at build_2qji639w163yahu2psl09gsre.run(C:\DocRoot\apps\test\platforms\android\app\build.gradle:145)
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
:CordovaLib:preBuild UP-TO-DATE
:CordovaLib:preDebugBuild UP-TO-DATE
:CordovaLib:compileDebugAidl
:CordovaLib:compileDebugRenderscript
:CordovaLib:checkDebugManifest
:CordovaLib:generateDebugBuildConfig
:CordovaLib:prepareLintJar
:CordovaLib:generateDebugResValues
:CordovaLib:generateDebugResources
:CordovaLib:packageDebugResources
:CordovaLib:platformAttrExtractor
:CordovaLib:processDebugManifest
:CordovaLib:javaPreCompileDebug
:CordovaLib:processDebugJavaRes NO-SOURCE
:app:preBuild UP-TO-DATE
:app:preDebugBuild FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[15.0.1,15.0.1]], but resolves to 16.1.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
    ....

I've seen similar issues with other plugins where version dependencies clash, I just want to know has anyone got a solution that will enable these two firebase plugins to live in harmony?

My NPM version is 5.6.0, Cordova 8.1.2 ([email protected]), and I have the latest SDK Manager updates (excluding previews)

Many thanks for any advice.
Darren

Specifications

  • Plugin version:
    cordova-plugin-firebase-authentication 1.0.1 "cordova-plugin-firebase-authentication"
    cordova-plugin-firestore 1.3.0 "Cordova Firestore Plugin"
    cordova-plugin-whitelist 1.3.3 "Whitelist"
    cordova-support-android-plugin 1.0.1 "cordova-support-android-plugin"
    cordova-support-google-services 1.2.1 "cordova-support-google-services"
  • Framework:
  • Framework version:
  • Operating system: Win7
@Daz66 Daz66 changed the title Prowith Google Play Service dependencies Problem with Google Play Service dependencies Oct 18, 2018
@ReallySmallSoftware
Copy link
Owner

Looking at the default dependencies for firestore and auth I'm not sure why this isn't working. The platforms/android/project.properties file will show the versions of everything being used. Can you post that?

Could you also run the ./gradlew :app:dependencies command as suggested from within your platforms/android project and see what that gives?

I have shared this pain before which is why I try to allow you to override the default versions with my plugins - but it can still be a challenge to know what you actually need to override them with!

@Daz66
Copy link
Author

Daz66 commented Oct 18, 2018

Hi,

Thanks for your prompt attention. For the simple test project my project.properties file looks like this (comment lines removed):

target=android-27
android.library.reference.1=CordovaLib
android.library.reference.2=app
cordova.gradle.include.1=cordova-support-google-services/app-build.gradle
cordova.system.library.1=com.google.firebase:firebase-auth:16.0.+
cordova.system.library.2=com.google.firebase:firebase-core:16.0.0
cordova.system.library.3=com.google.firebase:firebase-firestore:17.0.1
cordova.system.library.4=com.google.code.gson:gson:2.8.2
cordova.system.library.5=org.json:json:20171018
cordova.gradle.include.2=cordova-plugin-firestore/app-firestore.gradle

I'm not sure how to run gradlew from a Win CLI. Any idea?!

Cheers, Darren

@ReallySmallSoftware
Copy link
Owner

Well they look OK - although I have seen problems with the plus notation before.

I think you do '.\gradlew.bat app:dependencies' to run gradle for Windows.

@Daz66
Copy link
Author

Daz66 commented Oct 18, 2018

When running gradlew app:dependencies in the test root I get:

FAILURE: Build failed with an exception.

  • What went wrong:
    Project 'app' not found in root project 'test'.

Grief! Is anything ever easy?
Cordova is great when it works but if anything fails it takes weeks to figure out what's going on.
I'm wondering whether it's just my setup that's causing this issue. It seems unlikely as I have many other app that build fine - it's just this use of Google firebase/Firestore that's causing me troubles.

I assume you're developing on a Mac?

@Daz66
Copy link
Author

Daz66 commented Oct 18, 2018

I was wondering whether this is the cause and a possible solution to the issue?
OneSignal/OneSignal-Gradle-Plugin#37 (comment)

@Daz66
Copy link
Author

Daz66 commented Oct 18, 2018

Also wondering whether I could control anything eith these variables in the project root's config.xml?

<engine name="android" spec="~7.1.1" />
<plugin name="cordova-plugin-firebase-authentication" spec="^1.0.1">
    <variable name="FIREBASE_AUTH_VERSION" value="16.0.+" />
</plugin>
<plugin name="cordova-plugin-firestore" spec="^1.3.0">
    <variable name="ANDROID_FIREBASE_CORE_VERSION" value="16.0.0" />
    <variable name="ANDROID_FIREBASE_FIRESTORE_VERSION" value="17.0.1" />
</plugin>

@ReallySmallSoftware
Copy link
Owner

I thought I'd replied to this, sorry!

You can control versions with those variables - simply specify the version you want when installing the plugin:

cordova plugin install cordova-plugin-firestore --variable ANDROID_FIREBASE_FIRESTORE_VERSION=17.0.3 --save

for example.

I'm developing on Linux btw.

Try going into platforms/android and just running:

.\gradlew.bat dependencies

That plugin you mention could be the cause of the problem - I will have to take a look as I'm not familiar with it.

@Daz66
Copy link
Author

Daz66 commented Oct 24, 2018

Hi,

Thanks for looking at this - I'm really stuck!

I tried altering the Firestore version when installing the plugin but really have no idea what I'm supposed to be doing to fix the clash. Running .\gradlew.bat dependencies in platform/android doesn't seem to tell me much else:
Starting a Gradle Daemon (subsequent builds will be faster)

Configure project :CordovaLib
publishNonDefault is deprecated and has no effect anymore. All variants are now published.

Configure project :app
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doL
ast(Action) instead.
at build_e8ob7mn9v7d8w0ormoz0wuj4r.run(C:\DocRoot\apps\XXXXXXXXXX\platforms\android\app\build.gradle:145)
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
Task :dependencies
----Root project
No configurations
BUILD SUCCESSFUL in 1m 8s
1 actionable task: 1 executed

My cordova plugins show these versions:
cordova-plugin-firebase-authentication 1.0.1 "cordova-plugin-firebase-authentication"
cordova-plugin-firestore 1.3.0 "Cordova Firestore Plugin"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-support-android-plugin 1.0.1 "cordova-support-android-plugin"
cordova-support-google-services 1.2.1 "cordova-support-google-services"

I really don't understand where the build clash is coming from:
The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[15.0.1,15.0.1]], but resolves to 16.1.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies

Any clues?

As you know I've just created a new project and tried to build a test app using the latest plugins.
Why should this cause an issue?!

Many thanks in advance.

@ReallySmallSoftware
Copy link
Owner

Is there any chance you could share a repo of your project, or a cut down version that exhibits the same problem?

@Daz66
Copy link
Author

Daz66 commented Oct 25, 2018

Hi again,

There's no complexity to the project - I just followed these commands from scratch in my apps development folder:

cordova create test com.test.app test
cd test
cordova platform add android
cordova plugin add cordova-plugin-firebase-authentication
cordova plugin add cordova-plugin-firestore
cordova build

And with that the build fails with the google services clash!
I don't actually edit any files to re-create the problem.
If you could do the same and get a successful build then I'd know it's something wrong with my environment somewhere - but no idea where!

@Daz66
Copy link
Author

Daz66 commented Nov 1, 2018

After plugging away at this for a few hours I've managed a bit of progress - slightly!
I'd realized that I wasn't adding the essential cordova-support-google-services for Android.
So my new test project is this:

cordova create test2 com.test2.app test2
cd test2
cordova platform add android
cordova-support-google-services
Then follow https://github.com/chemerisuk/cordova-support-google-services#installation to add my google-services.json to my root config.xml
cordova plugin add cordova-plugin-firebase-authentication
cordova plugin add cordova-plugin-firestore
cordova build

So now I get no errors about clashes of version, but.... I have a new error:

  • What went wrong:
    Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

So am I getting closer or just digging a deeper hole?!

Thanks for any advice.

@Daz66
Copy link
Author

Daz66 commented Nov 1, 2018

Incidentally - I get a similar dex problem if I try using cordova-plugin-firebaseui-auth instead of cordova-plugin-firebase-authentication.

I suppose my basic question is: Can you recommend any combination of versions of cordova-plugin-firestore and any auth plugin that will build?

@ReallySmallSoftware
Copy link
Owner

Recommend is a strong word :-) But I have got two projects that use cordova-plugin-firestore and cordova-plugin-firebaseui-auth that do build (and run!) on Android and iOS. I am biased as I wrote both of these!

I think that phonegap-plugin-multidex might help.

I can also say that I was battling yesterday with one of my apps with dependency hell but I did get there in the end.

Incidentally I tried your original project from a few posts back and for totally different issues!

I believe that one of my projects only builds because of a dependency that gets added by phonegap-plugin-push - I need to see if I can add that dependency to my plugins as well.

@ReallySmallSoftware
Copy link
Owner

Further to the above, this is the list of plugins I currently have in my main project:

cordova-plugin-actionsheet 2.3.3 "ActionSheet"
cordova-plugin-android-fragmentactivity 0.0.7 "Cordova Android FragmentActivity Plugin"
cordova-plugin-app-launcher 0.4.0 "Launcher"
cordova-plugin-app-preferences 0.99.4 "AppPreferences"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-console 1.1.0 "Console"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-device-motion 2.0.1 "Device Motion"
cordova-plugin-device-orientation 2.0.1 "Device Orientation"
cordova-plugin-dialogs 2.0.1 "Notification"
cordova-plugin-dns 1.0.2 "DNS"
cordova-plugin-file 6.0.1 "File"
cordova-plugin-firebase-crashlytics 0.0.7 "Cordova Firebase Crashlytics Plugin"
cordova-plugin-firebaseui-auth 0.0.10 "Firebase UI Authentication"
cordova-plugin-firestore 1.3.2 "Cordova Firestore Plugin"
cordova-plugin-geolocation 4.0.1 "Geolocation"
cordova-plugin-globalization 1.0.9 "Globalization"
cordova-plugin-googleplayservices-check 1.0.0 "GooglePlayServicesCheck"
cordova-plugin-headercolor 1.0 "HeaderColor"
cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
cordova-plugin-is-debug 1.0.0 "IsDebug"
cordova-plugin-network-information 2.0.1 "Network Information"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-support-google-services 1.1.0 "cordova-support-google-services"
phonegap-plugin-multidex 1.0.0 "Multidex"
phonegap-plugin-push 2.2.3 "PushPlugin"
uk.co.workingedge.phonegap.plugin.launchnavigator 4.2.2 "Launch Navigator"

I don't for one second believe you need or want all of these...

@Daz66
Copy link
Author

Daz66 commented Nov 1, 2018

LOL. That's a hell of a list :D
Thanks for the gentle recommendation for a multidex plugin - I learn something new every hour!
I've got some time this afternoon so I'll see if that gets me a step further.
Thanks for your help with this - I thought I was grinding to a halt but now I have a boost of confidence.

@Daz66
Copy link
Author

Daz66 commented Nov 2, 2018

Hi again,

Getting ever closer. I managed to get a build using these plugins:
cordova-plugin-enable-multidex 0.1.3 "Enable Multidex"
cordova-plugin-firebase-authentication 1.0.1 "cordova-plugin-firebase-authentication"
cordova-plugin-firestore 1.3.2 "Cordova Firestore Plugin"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-support-android-plugin 1.0.1 "cordova-support-android-plugin"
cordova-support-google-services 1.2.1 "cordova-support-google-services"

So I was hoping that now my troubles were over. However I'm getting a strange error which looks like something's not setup right. I have copied your example in initialising the DB and trying to add a new user:
....
Firestore.initialise(options).then(function(db) { db.collection("users").add({
....
The catch shows this:
Attempt to invoke virtual method 'com.google.firebase.firestore.CollectionReference com.google.firebase.firestore.FirebaseFirestore.collection(java.lang.String)' on a null object reference

Is this something familiar to you?
I do have a correct google-services.json in the root and have added resource-file statement in the config.xml so hope this part is okay.

Thanks for any advice.

@Daz66
Copy link
Author

Daz66 commented Nov 27, 2018

Hi agan,

I saw your other issues with this plugin, specifically #7

I'm wondering whether any progress was made with that, or can you recommend a course of action I can take to get the latest FireStore API working with a Cordova project?

Many thanks in advance.

@Saturnyn
Copy link

@Daz66 Hi, were you ever able to fix this problem ?
I followed the same road as you and ended up on the "Attempt to invoke virtual method 'com.google.firebase.firestore.CollectionReference com.google.firebase.firestore.FirebaseFirestore.collection(java.lang.String)' on a null object reference" error as well

@Daz66
Copy link
Author

Daz66 commented Oct 18, 2019

Hi @Saturnyn
Sorry, had no luck.
I eventually gave up with plugins and included the firebase features I needed directly in the index.htm . Took a bit to get the security policy right but it seems to work!
Saying that, recently I've only been working on the website version of my app and haven't built this for the app stores yet!
Good luck

@Saturnyn
Copy link

@Daz66 : Thanks ! Our own app was using the firebase js sdk but it's not working well on the latest iOS so we have to switch to native plugins.

@ anyone having the same problem: I managed to solve the problem by removing the "config:{}" in the init code, cf #11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants