Flutter Firebase plugins correct versioning - plugins

For an app I'm developing I'm getting some crashes on some of my clients devices.
I suspect it has to do with me miss-understanding the proper way to configure all the different plugins to work together.
For instance, in this official guide https://firebase.google.com/docs/flutter/setup it says to use:
firebase_core: ^0.2.5
But the current plugin version (https://github.com/flutter/plugins) is:
firebase_core: ^0.4.0+6
And that's only one example. There are lots of other Firebase / Firestore plugins I use, and it's really unclear on how to properly configure them.
Add to this dependencies and more configuration in the Gralde files, for example:
implementation 'com.google.firebase:firebase-core:16.0.9'
Add to this the AndroidX configuration:
build.gradle:
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
gradle.properties:
android.enableJetifier=true
android.useAndroidX=true
So my question is:
How do I properly configure my app with all the config files (pubspec.yaml, build.gradle etc.)?

Avoid adding libraries over build.gradle. You'll also need to following this steps to make sure it works with AndroidX:
https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
Over the website you also have an specific section for non AndroidX libraries:
https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility#avoiding-androidx
Any version above those should be safe.

Related

Getting compile time error in audioplayers dart package

I am new in flutter and I followed londonappbrewery course, in that course she teach us to use audioplayers packages so I follow her and import it on pubspec.yaml but when I want to run my flutter app it give this error. Please give solutions I am running it on physical device with Android 10. This is the error.
Can you try the following and please make sure that you have an Android project setup with Kotlin,
This file ensures that the Android project is using Kotlin android/app/src/main/kotlin/com/example/your_app/MainActivity.kt
In android/build.gradle
buildscript {
ext.kotlin_version = '1.5.10' // Update this version or add this line
...
dependencies {
...
// Make sure this line is here
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
In android/app/build.gradle make sure this line is there too at the bottom,
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
In android/gradle/wrapper/gradle-wrapper.properties use updated gradle version gradle-6.5-bin.zip for distributionUrl
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
If any confusion or question please leave a comment.
I think it might solved by changing the following line in the build.gradle from:
ext.kotlin_version = '1.3.50'
To
ext.kotlin_version = '1.4.32'
…or whatever the latest version of Kotlin available is. Make sure to update your Kotlin version on Android Studio as well.

Flutter plugin that uses .aar modules builds and runs fine in the example app but fails to build in a different app

I've written a Flutter plugin to use an SDK that requires the inclusion of some .aar modules. It builds and runs perfectly in the example app for the plugin, but when I import the plugin in a different app and try to build it, the build immediately fails with a message saying that one of the .aar modules could not be found in the plugin. This makes no sense because the module is definitely there - the platform channels to use the SDK would fail in the example app if the module wasn't there.
Why would the example app build and run without any problems but a different app won't? The only thing I can think of is that I import the plugin from path in my pubspec but it seems unlikely to me that this is the culprit.
Any advice or assistance here would be appreciated. TIA!
I got it!!!!
The answer is as found here: How to add .aar dependency in library module?
The way this adapts to a Flutter plugin is as follows:
Add a libs folder at the root of the android project in the plugin. Add the .aar files there.
In the plugin's build.gradle file, update rootProject.allProjects to look as follows:
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
dirs project(':your_plugin_name_here').file('libs')
}
}
}
Still in the same build.gradle, add your .aar file(s) as dependencies as follows:
implementation(name:'aar_name_here', ext:'aar')
In the Flutter app that you want to use the plugin for, open the app-level build.gradle file and add the plugin itself as a dependency, like so:
android {
...
dependencies {
implementation project(':your_flutter_plugin');
}
}
In the settings.gradle file for the app that us using the plugin, change
include ':app'
to
include ':app', ':your_flutter_plugin'
And this should do it!!

Flutter Conflict: geolocator: ^5.1.4+1 and google_maps_flutter: ^0.5.21+7 generate dependency conflict

Currently I'm doing a Flutter application witch uses:
geolocator: ^5.1.4+1
google_maps_flutter: ^0.5.21+7
When I declare both dependencies in "pubspec.yaml" it get a conflict
"FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:preDebugBuild'.
Android dependency 'com.google.android.gms:play-services-tasks' has different version for the compile (16.0.1) and runtime (17.0.0) classpath. You should manually set the same version via DependencyResolution"
I've tryied also by editing gradle.properties with:
android.useAndroidX=true
android.enableJetifier=true
And in "app/build.gradle" added the dependencies as classpath and/or api as needed:
com.google.android.gms:play-services-tasks
Is anyone facing same issue? In case you solved it, what have you done to solve it?
I had exactly the same problem, though using google_maps_flutter0.5.21+8.
I added for every error message the following line to android/app/build.gradle under dependencies. Look then like the following:
dependencies {
...
implementation 'androidx.cursoradapter:cursoradapter:1.0.0'
implementation 'androidx.drawerlayout:drawerlayout:1.0.0'
implementation 'androidx.documentfile:documentfile:1.0.0'
implementation 'androidx.viewpager:viewpager:1.0.0'
implementation 'androidx.arch.core:core-runtime:2.0.0'
implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
implementation 'androidx.fragment:fragment:1.0.0'
implementation 'androidx.core:core:1.1.0'
implementation 'com.google.android.gms:play-services-basement:17.0.0'
implementation 'com.google.android.gms:play-services-base:17.0.0'
}
Hope that helps. If there's a better way please tell. No flutter expert so far.

Flutter project won't compile after android dependencies change

The issue started when I updated to the latest API 28. I read that the dependencies from com.* moved to androidx. I tried different approaches to resolve the issue, but still I have not managed to make it compile.
My dependency structure
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.google.firebase:firebase-core:16.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
The thing is that every time when I try to build it the error changes. Sometimes is
Android dependency 'androidx.slidingpanelayout:slidingpanelayout' has
different version for the compile (1.0.0-rc01) and runtime (1.0.0)
classpath. -- I do not have such lib in my dependency structure.
others.. something with Dex conflicts so I tried setting multiDexEnabled true at build.grandle and
android.useAndroidX=true
android.enableJetifier=true at grandle.properties
I tried also the to upgrade and downgrade the compileSdkVersion...
previous
compileSdkVersion 27
minSdkVersion 16
targetSdkVersion 27
current
compileSdkVersion 28
minSdkVersion 21
targetSdkVersion 28
Moreover, I saw the migrate tutorial from google. Still, by using Flutter I do not have any of these libs in my structure (at least I did not put any of these at the dependencies-- maybe they fetched under the hound at compile time).
This thing drives me crazy for past few days.
Any insights would be really helpful. Thanks in advances.
Coming back to my own post. The issue was one of the dependencies,especially, the fluttertoast. There was some conflict with the new android repository. So, for now, I downgrade to 2.2.3 and it is working. :-)

Where can I find gradle dependencies?

I'm trying to learn Gradle in Eclipse.
Is there any good integration where you can search for a Jar to include in the project?
Right now it's a hit-and-miss operation from my side.
Example:
I want to add the CLI library from Apache Commons. Also the Codec library.
I have added both jcenter() and mavenCentral like this:
repositories {
jcenter()
mavenCentral()
}
and I have tried this (and variations) in the dependencies section:
compile 'org.apache.commons:cli:1.2'
compile 'org.apache.commons:codec:1.10'
but all I get is
Could not resolve: org.apache.commons:cli:1.2
Could not resolve: org.apache.commons:codec:1.10
When searching in search.maven.org, if I search on org.apache.commons I get 111 pages of hits... I haven't found the time to step thru them all.
When searching for commons-cli, it finds a version from 2005... plus a library called
org.mod4j.org.apache.commons cli
No idea what the "mod4" means.
Is the conclusion that Apache commons doesnt exist in these repositories?
How do you do in these cases? How do you come up with the correct "compile"-specification?
Can I for example say "get latest version of this jar" ?
Would love to have a way to do:
gradle search apache-commons --only-latest-version
or something similar. Something like the wonderful GEM/BUNDLE commands in Ruby.
Thanks for all help
You can search the Maven Central repository to find specific versions of artifacts, but in some cases you have to know the exact name (artifactId) of the artifact. Unfortunately the apache artifacts are not consistent in their groupId or artifactId naming schemes. For example, Apache Commons CLI is commons-cli:commons-cli.
Here is the latest version of that artifact. There is even a convenient panel that shows the exact line to use based on your dependency tool (maven, Gradle, Ivy, etc.)
The below build.gradle works. Have a look at the syntax for dependency declaration. Please read this documentation for syntax.
apply plugin: 'java'
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile group: 'commons-cli', name: 'commons-cli', version: '1.2'
compile group: 'commons-codec', name: 'commons-codec', version: '1.10'
testCompile 'junit:junit:4.12'
}
And as for getting the 'latest' version of a library in gradle, I am afraid thats not possible currently like in maven.
Is there any good integration where you can search for a Jar to include in the project?
As far as I know Gradle itself has no specific support for this.
How do you do in these cases? How do you come up with the correct "compile"-specification?
Before searching in Maven repositories for the desired dependency, best is to consult the project's homepage first. commons-cli for example has a separate Dependency Information section and lists the required information for all kinds of build tools. For Gradle/Grails and the latest SNAPSHOT version this is
compile 'commons-cli:commons-cli:1.4-SNAPSHOT'
The list of valid versions is compiled in the Changes Reports section.
Can I for example say "get latest version of this jar"?
There is a plugin called gradle-versions-plugin that can list updates of defined dependencies. Of course, this requires that you have already defined your dependencies correctly.