Flutter says Execution failed for task ':sqflite:compileDebugJavaWithJavac' - flutter

I used to have this sqflite in my pubspec.yaml file but recently I removed the dependence seeing I won't be making use of it, then I run the app on my android device and emulator I got a strange error and have googled for the solution, it seems I can't find any help and as well check stackoverflow.
What have done so far:
As a rule of thumb, i ran flutter clean to see if issue will be
resolved but it did not worked either
Invalidate and Restart Android Studio
Here is the Error am having
Launching lib/main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
/Users/zionnite/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.0+3/android/src/main/java/com/tekartik/sqflite/SqflitePlugin.java:910: error: cannot find symbol
database.deleteDatabase(path);
^
symbol: variable database
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':sqflite: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 58s
Exception: Gradle task assembleDebug failed with exit code 1
Dependency of Interest
# sqflite: ^2.0.0+3
# path_provider: ^2.0.1
At this time even if I enable the dependency, the issue still persists.
However, everything is working out great on my ios simulator except android device and emulator

The issue caused by Java version 8. So you should use Java version 11.
Add this to build.gradle file (android/app/build.gradle)
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
Change JDK of Gradle in Android studio
Finally, Clean and rebuild.
That's it.

Issue resolved after downloading Java 11,also check the gradle and wrapper version you're using

I was encountering the same issue.I have done everything which is mentioned on stackoverflow .but the problem is in my new added package which is cached_network_image .I just remove this package and every thing start working.So you just check which new package you added and which create fuss..

I was able combat the enemy of death fighting for the progress of my code and obtain victory through the magical touch of flutter pub cache repair.
what i mean to say is that, when i ran flutter pub cache repair, Flutter was able to build and run on my android device and emulator

Related

I am using VS Code for Flutter. I have downloaded Android SDK platform 30. But it tells me to download 29 version

I am new to flutter. Here is a list of available tools on SDK Manager -
As you can see I've downloaded the tools. But debugging in the ide shows an error and tells me download a tools that are not installed -
'''
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Failed to install the following SDK components:
build-tools;28.0.3 Android SDK Build-Tools 28.0.3
platforms;android-29 Android SDK Platform 29
Install the missing components using the SDK manager in Android Studio.
2
* 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 51s
[!] Gradle threw an error while downloading artifacts from the network. Retrying to download...
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
'''
Please help me out.
There seemed to be errors in installing certain dependencies ( sdk 30 ). Might be a technical glitch. Try installing again using flutter doctor.
I think you have to accept the licenses before building.
Try this command in the terminal
flutter doctor --android-licenses
Try flutter doctor command in your terminal. which helps us diagnose issues with your setup
flutter doctor
to learn more https://stackoverflow.com/a/55641042/7904389
Please share the android/app/build.gradle, it is probably targeting API level 29 (targetSdkVersion 29 and compileSdkVersion 29). Change them to 30 or download the API level 29 SDKs.
If it still doesn't work after that, the SDK might be missing, go to the ANDROID_HOME directory and ensure it contains an sdk directory with the stuff you want.
I couldn't figure out what the error was, but creating a new project worked for me.

How do I solve a configuration problem with audioplayers when using the command flutter build apk?

I have just created an app with flutter and I want to get the apks by splitting per abi. When given the command, there is a problem with configuring the plugin audioplayers.
I thought it could be a problem with using androidX?
Here is the error I get:
´´´
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':audioplayers:verifyReleaseResources'.
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
Android resource linking failed
C:\Users\vanda_qwkpv9x.gradle\caches\transforms-2\files-2.1\7faf2ad74a0b9932e38d86e684646e95\core-1.0.0\res\values\values.xml:57:5-88:25: AAPT: error: resource android:attr/fontVariationSettings not found.
C:\Users\vanda_qwkpv9x.gradle\caches\transforms-2\files-2.1\7faf2ad74a0b9932e38d86e684646e95\core-1.0.0\res\values\values.xml:57:5-88:25: AAPT: error: resource android:attr/ttcIndex not found.
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 56s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 57.7s
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve
the incompatibility.
Building plugin audioplayers...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done 2.0s
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'audioplayers'.
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Get more help at https://help.gradle.org
BUILD FAILED in 1s
The plugin audioplayers could not be built due to the issue above.
Anyone suggestions?
EDIT: With newer Flutter projects (thus newer Gradle versions), android.enableR8 is deprecated!
I'm not an expert with Android nor Flutter, but after many tests it seems that the issue isn't related to a package your recently installed, but with the size of the build! I was getting errors related to audioplayers, assets_audio_player, multiple Firebase packages and so on.
In android\gradle.properties make sure you don't have android.enableR8 set to false.
Here were my issues and steps for those interested:
I was only getting errors similar to yours only on build, not while using hot reload
Errors were related to audioplayers which led me to think it's just a package issue
Replaced it with assets_audio_player, but the problems continued
Changed the order, but this made the error shift to Firebase. I recently added Craslytics and this made me think it's because I used a newer version compared to the 1-2 months old packages. I thought it was the time to upgrade to 8.x, but that didn't make sense either. Never had such issues with any FB service/
Removed the latest sound packages, build was successful, but after adding more random packages (just to increase the size), the errors came back!
R8 announcement:
R8, the new code shrinker from Google, is available in Android studio 3.3 beta
Android developers know that APK size is an important factor in user engagement. Code shrinking helps reduce the size of your APK by getting rid of unused code and resources as well as making your actual code take less space (also known as minification or obfuscation).

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

How to properly import Open Source projects in Flutter?

I am learning Flutter and I would like to import an Open Source project to learn some of the structure etc.
The project is: https://github.com/matthewtory/trinity-orientation-2018
I am using Android Studio, and so far I can create my own projects and run them via my phone but when I want to import this project I am getting a lot of errors and warnings. The app is finished and also on the play store, so why doesn't it run in my IDE? Am I missing something?
Error message is:
Launching lib\main.dart on SM G960F in debug mode...
Initializing gradle...
Resolving dependencies...
* Error running Gradle:
ProcessException: Process "C:\Users\marcs\AndroidStudioProjects\trinity-orientation-2018-master\android\gradlew.bat" exited abnormally:
firebase_storage
firebase_messaging
url_launcher
camera
path_provider
cloud_firestore
shared_preferences
image_picker
firebase_core
firebase_auth
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\marcs\AndroidStudioProjects\trinity-orientation-2018-master\android\app\build.gradle' line: 16
* What went wrong:
A problem occurred evaluating project ':app'.
> versionCode not found. Define flutter.versionCode in the local.properties 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 2s
Command: C:\Users\marcs\AndroidStudioProjects\trinity-orientation-2018-master\android\gradlew.bat app:properties
Finished with error: Please review your Gradle project setup in the android/ folder.
I downloaded the project and imported the folder in Android Studio. It first asked to get the dependencies which I did and immediately, I tried to run it on my phone.
Feel free to check the code on the Github project. I have not changed anything. I hope to run this project to learn about animation and navigation concepts.
The error message says you have to define version code. Try to add below lines to your local.properties file (under android folder)
flutter.versionName=1.0.0
flutter.versionCode=1
You may get other errors but at least this will fix the error in your question. Share other error message if you get.

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.