image_picker plugin causes build error for Android - flutter

I installed the image_picker plugin into my project, and it works with iOS, But now the Android build crashes with the error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: Error while generating the main dex list.
Any idea why the Android build crashes when using this plugin?

You have to enable multidex in your build.gradle file :
android {
.
.
.
defaultConfig {
minSdkVersion //your minimum SDK version
targetSdkVersion //your target SDK version
multiDexEnabled true // this is what you should add
}
}
dependencies {
compile 'com.android.support:multidex:1.0.3'
}

I had to roll back my Firestore plugin to 0.7.4 to fix this: answer found here.
I do also have multidex enabled as other answers suggested - this fixed an earlier crash I encountered with Firebase plugins.

Related

How to find what Flutter packages requre SDK version #33?

When trying to deploy my Flutter app, I'm getting an error that says that the deployment requires SDK version #33.
How can I find what packages in the app require SDK #33?
R
unning Gradle task 'assembleDebug'...
Warning: The plugin url_launcher_android requires Android SDK version 33.
For more information about build configuration, see https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
One or more plugins require a higher Android SDK version.
Fix this issue by adding the following to D:\Ian\Documents\github\good_day\android\app\build.gradle:
android {
compileSdkVersion 33
...
}
android>app>build.gradle
compileSdkVersion 33
targetSdkVersion 33

Build APK stuck at Task :app:checkReleaseAarMetadata

i am new in flutter.
When i run:
flutter apk build -v
it always stuck at
[+29946 ms] > Task :app:checkReleaseAarMetadata
I left it for almost an hour and nothing,
same happen when i run it on release or debug on my own device via usb debugging, but run perfectly on emulator on debug mode
any help would be appreciated, thanks
add the following line to android/build.gradle.try it and update is it fixed!
buildscript {
ext {
androidXCore = "1.7.0" // <-- Add this line
buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 29
ndkVersion = "20.1.5948944"
}
Thanks, I found the solution.
In the end tried to clean install Android Studio including sdk, gradle, etc by deleting android studio related stuff on %APPDATA%, %USERPROFILE%, %LOCALAPPDATA%.
After that i build the apk again from vscode console and it work.
I think the error occurred because of missing stuff in gradle or error during sdk installation.

App requires Multidex support in flutter?

I'm getting this error while building my app in Flutter. it seems the problem that the multidex is not enabled even though I did everything needed to enable it. this the error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeProjectDexDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> 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.
Type androidx.activity.R$attr is defined multiple times: C:\Users\Abdul rehman\OneDrive\Desktop\CSC451\Capstone Project\harfanah\build\app\intermediates\project_dex_archive\debug\out\4b5c628c7fbb96e2839e63f71f8803802c039de25c33dd9c9475187dc45e6e1a_1.jar:classes.dex, C:\Users\Abdul rehman\OneDrive\Desktop\CSC451\Capstone Project\harfanah\build\app\intermediates\project_dex_archive\debug\out\9bd7ed05083b8d3edbf142363966d832d9f0694faefda4d175e3ad8ad18fc06d_1.jar:classes.dex
* 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 30s
[!] App requires Multidex support
Flutter multidex handling is disabled. If you wish to let the tool configure multidex, use the --mutidex flag.
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
I have already checked all of the solutions.
enabled Multidex support and used the latest version:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.harfanahApplication.harfanah"
minSdkVersion 21
targetSdkVersion 32
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
.
.
.
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation("androidx.multidex:multidex:2.0.1")
}
I also added these to gradle.properies
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
Still it is not working. any suggestions?
Have you tried "flutter clean" and then rebuild? You can let the Flutter CLI tool do it for you with "flutter build --multidex".
use flutter clean and
flutter pub get
then you will get a notification on whether you need to install it or not.
type y (yes) to it .then use flutter run
I had the same issue on a Mac M1(2021). To debug on an android device, I extended #AntEdode's solution a bit:
flutter build apk --multidex --debug
During build, the same error will pop up, however the SDK will now ask whether or not you want to install multidex:
[!] App requires Multidex support
Multidex support is required for your android app to build since the number of methods has exceeded 64k. You may pass the --no-multidex
flag to skip Flutter's multidex support to use a manual solution.
Flutter tool can add multidex support. The following file will be added by flutter:
android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java
Do you want to continue with adding multidex support for Android? [y|n]:
After confirmation - voila:
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
To run on your emulator:
flutter run --multidex

How to add a fork github package to the pubspec.yaml?

map_view plugin is no longer maintained and let users with problems if the min sdk is up to 28, so luckily Eimji fork a modified version of the package but it's only on github https://github.com/Eimji/flutter_google_map_view and not on https://pub.dartlang.org I search to add his fork to my pubspec.yaml.
I tried
flutter_google_map_view:
git://github.com/Eimji/flutter_google_map_view.git
Thank you
Update
I changed name by map_view it seems accepted ...
but when I use flutter_google_map_view I have
Error on line 1, column 7 of flutter_google_map_view\pubspec.yaml: "name" field doesn't match expected name "flutter_google_map_view".
I don't know why map_view "works" but not mapview ...So I don't know if it's really accepted or the great methode ...
So now I have other issue when I upload my local map_view package ...
* Error running Gradle:
Exit code 1 from: C:\Users\utilisateur\AndroidStudioProjects\nirbi\android\gradlew.bat app:properties:
WARNING: The specified Android SDK Build Tools version (25.0.3) is ignored, as it is below the minimum supported version (27.0.3) for Android Gradle Plugin 3.1.2.
Android SDK Build Tools 27.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '25.0.3'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
WARNING: The specified Android SDK Build Tools version (25.0.3) is ignored, as it is below the minimum supported version (27.0.3) for Android Gradle Plugin 3.1.2.
Android SDK Build Tools 27.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '25.0.3'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
WARNING: The specified Android SDK Build Tools version (25.0.3) is ignored, as it is below the minimum supported version (27.0.3) for Android Gradle Plugin 3.1.2.
Android SDK Build Tools 27.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '25.0.3'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':map_view'.
> Failed to notify project evaluation listener.
> java.lang.AbstractMethodError (no error message)
I search buildToolsVersion '25.0.3 from my build.gradle file , but nothing like this. So I add buildToolsVersion '28.0.3' in build.gradle but have always the same error ...
Update
I remove all "buildToolsVersion '25.0.3'" it seem working and now I have this last issue :
* Error running Gradle:
Exit code 1 from: C:\Users\utilisateur\AndroidStudioProjects\nirbi\android\gradlew.bat app:properties:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':map_view'.
> Failed to notify project evaluation listener.
> java.lang.AbstractMethodError (no error message)
I think map_view is not correctly accepted ...
Update
Some suggestions to simply import this github package https://github.com/Eimji/flutter_google_map_view to pubspec.yaml ?
when I use
flutter_google_map_view:
git: git://github.com/Eimji/flutter_google_map_view.git
I have this error ...
Git error. Command: git clone --mirror git://github.com/munificent/map_view.git C:\Users\utilisateur\AppData\Roaming\Pub\Cache\git\cache\map_view-84b47933c6a730a2f0624a589576e53be480ad60
Cloning into bare repository 'C:\Users\utilisateur\AppData\Roaming\Pub\Cache\git\cache\map_view-84b47933c6a730a2f0624a589576e53be480ad60'...
Update
I tried my last chance ! import map_view: ^0.0.14 (no compatible android X) and add manualy all modification did by Eimji https://github.com/Eimji/flutter_google_map_view/commit/5b631c499783936dfc462039274a6f5c59323068#diff-7ae5a9093507568eabbf35c3b0665732
I have this error
* Error running Gradle:
Exit code 1 from: C:\Users\utilisateur\AndroidStudioProjects\nirbi\android\gradlew.bat app:properties:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':map_view'.
> Failed to notify project evaluation listener.
> java.lang.AbstractMethodError (no error message)
See https://www.dartlang.org/tools/pub/dependencies#git-packages
dependencies:
kittens:
git:
url: git://github.com/munificent/kittens.git
ref: some-branch
If pubspec.yaml is not in the root directory you can also specify a path
dependencies:
kittens:
git:
url: git://github.com/munificent/cats.git
path: path/to/kittens

Unable to import new Gradle project:failed to find Build Tools revision 25.2.4

When I try to import https://github.com/TomGrill/gdx-firebase this project in eclipse,I got this error
"Could not find com.android.support:support-v4:24.0.0."
I have done installation of latest android sdk tools 25.2.4 from android sdk manager and updated the following changes in build.gradle.
compileSdkVersion 23
buildToolsVersion "25.2.4"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
}
currently I am getting this error
"failed to find Build Tools revision 25.2.4"
Can anyone tell me,how do I fix this?
Update
I am still getting this error while importing that project,how to fix this?
"Could not find com.android.support:support-v4:24.0.0."
Searched in the following locations:
https://repo1.maven.org/maven2/com/android/support/support-v4/24.0.0/support-v4-24.0.0.pom
https://repo1.maven.org/maven2/com/android/support/support-v4/24.0.0/support-v4-24.0.0.aar
file:/Users/divya/.m2/repository/com/android/support/support-v4/24.0.0/support-v4-24.0.0.pom
file:/Users/divya/.m2/repository/com/android/support/support-v4/24.0.0/support-v4-24.0.0.aar
https://jcenter.bintray.com/com/android/support/support-v4/24.0.0/support-v4-24.0.0.pom
https://jcenter.bintray.com/com/android/support/support-v4/24.0.0/support-v4-24.0.0.aar
https://oss.sonatype.org/content/repositories/snapshots/com/android/support/support-v4/24.0.0/support-v4-24.0.0.pom
https://oss.sonatype.org/content/repositories/snapshots/com/android/support/support-v4/24.0.0/support-v4-24.0.0.aar
https://oss.sonatype.org/content/repositories/releases/com/android/support/support-v4/24.0.0/support-v4-24.0.0.pom
https://oss.sonatype.org/content/repositories/releases/com/android/support/support-v4/24.0.0/support-v4-24.0.0.aar
file:/Applications/android/android-sdk-macosx/extras/google/m2repository/com/android/support/support-v4/24.0.0/support-v4-24.0.0.pom
file:/Applications/android/android-sdk-macosx/extras/google/m2repository/com/android/support/support-v4/24.0.0/support-v4-24.0.0.aar
Required by:
de.tomgrill.gdxfirebase.android:android:0.0.4-SNAPSHOT > com.google.firebase:firebase-database:9.8.0 > com.google.android.gms:play-services-basement:9.8.0
Check buildToolsVersion, you have in Android SDK Manager. Currently latest is 25.0.2.
Android SDK Build-tools is different from
Android SDK Tools(latest 25.2.4) and
Android SDK Platform-tools(latest 25.0.3).
Hopefully it may be helpful
Thanks