1

I am trying to build an Android apk for google play console. When I run

FAILURE: Build failed with an exception.

* Where:
Script '/opt/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 991

* What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
> Process 'command '/opt/flutter/bin/flutter'' finished with non-zero exit value 1

* 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 48s
Running Gradle task 'assembleRelease'...                           49.0s
Gradle task assembleRelease failed with exit code 1
Process finished with exit code 1

Does anyone know what's wrong and how to fix it?

The flutter build apk --verbose

[+4690 ms] [+5536 ms] ../../../.pub-cache/hosted/pub.dartlang.org/flutter_svg-0.19.1/lib/src/picture_provider.dart:52:59: Error: No named parameter with
the name 'nullOk'.
[   +1 ms] [   +1 ms]         context != null ? Localizations.localeOf(context, nullOk: true) : null,
[        ] [        ]                                                           ^^^^^^
[        ] [        ] /opt/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17: Context: Found this candidate, but the arguments don't
match.
[        ] [        ]   static Locale localeOf(BuildContext context) {
[        ] [        ]                 ^^^^^^^^
[+4399 ms] [+4424 ms] Persisting file store
[        ] [   +2 ms] Done persisting file store
[        ] [   +1 ms] Target kernel_snapshot failed: Exception
[        ]            #0      KernelSnapshot.build (package:flutter_tools/src/build_system/targets/common.dart:278:7)
[        ]            <asynchronous suspension>
[        ]            #1      _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:796:9)
[        ]            <asynchronous suspension>
[        ]            #2      Future.wait.<anonymous closure> (dart:async/future.dart)
[        ]            <asynchronous suspension>
[        ]            #3      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:734:32)
[        ]            <asynchronous suspension>
[        ]            #4      Future.wait.<anonymous closure> (dart:async/future.dart)
[        ]            <asynchronous suspension>
[        ]            #5      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:734:32)
[        ]            <asynchronous suspension>
[   +1 ms]            #6      Future.wait.<anonymous closure> (dart:async/future.dart)
[        ]            <asynchronous suspension>
[        ]            #7      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:734:32)
[        ]            <asynchronous suspension>
[        ]            #8      FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:563:16)
[        ]            <asynchronous suspension>
[        ]            #9      AssembleCommand.runCommand (package:flutter_tools/src/commands/assemble.dart:220:32)
[        ]            <asynchronous suspension>
[        ]            #10     FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1157:12)
[        ]            <asynchronous suspension>
[  +18 ms]            #11     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1009:27)
[        ]            <asynchronous suspension>
[        ]            #12     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
[        ]            <asynchronous suspension>
[        ]            #13     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
[        ]            <asynchronous suspension>
[        ]            #14     CommandRunner.runCommand (package:args/command_runner.dart:197:13)
[        ]            <asynchronous suspension>
[        ]            #15     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:278:9)
[        ]            <asynchronous suspension>
[   +1 ms]            #16     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
[        ]            <asynchronous suspension>
[        ]            #17     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
[        ]            <asynchronous suspension>
[        ]            #18     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:234:5)
[        ]            <asynchronous suspension>
[        ]            #19     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:64:9)
[        ]            <asynchronous suspension>
[        ]            #20     run.<anonymous closure> (package:flutter_tools/runner.dart:62:12)
[        ]            <asynchronous suspension>
[   +7 ms]            #21     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
[        ]            <asynchronous suspension>
[        ]            #22     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
[        ]            <asynchronous suspension>
[        ]            #23     runInContext (package:flutter_tools/src/context_runner.dart:73:10)
[        ]            <asynchronous suspension>
[        ]            #24     main (package:flutter_tools/executable.dart:90:3)
[        ]            <asynchronous suspension>
[        ] [   +3 ms] 
[        ]            #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
[        ]            #1      AssembleCommand.runCommand (package:flutter_tools/src/commands/assemble.dart:237:7)
[   +3 ms]            <asynchronous suspension>
[        ]            #2      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1157:12)
[        ]            <asynchronous suspension>
[        ]            #3      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1009:27)
[        ]            <asynchronous suspension>
[        ]            #4      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
[        ]            <asynchronous suspension>
[        ]            #5      AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
[        ]            <asynchronous suspension>
[        ]            #6      CommandRunner.runCommand (package:args/command_runner.dart:197:13)
[   +7 ms]            <asynchronous suspension>
[        ]            #7      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:278:9)
[        ]            <asynchronous suspension>
[        ]            #8      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
[        ]            <asynchronous suspension>
[        ]            #9      AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
[        ]            <asynchronous suspension>
[        ]            #10     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:234:5)
[        ]            <asynchronous suspension>
[        ]            #11     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:64:9)
[   +5 ms]            <asynchronous suspension>
[        ]            #12     run.<anonymous closure> (package:flutter_tools/runner.dart:62:12)
[        ]            <asynchronous suspension>
[        ]            #13     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
[        ]            <asynchronous suspension>
[        ]            #14     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
[        ]            <asynchronous suspension>
[        ]            #15     runInContext (package:flutter_tools/src/context_runner.dart:73:10)
[        ]            <asynchronous suspension>
[        ]            #16     main (package:flutter_tools/executable.dart:90:3)
[        ]            <asynchronous suspension>
[   +3 ms] FAILURE: Build failed with an exception.
[        ] * Where:
[        ] Script '/opt/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 991
[        ] * What went wrong:
[        ] Execution failed for task ':app:compileFlutterBuildRelease'.
[        ] > Process 'command '/opt/flutter/bin/flutter'' finished with non-zero exit value 1
[        ] * 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
[        ] [   +9 ms] "flutter assemble" took 10,215ms.
[        ] [   +1 ms] ensureAnalyticsSent: 0ms
[        ] [   +1 ms] Running shutdown hooks
[   +4 ms] [        ] Shutdown hooks complete
[        ] [   +1 ms] exiting with code 1
[        ] > Task :app:compileFlutterBuildRelease FAILED
[        ] > Task :agora_rtc_engine:bundleLibCompileRelease
[        ] 28 actionable tasks: 28 executed
[ +367 ms] Running Gradle task 'assembleRelease'... (completed in 57.4s)
[   +3 ms] "flutter apk" took 57,915ms.
[   +3 ms] Gradle task assembleRelease failed with exit code 1
[        ] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      buildGradleApp (package:flutter_tools/src/android/gradle.dart:411:7)
           <asynchronous suspension>
           #2      _AndroidBuilderImpl.buildApk (package:flutter_tools/src/android/android_builder.dart:101:7)
           <asynchronous suspension>
           #3      BuildApkCommand.runCommand (package:flutter_tools/src/commands/build_apk.dart:103:5)
           <asynchronous suspension>
           #4      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1157:12)
           <asynchronous suspension>
           #5      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1009:27)
           <asynchronous suspension>
           #6      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #7      AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
           <asynchronous suspension>
           #8      CommandRunner.runCommand (package:args/command_runner.dart:197:13)
           <asynchronous suspension>
           #9      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:278:9)
           <asynchronous suspension>
           #10     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #11     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
           <asynchronous suspension>
           #12     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:234:5)
           <asynchronous suspension>
           #13     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:64:9)
           <asynchronous suspension>
           #14     run.<anonymous closure> (package:flutter_tools/runner.dart:62:12)
           <asynchronous suspension>
           #15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #16     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
           <asynchronous suspension>
           #17     runInContext (package:flutter_tools/src/context_runner.dart:73:10)
           <asynchronous suspension>
           #18     main (package:flutter_tools/executable.dart:90:3)
           <asynchronous suspension>
           
           
[ +166 ms] ensureAnalyticsSent: 154ms
[   +1 ms] Running shutdown hooks
[        ] Shutdown hooks complete
[        ] exiting with code 1

After I upgraded flutter_svg to ^0.20.0-nullsafety.3

[   +3 ms] Gradle task assembleRelease failed with exit code 1
[        ] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      buildGradleApp (package:flutter_tools/src/android/gradle.dart:411:7)
           <asynchronous suspension>
           #2      _AndroidBuilderImpl.buildApk
(package:flutter_tools/src/android/android_builder.dart:101:7)
           <asynchronous suspension>
           #3      BuildApkCommand.runCommand (package:flutter_tools/src/commands/build_apk.dart:103:5)
           <asynchronous suspension>
           #4      FlutterCommand.verifyThenRunCommand
(package:flutter_tools/src/runner/flutter_command.dart:1157:12)
           <asynchronous suspension>
           #5      FlutterCommand.run.<anonymous closure>
           (package:flutter_tools/src/runner/flutter_command.dart:1009:27)
           <asynchronous suspension>
           #6      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #7      AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
           <asynchronous suspension>
           #8      CommandRunner.runCommand (package:args/command_runner.dart:197:13)
           <asynchronous suspension>
           #9      FlutterCommandRunner.runCommand.<anonymous closure>
           (package:flutter_tools/src/runner/flutter_command_runner.dart:278:9)
           <asynchronous suspension>
           #10     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #11     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
           <asynchronous suspension>
           #12     FlutterCommandRunner.runCommand
(package:flutter_tools/src/runner/flutter_command_runner.dart:234:5)
           <asynchronous suspension>
           #13     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:64:9)
           <asynchronous suspension>
           #14     run.<anonymous closure> (package:flutter_tools/runner.dart:62:12)
           <asynchronous suspension>
           #15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #16     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
           <asynchronous suspension>
           #17     runInContext (package:flutter_tools/src/context_runner.dart:73:10)
           <asynchronous suspension>
           #18     main (package:flutter_tools/executable.dart:90:3)
           <asynchronous suspension>
Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125

3 Answers3

1

1- What channel for Flutter are you using, stable?

2- If not, switch to stable, and run flutter upgrade.

3- Then run flutter clean.

4- Make sure you are in your correct path in terminal for your project.

5- Then flutter build apk.

If it fails, provide us with the output of this command flutter build apk --verbose

This will give a detailed explanation why and where it failed, and report back.

-=-=- Edit 1, after OP posted output of flutter build apk --verbose

read the first three lines of the output, there is your error

context != null ? Localizations.localeOf(context, nullOk: true) : null, 
[        ] [        ] ^^^^^^ [        ] [        ] 
opt/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17: 
Context: Found this candidate, but the arguments don't match. 
[        ] [        ]   static Locale localeOf(BuildContext context) 
{ [        ] [        ]                 ^^^^^^^^

This ==> nullOk:true Post the code related to your SVG package, to telling your app that it will not be null, but it's receiving a null value.

Try updating your flutter_svg package to this version in pubspec.yaml

flutter_svg: ^0.20.0-nullsafety.3

Huthaifa Muayyad
  • 11,321
  • 3
  • 17
  • 49
  • I have run upgrade and I am in stable. what do you mean in correct path? – Haifeng Zhang Mar 23 '21 at 06:56
  • I mentioned 6 steps, please don't stop at #2. By path, I mean the path of your project. i.e `user/halfengZhangdesktop/myAppProject/` That's the path, are you in the correct path for your project? What is your path and what is the path in the terminal when you run build? – Huthaifa Muayyad Mar 23 '21 at 06:58
  • i had tried the steps and the error still exist. – Haifeng Zhang Mar 23 '21 at 07:05
  • Dude, what is the output of `flutter build apk --verbose` . There clearly is something wrong going on and it's not a guessing game, and you only reply with "it didn't work". We know it's not working apparently, and we're trying to debug it, what is the output of this command? – Huthaifa Muayyad Mar 23 '21 at 07:10
  • please see my edited question, I have paste the output – Haifeng Zhang Mar 23 '21 at 07:16
  • @HaifengZhang read the first three lines of the output, there is your error `context != null ? Localizations.localeOf(context, nullOk: true) : null, [ ] [ ] ^^^^^^ [ ] [ ] /opt/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17: Context: Found this candidate, but the arguments don't match. [ ] [ ] static Locale localeOf(BuildContext context) { [ ] [ ] ^^^^^^^^` I'm editing my answer because I can't fit code here. – Huthaifa Muayyad Mar 23 '21 at 07:21
  • 1
    I updated answer, you should updte svg package to version: `flutter_svg: ^0.20.0-nullsafety.3` – Huthaifa Muayyad Mar 23 '21 at 07:30
  • Huthaifa, really appreciate your help. updated flutter_svg and got more errors. It's late on my end and will continue work on this. Had upvoted to your answer. – Haifeng Zhang Mar 23 '21 at 07:34
  • @HaifengZhang Sure thing, kindly upvote the useful comments and mark it as an answer. I would appreciate it, happy coding! – Huthaifa Muayyad Mar 23 '21 at 07:35
1
flutter clean,
flutter pub get,

flutter build appbundle --release --no-tree-shake-icons
Lance Olana
  • 154
  • 1
  • 4
0

There is 2 solutions for this error

  1. you need to build in this order, otherwise the release build will complain of missing debug.jars or profile.jars

    i. flutter build apk --debug

    ii. flutter build apk --profile

    iii. flutter build apk --release

2)downgrading the gradle.build

dependencies {
    classpath 'com.android.tools.build:gradle:4.0.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

to

 dependencies {
    classpath 'com.android.tools.build:gradle:3.5.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

and also changed the gradle-warpper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

to

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip

note : lintOptions { checkReleaseBuilds false } also work some times check this question for more details ':app:lintVitalRelease' error when generating signed apk

Aashif Ahamed
  • 1,143
  • 1
  • 9
  • 21