evollu / react-native-firebase-analytics

React native bridge for firebase analytics
MIT License
206 stars 54 forks source link

Dependency issues on Android #40

Open javieramp opened 7 years ago

javieramp commented 7 years ago

Hi.

I have found some trouble when import the library in my current workspace. You are linking to the latest firebase-core/firebase-analytics version using the "+" operator in the Gradle file (compile 'com.google.firebase:firebase-core:+', compile 'com.google.firebase:firebase-analytics:+'). Two things about this: firebase-analytics is inside the core package(see documentation: https://firebase.google.com/docs/android/setup), the other is that the "+" operator is discouraged (android studio warns about it), instead you must use a concrete versión of the library. I think that you must change this operator and provide different versions for every new release of firebase library, thus the project will have dependencies over a concrete version, not the latest, who can break the workspace code. If you cannot made it, i can help you with some pull requests.

Best regards.

albertopenas commented 7 years ago

I aggre, i am having trouble with firebase-core library in android env.

IvanLopezCarreira commented 7 years ago

im having trouble too with this issue

evollu commented 7 years ago

everyone has different version of google play service and but this repo has to support all of them. By setting concrete version locks developer to the version of play service for the whole application. Concrete version is good if you declare in your main project. But in a bridge repo, this might be a better trade off. + doesn't mean latest, it means it can works with any version

You can lock your play service version by adding compile 'com.google.firebase:firebase-core:10.0.1' in your main project's gradle

javieramp commented 7 years ago

Hi again,

I think that you you said isn't correct. In this documentation at point 24.2.4. Use Dynamic Versions and Changing Modules comment that + operator set the last version available.

https://docs.gradle.org/current/userguide/dependency_management.html

albertopenas commented 7 years ago

You can read this blog post: https://brock.io/post/repeatable_android_builds/ to understand how dependencies work in android. When you put a 'compile dependency.+' with plus operator you can break developers builds, because it will use the latest version available, not all of us can upgrade to the last version every time that google launches a new release. In fact we are using firebase 9.4, and we are forced to locally change your project dependency to compile with 'com.google.firebase:firebase-core:9.4.0' and to change a bridge method called setScreenName because it doesnt exists in firebase-core:9.4.0(added in 9.8). Thanks for your time.

evollu commented 7 years ago

@albertopenas what is your solution for supporting both 9.4 and 10.1?

albertopenas commented 7 years ago

Thanks for your answer.

A solution is to have different versions of the library with fixed mappings to firebase-core libraries. Google has a similar solution in his firebase-UI repo for Android. You can see it in the
repo. In the googles repo you can see a table with some mappings like that: FirebaseUI Version -> Firebase/Play Services Version ... 0.6.2 -> 9.8.0 ... 0.5.3 -> 9.4.0 ...

What I do not know is how to version the npm package. I know that is extra work, if you plan to make the pointed solution and you dont have time, send me a private message.

Thanks again for your time. Best regards @evollu

evollu commented 7 years ago

It make sense. The breaking change of adding new functionality is a problem. I will create version table, 1.0.5 -> 9.4, 1.0.6->9.6, next time with breaking changes I will update minor version to 1.1.0 to avoid surprise. If you use "1.0.5" rather than "^1.0.5", you should get old code back.

Regarding + issue, have you tried forcing resolutions strategy on your own build.gradle? + is easier for me to maintain because I don't have to publish this repo every time Firebase SDK releases.

try using resolutionStrategy? this should help you lock the version for your project

resolutionStrategy { 
        force 'com.google.firebase:firebase-core:9.4.0'
        force 'com.google.firebase:firebase-messaging:9.4.0'
    }
javieramp commented 7 years ago

Hi @evollu i did next steps:

Then i check packages.json and dependences was:

dependencies { ... "react-native-firebase-analytics": "1.0.5", ... }

Then i check at Android Studio module of react-native-firebase-analytics --> build.gradle:

dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.facebook.react:react-native:+' compile 'com.google.firebase:firebase-core:9.+' compile 'com.google.firebase:firebase-analytics:9.+' }

Installing version 1.0.5 does not create dependencies in gradle with 9.4 but creates them with 9. +

Did I do something wrong so that version 9.4 does not appear in gradle?

evollu commented 7 years ago

@javieramp you can use resolutionStrategy to lock version to 9.4