Flutter project won't compile after android dependencies change - flutter

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. :-)

Related

I am trying to run my flutter app and I get this error every time , just upgraded flutter to 2.10.0 version [duplicate]

In Stripe, my client wants email and cardholder name, but the Stripe payment UI doesn't provide that option in com.stripe.android.view.CardMultilineWidget. I wanted to give it a try with the latest stripe version,
I was using Stripe version (14.1.1). So I updated it to the latest one (16.8.0)
The build showed me the error that it doesn't take minSdkVersion 19. It requires 21 in manifest merger. So I updated minSdkVersion to 21.
I got
caches/transforms-2/files-2.1/4541b0189187e0017d23bbb0afebd16a/jetified-kotlin-stdlib-common-1.5.0.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
I tried changing the Gradle version, but I am still getting the same error. How can I solve the incompatible error and add the email and cardholder name in Stripe?
Changing this in file build.gradle solved my problem.
From
ext.kotlin_version = '1.3.50'
to
ext.kotlin_version = '1.6.0'
Or whatever the latest version of Kotlin available and make sure to update Kotlin version on Android Studio as well.
I had this problem in a Flutter project.
In my case, a line for kotlin-gradle-plugin was missing in the Android build.gradle file, so adding ext.kotlin_version = '1.6.10' didn’t fix it.
After adding
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
the error was gone.
Full code section:
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Although this question has been answered, I think it's worth explaining what is happening
For the example:
The binary version of its metadata is 1.7.1, expected version is 1.5.1.
The expected version is the Kotlin for kotlin-gradle-plugin
The binary version is the what is downloaded (or previously compiled)
for com.android.tools.build:gradle
<project_dir>/android/build.gradle
buildscript {
ext.kotlin_version = '1.5.20' // <= expected version is 1.5.1
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1' // downloads 1.7.1 Metadata
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // <= 1.5.20 used here
Why is this Happening So Much?
The user updates the Kotlin version of the plugin to match the IDE version per the warning.
The user updates the android build tools gradle plugin per the warning
This is the WRONG version!
Now you don't have any warnings, but the version suggested is 7.1.3 which is not the latest. (I don't know why it suggests this older version) 7.3.1 is currently the latest and is meta data 1.7.1, so it will match the Kotlin version of 1.7.20 (which is also metadata 1.7.1)
What else could be wrong?
Due to caching, gradle may be using an older dependency before you updated. To start clean:
delete the ~/.gradle/cache directory
delete the android/.gradle directory
delete the project_dir/build dir
ensure the android/gradle/gradle-wrapper.properies has the correct distributionUrl (currently distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip)
from project_dir do flutter build apk
NOTE: your dependencies may need to be updated if their com.android.tools.build:gradle version is too old. Alternatively, both the kotlin and tools:gradle versions can be downgraded to compatible version that match metadata (although Android Studio will warn for that not matching the IDE Kotlin version)
How to Prevent this from happening Again?
Use the same Kotlin version as the IDE normally for ext.kotlin_version. see https://kotlinlang.org/docs/releases.html#release-details
Double check the com.android.tools.build:gradle version. See https://developer.android.com/studio/releases/gradle-plugin#updating-gradle and https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google
If you are facing this error in Flutter build for Android then try to change the Kotlin version to
ext.kotlin_version = '1.4.32'
Firstly, go to settings, and then navigate to plugins. Find the Kotlin plugin and update it.
Next, in gradle files, go to build.gradle (Project: YourApp). Then, change the following code (in buildscript) from:
ext.kotlin_version = '1.3.50'
to the latest version, such as:
ext.kotlin_version = '1.4.32'
To know the latest version, go to settings and the plugins, find the Kotlin plugin, and make sure it is updated. The latest version is under JetBrains.
After following the instructions, your error will be resolved.
Make sure that the Kotlin version of your IDE is the same as the version declared in your gradle.build file.
It was fixed by updating the Kotlin Gradle plugin version.
In the project level build.gradle file, update the following line.
ext.kotlin_version = '1.6.10'
You can find the latest Kotlin Gradle plugin version at
Tools / Build tools / Gradle.
Changed the Project build gradle to
buildscript {
ext.kotlin_version = '1.7.20'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
What do you need to to solve this?
I was facing this issue since last night. Just navigate through some webpages couldn't get to the exact solution. I finally solved it by these steps:
Replace ext.kotlin_version = '1.3.50' with ext.kotlin_version = '1.4.32' in the build.gradle file.
Clean project → Build the project with Gradle files → Run
in my case for
The binary version of its metadata is 1.7.1, expected version is 1.5.1
got to (dependencies) inside build.gradle(project) convert from 1.5.x (x) in my case is (20)
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"
to 1.7.10
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
Another solution is to downgrade androidx.core:core-ktx library to any compatible version. This one worked for kotlin_version = '1.3.31':
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.3.1' // The only working for this version (sdk/gradle)
implementation 'androidx.core:core-ktx:1.0.2' // The only working for this version (sdk/gradle)
implementation 'androidx.constraintlayout:constraintlayout:1.1.2' // higher versions require min-sdk >= 26
...
}
Android SDK: compileSdkVersion 30 and minSdkVersion 19.
Gradle build Tool: com.android.tools.build:gradle:3.3.1.
Just go to file build.gradle (Project: yourProjectName).
Change
plugins {
...
id 'org.jetbrains.kotlin.android' version '1.5.x' apply false
...
}
(1.5.x means x version number at your case, such as 1.5.1.)
To
plugins {
...
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
...
}
It works in my case...
Most of the answers here seem to revolve around projects that use Gradle.
I randomly encountered this problem in IntelliJ IDEA that that was compiling and running a Maven project just fine 5 minutes before - no configuration changes. I introduced a new exception class and this problem popped up.
I tried invalidating caches and restarting, which didn't resolve the issue - however, disabling and re-enabling the Kotlin plugin resolved the issue.
Using Flutter, it was fixed by:
Updating Android Studio packages, specially the Kotlin plugin.
Get the last Kotlin plugin version Nbr from Gradle - Plugin and versions. For now it's 1.6.10.
Update <Your_project_name_folder>\android\build.gradle file by replacing the old Kotlin version by the new one you got from the web site above.
ext.kotlin_version = '<The_new_version_Nbr>' in my case ext.kotlin_version = '1.6.10'
Restart Visual Studio Code.
You're done.
Go to the file build.gradle, change the version of kotlin.
In case in my flutter project I opened build.gradle and changed
`ext.kotlin_version = '1.5.30'`
to
ext.kotlin_version = '1.6.0'
Here
buildscript {
ext.kotlin_version = '1.6.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Then save and do
flutter clean and flutter run.
Works fine for me.
I faced the same problem in Flutter and I fixed it by going to:
File > Settings > Plugins as #Muzzamil said and I checked for the version of Kotlin in my IDE and simply replaced the value in ext.kotlin_version (that is 1.6.10) by that value
ext.kotlin_version = '1.6.10'
project build.gradle:
ext.kotlin_version = '1.6.10'
app/build.gradle:
dependencies {
// classpath 'com.android.tools.build:gradle:7.1.2'
// classpath "org.jetbrains.kotlin:kotlin-gradle- plugin:$kotlin_version"
}
But after changes ext.kotlin_version to lower this warning stay but the red warning is gone
For macOS you can
rm -r $HOME/.gradle/caches/
or you can invalidate caches
File >> Invalidate caches
I have the set minsdk 24 and restart the Android Studio, its working fine.
This works for me
buildscript {
ext.kotlin_version = '1.7.20'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
solution
A failure occurred while executing com.android.build.gradle.internal.tasks
Please check if you Kotlin version is compatible with compose version.
if not, then please make the changes and it should work fine.
Compose Compiler Version Compatible Kotlin Compiler Version
1.3.0 --> 1.7.10
1.3.0-rc01 --> 1.7.10
1.3.0-beta01 --> 1.7.10
1.2.0 --> 1.7.0
1.2.0-rc01 --> 1.6.21
1.2.0-beta03 --> 1.6.21
1.2.0-alpha08 --> 1.6.20
1.1.0 --> 1.6.10
1.1.1 --> 1.6.10
1.1.0-rc031.6.10
I upgraded the android studio version to the latest and that resolved the issue
I have faced this error in IntelliJ IDEA with a Maven project.
The solution is about to turn off Kotlin plugin in IntelliJ IDEA if you are not using Kotlin in your project.
Go to:
Menu File → Settings → Plugins
And turn off the Kotlin plugin by click on the checkbox. See here:

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 Firebase plugins correct versioning

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.

Android Studio Emulator: App won't run unless you update google play services

I am building an application that uses the google maps api.The first activity of the application is a maps activity, which refuses to run based on the error I stated in the title.
I have heavily modified my build.gradle trying to fix the problem; based on other solutions I found on this website.
But I think I may have made it worse: This is what my build.gradle looks like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.navigation.dixongardens.ben.bensgardens"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:28.0.0-alpha1'
compile 'com.google.android.gms:play-services-maps:11.6.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
// androidTestImplementation 'com.android.support.test:runner:1.0.1'
// androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.google.maps.android:android-maps-utils:+'
compile 'com.google.android.gms:play-services:11.8.+'
compile 'com.android.support:design:26.0.0-alpha1'
}
Can someone help guide me as to what is wrong with my build.gradle? I am confused as to which dependencies are required for google services to work properly.
It's not an issue with your app, but an issue with your emulator. You need to update the emulator you are running / download a new system image and create an emulator from that.
The exception is telling you that Google Maps expects a newer version of Google Play Services than what is currently running on your device. Sometimes it will have a link to update google play services under the notification. (in the app on the google map view)
You don't need to do anything, only you need to click notification showing above message. Then google play service will be updated automatically. Easy

Android Studio Gradle javax.mail activation.jar dependency issue

I am porting my Swing app to Android. I use mail.jar and jscape's secure iNet factory (sinetfactory.jar) for FTP/SFTP/SSH support in my swing app.
Both mail.jar and sinetfactory.jar use the java activation framework (activation.jar) which has java.awt dependencies. The android version of mail.jar and activation.jar are modified to remove this dependency on java.awt.
When I add android mail.jar, activation.jar and sinetfactory.jar to my Android Studio project, I get the following error:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/sun/activation/registries/LineTokenizer;
This exact same error has a topic on StackOverflow, but does not apply to my situation. That topic seemed to be a Gradle issue. My issues is that I have 2 libraries with the same dependency (activation framework). I need to use both versions of activation.jar. i.e. mail.jar needs the android modified version of activation.jar, whereas sinetfactory.jar needs the original java version of activation.jar.
What are my options to resolve this issue? Can this be done via some gradle setting?
Try to use it
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
}
compile 'javax.mail:javax.mail-api:1.5.3'