Gradle build failed to produce an .apk file - flutter

After upgrading Flutter from 1.9.7 to v1.12.13+hotfix.5 my application build failed. I got the following exception:
[ +124 ms] > Task :draw:compileFossDebugSources UP-TO-DATE
[ +5 ms] > Task :draw:assembleFossDebug UP-TO-DATE
[ +136 ms] Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
[ ] Use '--warning-mode all' to show the individual deprecation warnings.
[ ] See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
[ ] BUILD SUCCESSFUL in 5m 30s
[ ] 396 actionable tasks: 16 executed, 380 up-to-date
[ +529 ms] Running Gradle task 'assembleFossDebug'... (completed in 331.1s, longer than expected)
[ +35 ms] "flutter run" took 332,133ms.
Gradle build failed to produce an .apk file. It's likely that this file was generated under C:\flutter_projects\my_branch\iamflexi_app\build, but the tool couldn't find it.
#0 throwToolExit (package:flutter_tools/src/base/common.dart:28:3)
#1 _exitWithExpectedFileNotFound (package:flutter_tools/src/android/gradle.dart:827:3)
#2 findApkFiles (package:flutter_tools/src/android/gradle.dart:765:5)
#3 buildGradleApp (package:flutter_tools/src/android/gradle.dart:451:35)
#4 _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:73:64)
#5 _rootRunUnary (dart:async/zone.dart:1134:38)
#6 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#7 _FutureListener.handleValue (dart:async/future_impl.dart:139:18)
#8 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680:45)
#9 Future._propagateToListeners (dart:async/future_impl.dart:709:32)
#10 Future._completeWithValue (dart:async/future_impl.dart:524:5)
#11 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:32:15)
#12 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:290:13)
#13 _DefaultProcessUtils.stream (package:flutter_tools/src/base/process.dart)
#14 _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:73:64)
#15 _rootRunUnary (dart:async/zone.dart:1134:38)
#16 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#17 _FutureListener.handleValue (dart:async/future_impl.dart:139:18)
#18 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680:45)
#19 Future._propagateToListeners (dart:async/future_impl.dart:709:32)
#20 Future._completeWithValue (dart:async/future_impl.dart:524:5)
#21 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:554:7)
#22 _rootRun (dart:async/zone.dart:1126:13)
#23 _CustomZone.run (dart:async/zone.dart:1023:19)
#24 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
#25 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
#26 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#27 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
#28 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#29 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:175:5)
However when i open my application in Android module in Android Studio then it runs fine but when i tried to run with Flutter i got that error.

Using Android Studio may prompt you to upgrade the project's settings (i.e. gradle version). A quick fix for this issue is by downgrading to the project's previous gradle version as previously mentioned in the comments. You can also try going through suggestions posted on this GitHub issue thread ahttps://github.com/flutter/flutter/issues/45681 and see if anything works for you.

Related

Whats the difference between dart run vs flutter pub run

I downloaded the Mockito library (https://pub.dev/packages/mockito) and followed the instruction to use "dart run build_runner build" to generate mocks in my project directory and it failed with the following error.
Could not find a file named "pubspec.yaml" in "/Users/mark/.pub-cache/hosted/pub.dartlang.org/_fe_analyzer_shared-31.0.0".
#0 new Pubspec.load (package:pub/src/pubspec.dart:288:7)
#1 new Package.load (package:pub/src/package.dart:149:27)
#2 SystemCache.load (package:pub/src/system_cache.dart:113:20)
#3 Entrypoint._createPackageGraph (package:pub/src/entrypoint.dart:112:63)
#4 Entrypoint.packageGraph (package:pub/src/entrypoint.dart:107:54)
#5 getExecutableForCommand (package:pub/src/executable.dart:338:19)
#6 RunCommand.run (package:dartdev/src/commands/run.dart:232:32)
#7 CommandRunner.runCommand (package:args/command_runner.dart:209:27)
#8 DartdevRunner.runCommand (package:dartdev/dartdev.dart:232:30)
#9 CommandRunner.run.<anonymous closure> (package:args/command_runner.dart:119:25)
#10 new Future.sync (dart:async/future.dart:296:31)
#11 CommandRunner.run (package:args/command_runner.dart:119:14)
#12 runDartdev (package:dartdev/dartdev.dart:67:29)
#13 main (file:///opt/s/w/ir/cache/builder/sdk/pkg/dartdev/bin/dartdev.dart:11:9)
#14 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:293:32)
#15 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
However if I followed the instructions in Flutter's cookbook(https://docs.flutter.dev/cookbook/testing/unit/mocking#3-create-a-test-file-with-a-mock-httpclient) and used "flutter pub run build_runner build" in the project directory it works.
What are the differences between dart run and flutter pub run? Why dart run tries to execute from the /Users/username/.pub-cache directory when I am executing it from the project directory?
I saw this related issue in Mockit, however it does not explain the differences. (https://github.com/dart-lang/mockito/issues/435)

LateInitializationError: Field 'annotationAst' has not been initialized

I upgrade my packages using dart pub outdated --mode=null-safety command. after updating my packages I got this error while running dart migrate to migrate my code to null-safety.
also when I tried to run flutter pub run build_runner build --delete-conflicting-outputs command for moor database.
I have no clue where this error is coming from and my codebase is really big to search for any initialization or annotation
Why does this issue happen and How can I solve that?
LateInitializationError: Field 'annotationAst' has not been initialized.
#0 ElementAnnotationImpl.annotationAst (package:analyzer/src/dart/element/element.dart)
#1 ConstantEvaluationEngine.computeDependencies (package:analyzer/src/dart/constant/evaluation.dart:336:39)
#2 _ConstantWalker._computeDependencies (package:analyzer/src/dart/constant/compute.dart:75:22)
#3 _ConstantNode.computeDependencies (package:analyzer/src/dart/constant/compute.dart:43:19)
#4 Node.getDependencies (package:analyzer/src/summary/link.dart:148:40)
#5 DependencyWalker.walk.strongConnect (package:analyzer/src/summary/link.dart:53:40)
#6 DependencyWalker.walk (package:analyzer/src/summary/link.dart:119:18)
#7 computeConstants (package:analyzer/src/dart/constant/compute.dart:26:14)
#8 LibraryAnalyzer._computeConstants (package:analyzer/src/dart/analysis/library_analyzer.dart:250:5)
#9 LibraryAnalyzer.analyzeSync (package:analyzer/src/dart/analysis/library_analyzer.dart:135:5)
#10 LibraryAnalyzer.analyze (package:analyzer/src/dart/analysis/library_analyzer.dart:103:12)
#11 AnalysisDriver._computeAnalysisResult.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1624:63)
#12 PerformanceLog.run (package:analyzer/src/dart/analysis/performance_logger.dart:32:15)
#13 AnalysisDriver._computeAnalysisResult (package:analyzer/src/dart/analysis/driver.dart:1600:20)
#14 AnalysisDriver._computeErrors (package:analyzer/src/dart/analysis/driver.dart:1678:26)
#15 AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:1301:20)
#16 AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2334:24)

Flutter not building the android dependencies

Folks,
I am re-building an already built flutter application upon changing of the laptop. However I have strangely observed that the dependencies that we mention in the pubspec, not all of them are getting compiled. Those ones which has native dependencies and eventually have android code base in the dependencies fail to compile. I am cluless how this is happening and where should i look forward to get this going. The only error I get is as below. The contentious dependencies were share and connectivity
warning: [options] source value 7 is obsolete and will be removed in a future release
[ +5 ms] warning: [options] target value 7 is obsolete and will be removed in a future release
[ +1 ms] warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
[ +1 ms] error: warnings found and -Werror specified
[ +190 ms] FAILURE: Build failed with an exception.
[ ] * What went wrong:
[ ] Execution failed for task ':share:compileDebugJavaWithJavac'.
[ +97 ms] > 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.
[ +3 ms] * Get more help at https://help.gradle.org
[ +1 ms] BUILD FAILED in 1m 41s
[ +1 ms] Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
[ +1 ms] Use '--warning-mode all' to show the individual deprecation warnings.
[ +5 ms] See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings
[ ] 410 actionable tasks: 4 executed, 406 up-to-date
[ +794 ms] Running Gradle task 'assembleDebug'... (completed in 103.9s)
[ +9 ms] Exception: Gradle task assembleDebug failed with exit code 1
[ +4 ms] "flutter run" took 1,08,191ms.
[ +9 ms]
#0 throwToolExit (package:flutter_tools/src/base/common.dart:14:3)
#1 RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:607:7)
<asynchronous suspension>
#2 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:977:18)
<asynchronous suspension>
#3 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:836:33)
<asynchronous suspension>
#4 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart)
#5 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:29)
#6 _rootRun (dart:async/zone.dart:1190:13)
#7 _CustomZone.run (dart:async/zone.dart:1093:19)
#8 _runZoned (dart:async/zone.dart:1630:10)
#9 runZoned (dart:async/zone.dart:1550:10)
#10 AppContext.run (package:flutter_tools/src/base/context.dart:149:18)
#11 FlutterCommand.run (package:flutter_tools/src/runner/flutter_command.dart:825:20)
#12 CommandRunner.runCommand (package:args/command_runner.dart:197:27)
#13 FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:335:21)
#14 _rootRunUnary (dart:async/zone.dart:1198:47)
#15 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#16 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#17 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#18 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#19 Future._completeWithValue (dart:async/future_impl.dart:529:5)
#20 Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7)
#21 _rootRun (dart:async/zone.dart:1190:13)
#22 _CustomZone.run (dart:async/zone.dart:1093:19)
#23 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#24 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
#25 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#26 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#27 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#28 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)
[ +6 ms] ensureAnalyticsSent: 3ms
[ +3 ms] Running shutdown hooks
[ ] Shutdown hook priority 4
[ +12 ms] Shutdown hooks complete
[ +1 ms] exiting with code 1
I am using flutter 1.22.6 stable
dart 2.10.5
Gradle 6.5
I have tried it out with 1.22.3 and also with 1.20.4, still this is not taking me anywhere. All that it ends up is not compiling the dependencies having android code in it. gradlew assembleDebug --info and likes of it has resulted in me understanding that the java symbols are not created which eventually are not found by the compilation script, hence it is generating error.
things ive done so far:
run with --no-sound-null-safety and --verbose
find dependencies that complain and check for updates, then update to latest in pubspec
one dependency complained about android min sdk version in gradle.build, so i updated accordingly
now i can build to my test machine and work out the runtime bugs!
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Flutter

flutter build apk --release fails while flutter build apk -- debug works fine

I need to release a signed apk for my flutter project, but the "flutter build apk --release" command fails.
The "flutter build apk --debug" command works fine.
I have checked the setup using "flutter doctor" and everything seems fine.
I have tried cleaning the project with flutter clean but it didn't help.
The error returned by the "flutter build apk --debug -v" is:
Gradle build failed to produce an Android package.
#0 throwToolExit (package:flutter_tools/src/base/common.dart:24:3)
#1 _buildGradleProjectV2 (package:flutter_tools/src/android/gradle.dart:484:7)
<asynchronous suspension>
#2 buildGradleProject (package:flutter_tools/src/android/gradle.dart:346:14)
<asynchronous suspension>
#3 buildApk (package:flutter_tools/src/android/apk.dart:34:9)
<asynchronous suspension>
#4 BuildApkCommand.runCommand (package:flutter_tools/src/commands/build_apk.dart:51:11)
<asynchronous suspension>
#5 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:559:18)
#6 _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:77:64)
#7 _rootRunUnary (dart:async/zone.dart:1132:38)
#8 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#9 _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
#10 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
#11 Future._propagateToListeners (dart:async/future_impl.dart:668:32)
#12 Future._complete (dart:async/future_impl.dart:473:7)
#13 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#14 _AsyncAwaitCompleter.complete.<anonymous closure> (dart:async-patch/async_patch.dart:33:20)
#15 _rootRun (dart:async/zone.dart:1124:13)
#16 _CustomZone.run (dart:async/zone.dart:1021:19)
#17 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:947:23)
#18 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#19 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#20 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:115:13)
#21 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:5)
Error was due to invalid password for the keystore. After fixing it, build compleded correctly.
According to Android SDK docs you can use the following command depending on the sdkmanager location: Docs on --licenses option seems to be missing though.
yes | sdkmanager --licenses
GNU/Linux Distributions:
yes | ~/Android/Sdk/tools/bin/sdkmanager --licenses
macOS:
export JAVA_HOME=/Applications/Android\
Studio.app/Contents/jre/jdk/Contents/Home
yes | ~/Library/Android/sdk/tools/bin/sdkmanager --licenses
Windows:
%ANDROID_HOME%/tools/bin/sdkmanager --licenses
Run Flutter Clean Also
If you have following this link properly of Signing the app if you want to upload it to play store then following command should work properly :
flutter build apk --release
If above doesn't work try to use :
flutter build apk // this command default creates the release apk, but don't know if you can upload it to play store

Flutter with installation error for %1 is not a valid win32 application

I am new in the flutter and trying to install it with following steps...
1) download and unzipped in drive
2) Set path in environment variables
Now i am trying to run flutter doctor it's showing me below error please check if anyone face same issue...Thanks!
` [√] Flutter (Channel beta, v0.6.0, on Microsoft Windows [Version 10.0.17134.228], locale en-US)
-Unhandled exception:
ProcessException: %1 is not a valid Win32 application.
Command: C:\Users\Rahul Mishra\AppData\Local\Android\Sdk\platform-tools\adb.EXE devices -l
#0 _ProcessImpl._runAndWait (dart:io/runtime/binprocess_patch.dart:488:7)
#1 _runNonInteractiveProcessSync (dart:io/runtime/binprocess_patch.dart:634:18)
#2 Process.runSync (dart:io/runtime/binprocess_patch.dart:66:12)
#3 LocalProcessManager.runSync (package:process/src/interface/local_process_manager.dart:83:20)
#4 _runWithLoggingSync (package:flutter_tools/src/base/process.dart:322:48)
#5 runSync (package:flutter_tools/src/base/process.dart:296:10)
#6 getAdbDevices (package:flutter_tools/src/android/android_device.dart:563:23)
#7 AndroidDevices.pollingGetDevices (package:flutter_tools/src/android/android_device.dart:55:53)
<asynchronous suspension>
#8 PollingDeviceDiscovery.devices (package:flutter_tools/src/device.dart:163:56)
<asynchronous suspension>
#9 DeviceManager.getAllConnectedDevices (package:flutter_tools/src/device.dart:91:46)
<asynchronous suspension>
#10 DeviceValidator.validate (package:flutter_tools/src/doctor.dart:537:54)
<asynchronous suspension>
#11 Doctor.startValidatorTasks (package:flutter_tools/src/doctor.dart:88:56)
#12 Doctor.diagnose (package:flutter_tools/src/doctor.dart:145:41)
#13 _AsyncAwaitCompleter.start (dart:async/runtime/libasync_patch.dart:49:6)
#14 Doctor.diagnose (package:flutter_tools/src/doctor.dart:135:24)
#15 DoctorCommand.runCommand (package:flutter_tools/src/commands/doctor.dart:29:39)
#16 _AsyncAwaitCompleter.start (dart:async/runtime/libasync_patch.dart:49:6)
#17 DoctorCommand.runCommand (package:flutter_tools/src/commands/doctor.dart:28:42)
#18 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:348:18)
#19 _asyncThenWrapperHelper.<anonymous closure> (dart:async/runtime/libasync_patch.dart:77:64)
#20 _rootRunUnary (dart:async/zone.dart:1132:38)
#21 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#22 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#23 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#24 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#25 Future._complete (dart:async/future_impl.dart:476:7)
#26 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#27 _AsyncAwaitCompleter.complete.<anonymous closure> (dart:async/runtime/libasync_patch.dart:33:20)
#28 _rootRun (dart:async/zone.dart:1124:13)
#29 _CustomZone.run (dart:async/zone.dart:1021:19)
#30 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:947:23)
#31 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#32 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#33 _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:114:13)
#34 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:170:5)`
When I ran into this it was because the environment variable ANDROID_HOME had a space in it, in your case it would be C:\Users\Rahul Mishra\AppData\Local\Android\Sdk and there is a space between Rahul and Mishra
What I did to resolve it is make a junction to my profile that doesn't contain spaces and redirect ANDROID_HOME to it. To make a junction you would do something like:
mklink /J C:\Users\rmishra "C:\Users\Rahul Mishra"
Then in System Properties -> Environment Variables change ANDROID_HOME to point to C:\Users\rmishra\AppData\Local\Android\Sdk
Hopefully this helps
Did you install Android Studio, it is sending and adb error i believe that part of the android sdk installation.
Please do all the steps from the documentation for windows.
It is because of the space in your username. I had the same issue and messed up my whole registry and changed the directory of my user to something without last name. At the end it worked.
First change your username and then try to change the directory name
Like #cshortridge mentioned its because of the ANDROID_HOME had space but that solution didn't work for me, so I started to search and I discovered you just have to move the Android SDK which is located by default. I found this wonderful tutorial to change the path of the SDK manager:
https://github.com/flutter/flutter/issues/19805#issuecomment-478306166
hope that helps someone :)