How to solve duplicate classes issue for Flutter? - flutter

after adding
location: ^1.4.1
to my dependencies in pubspec.yaml:
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
rxdart: ^0.20.0
http: ^0.12.0
date_format: ^1.0.5
intl: ^0.15.7
fluttertoast: ^2.2.3
location: ^1.4.1
I do Packages get, and everything is fine, but when I try to build it, the app crashes with a message:
Launching lib\main.dart on Lenovo K33a48 in debug mode...
Initializing gradle...
Resolving dependencies...
Gradle task 'assembleDebug'...
D8: Program type already present: android.support.v4.app.INotificationSideChannel
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
"Here goes the list of all jar archives"
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.support.v4.app.INotificationSideChannel
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 18s
Finished with error: Gradle task assembleDebug failed with exit code 1
My targetSdk is 28. I use Android Studio 3.2.1
Help would be very much appreciated!

this happens because the library you are using uses the same dependences.
SOLUTION 1
in VSCode Search (Ctrl+Shift + P)
in your error android.support.v4.app.INotificationSideChannel. search for keywords Notification/Side/Channel. pick one.
If there are the same dependences, it means that there are duplicate libraries.
Solution: Delete one of the libraries you are using
SOLUTION 2 (Recommended)
in VSCode Search (Ctrl+Shift + P)
in your error android.support.v4.app.INotificationSideChannel. search for keywords Notification/Side/Channel. pick one.
Find a library that uses the same dependences, then update to the latest package version.
This solution will keep the library you are using without deleting it

I'm unable to replicate the behavior you've reported. The issue seems to have been resolved by a plugin update as you've mentioned in the comments. Running flutter clean should solve most conflicts caused in the dependencies cache.

Related

Flutter CachedNetworkImage Could not resolve all artifacts for configuration ':path_provider:classpath'

After adding the CachedNetworkImage dependency to my Flutter project and trying to flutter run using vscode (& Intellij..) the following exception was thrown:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':path_provider'.
> Could not resolve all artifacts for configuration ':path_provider:classpath'.
> Could not find sdklib.jar (com.android.tools:sdklib:26.3.0).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/sdklib/26.3.0/sdklib-26.3.0.jar
> Could not find apkzlib.jar (com.android.tools.build:apkzlib:3.3.0).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/apkzlib/3.3.0/apkzlib-3.3.0.jar
> Could not find apksig.jar (com.android.tools.build:apksig:3.3.0).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/apksig/3.3.0/apksig-3.3.0.jar
> Could not get unknown property 'android' for project ':path_provider' of type org.gradle.api.Project.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 17s
Exception: Gradle task assembleDebug failed with exit code 1
I got the following dependencies in the pubspec.yaml file:
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cached_network_image: ^2.5.0
cupertino_icons: ^1.0.0
curved_navigation_bar: ^0.3.7
flutter_launcher_icons: ^0.8.1
flutter_riverpod: ^0.12.4
http: ^0.12.2
material_floating_search_bar: ^0.2.6
shimmer: ^1.1.2
I'm using the latest pre-nullsafety versions, since I'm not ready for flutter 2.0 yet.
I don't think the blocked <dl.google.com> domain is the reason since I have the VPN on and can download the required jars externally..
If you got any insights on why I'm getting this error please share your ideas, I've been on it for the whole day :(
There are few possible solutions for this problem:
Do a flutter clean on the terminal then flutter pub get.
or remove the version on the package from cached_network_image: ^2.5.0 to cached_network_image:. Then do the 1st solution again (But try to avoid using this solution)
But if ever this 2 solutions would not work and you're goal is just caching images there is an alternative to this without using the CachedNetworkImage package.
NetworkImage class and Image.network() both do cached images.
Here's a link that might help you when you try Image.network()
: https://www.youtube.com/watch?v=7oIAs-0G4mw

Flutter app not starting due to dependency issue with firebase:firebase-ml-vision and Google Services

My Flutter project started giving error when I try to run the app. After getting the error, I updated my dependencies to the latest one as per the migration guide (https://firebase.flutter.dev/docs/migration/) but it is still failing. I did not make any changes to my project since yesterday but today when I tried to run it, it stated giving this error.
Following are my latest dependencies:
firebase_core: ^0.5.2
firebase_auth: ^0.18.3
firebase_crashlytics: ^0.2.3
cloud_firestore: ^0.14.3
cloud_functions: ^0.7.0+1
firebase_storage: ^5.0.1
firebase_admob: ^0.10.2
firebase_messaging: ^7.0.3
mlkit: ^0.15.1
Error on statup:
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[19.0.
2]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.
Dependency failing: com.google.android.gms:play-services-vision:20.0.0 -> com.google.android.gms:play-services-vision-co
mmon#[19.0.2], but play-services-vision-common version was 19.1.0.
The following dependencies are project dependencies that are direct or have transitive dependencies that lead to the art
ifact with the issue.
-- Project 'app' depends onto com.google.firebase:firebase-ml-vision#{strictly 24.1.0}
-- Project 'app' depends onto com.google.firebase:firebase-ml-vision-image-label-model#{strictly 20.0.2}
-- Project 'app' depends onto com.google.android.gms:play-services-vision-common#{strictly 19.1.0}
-- Project 'app' depends on project 'mlkit' which depends onto com.google.firebase:firebase-ml-vision-image-label-model#
17.+
-- Project 'app' depends onto com.google.android.gms:play-services-vision-image-label#{strictly 18.0.4}
-- Project 'app' depends onto com.google.android.gms:play-services-vision#{strictly 20.0.0}
-- Project 'app' depends onto com.google.android.gms:play-services-vision-image-labeling-internal#{strictly 16.0.0}
-- Project 'app' depends on project 'mlkit' which depends onto com.google.firebase:firebase-ml-vision#20.+
For extended debugging info execute Gradle from the command line with ./gradlew --info :app:assembleDebug to see the dep
endency paths to the artifact. This error message came from the google-services Gradle plugin, report issues at https://
github.com/google/play-services-plugins and disable by adding "googleServices { disableVersionCheck = false }" to your b
uild.gradle file.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
Exception: Gradle task assembleDebug failed with exit code 1

Flutter, Getting build error on image_picker: ^0.6.0+9

When I update my package to image_picker: ^0.6.0+9 getting build error.
I have already migrate Android X.
Error:
Launching lib/main.dart on vivo V3 in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
D8: Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 2s
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
Finished with error: Gradle task assembleDebug failed with exit code 1
Make Sure to follow the guide to support AndroidX
https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
For Solving Dex error
Try adding this line In your Project folder > android > app > build.gradle
add the following Line in multiDexEnabled true
inside defaultConfig
Use flutter clean command once it is done then try running your app.
Add following line in gradle.properties
android.useAndroidX=true
android.enableJetifier=true
Remove Simple Permission package.
it's because your app isn't compatible with AndroidX ,
There are 2 solution
1-create a flutter compatible with AndroidX app by using this command in your terminal
flutter create --androidx [project_name]
2-configure your app manually
Its not problem with the Image provider its something to do with the latest flutter package. To resolve this issue
Open the Android folder of your your flutter project in Android Studio
Wait for the gradle to build once the task is complete click on Refactor -> Refactor this -> Migrate to AndroidX or press Ctrl+T -> Migrate to AndroidX
Do flutter clean
And boom your good to go
If you want to do manually by twicking the gradle file here is link
https://flutter.dev/docs/development/androidx-migration
Happy Hacking

flutter project compilation failing with "Execution failed for task 'fluttertoast:compileDebugJavaWithJavac'" AndroidX

I am answering my own question here because I solved it after many hours of searching. This is NOT an already answered question, so please don't tag it as such. I wish it was, it would've saved me hours of frustration.
Flutter project is failing with this error. Fluttertoast error.
??: ?? ContextCompat
??: ? FluttertoastPlugin
2 ???
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':fluttertoast:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
*
Get more help at https://help.gradle.org
BUILD FAILED in 26s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility for more information on the problem and how to fix it.
*******************************************************************************************
Finished with error: Gradle task assembleDebug failed with exit code 1
The underlying issue is that the android.support.v4.Content.ContextCompat import in fluttertoastplugin.java can't resolve the symbol ContextCompat. This is a dependency issue.
The solution is to go to your flutter project's pubspec.yaml and find the fluttertoast dependency and update it to the latest version (currently ^3.1.0)
dependencies:
flutter:
sdk: flutter
dropdown_formfield: ^0.1.0
camera: ^0.5.2+1
fluttertoast: ^3.1.0 <----- THIS ONE
path_provider: ^1.1.0
video_player: ^0.10.1
latlong: ^0.6.1
google_maps_flutter: ^0.5.11+1
http: ^0.12.0
flutter_blue: ^0.5.0
flutter_bluetooth_serial: ^0.0.5
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
In my case. I updated all dependencies in pubspec.yaml and it worked.
In my case all I did was run
flutter clean
and rerun project and everything worked fine.

Flutter: build error when adding "image_cropper" and "contacts_service" packages

I can successfully build and run a fresh new flutter project. But when I add both image_cropper: ^1.0.0 and contacts_service: ^0.2.4 packages to pubspec.yaml and run flutter packages get, I cannot build the project anymore, and get this build error:
D8: Program type already present: android.support.v4.app.INotificationSideChannel
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\2.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\3.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\4.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\5.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\6.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\7.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\8.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\9.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\10.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\11.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\12.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\13.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\14.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\15.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\16.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\17.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\18.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\19.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\20.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\21.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\22.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\23.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\24.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\25.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\26.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\27.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\28.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\29.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\30.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\31.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\32.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\33.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\34.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\35.jar, E:\Projects\flutter\hello\build\app\intermediates\transforms\dexBuilder\debug\36.jar
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.support.v4.app.INotificationSideChannel
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 19s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See https:///CP92wY for more information on the problem and how to fix it.
*******************************************************************************************
Finished with error: Gradle task assembleDebug failed with exit code 1
I do not understand this error very well, but it seems that there is a naming conflict between these two packages (because of duplicate_classes in the error text). Is there any workaround for this?
Note that this error does not happen with any other pair of packages for me.
In build.gradle defaultConfig add multiDexEnabled true
This was an Android X compatibility issue. I could get it fixed by following the steps mentioned here, but in summary:
First make sure that compileSdkVersion is at least 28 in app/build.gradle. This property controls the version of the Android SDK that Gradle uses to build your APK. It doesn’t affect the minimum SDK version that your app can run on.
Right click on android directory of flutter project and open it using this menu: Flutter > Open android module in android studio
In the newly opened project, from menus select Refactor > Migrate to AdnroidX
Close the project and open your flutter project again.