Repository navigation
flutter build apk fails on an app using Android Gradle plugin 4.0 #58247
Copy link
Copy link
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work listc: crashStack traces logged to the consoleStack traces logged to the consolec: regressionIt was better in the past than it is nowIt was better in the past than it is nowcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.Affects or could affect many people, though not necessarily a specific customer.dependency: androidAndroid team may need to help usAndroid team may need to help usfound in release: 1.21Found to occur in 1.21Found to occur in 1.21has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyAndroid applications specificallyt: gradle"flutter build" and "flutter run" on Android"flutter build" and "flutter run" on AndroidtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.
Milestone
Description
Canonical Issue
https://issuetracker.google.com/issues/141126614
Steps to Reproduce
- Run
flutter create counter - Update the app to use Android Gradle plugin 4.0.0
- Run
flutter build apk
Logs
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lintVitalRelease'.
> Could not resolve all artifacts for configuration ':app:debugRuntimeClasspath'.
> Failed to transform libs.jar to match attributes {artifactType=processed-jar, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for JetifyTransform: /Users/michaelbui/Projects/counter/build/app/intermediates/flutter/debug/libs.jar.
> Failed to transform '/Users/michaelbui/Projects/counter/build/app/intermediates/flutter/debug/libs.jar' using Jetifier. Reason: FileNotFoundException, message: /Users/michaelbui/Projects/counter/build/app/intermediates/flutter/debug/libs.jar (No such file or directory). (Run with --stacktrace for more details.)
Please file a bug at http://issuetracker.google.com/issues/new?component=460323.
* 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
[✓] Flutter (Channel stable, v1.17.2, on Mac OS X 10.15.5 19F96, locale en-AU)
• Flutter version 1.17.2 at /Users/michaelbui/flutter
• Framework revision 5f21edf8b6 (20 hours ago), 2020-05-28 12:44:12 -0700
• Engine revision b851c71829
• Dart version 2.8.3
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/michaelbui/Library/Android/sdk
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.5, Build version 11E608c
• CocoaPods version 1.9.1
[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6222593)
[✓] VS Code (version 1.45.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.10.2
Edit: created an issue against the Jetifier component as suggested by Gradle output https://issuetracker.google.com/u/1/issues/157728192
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work listc: crashStack traces logged to the consoleStack traces logged to the consolec: regressionIt was better in the past than it is nowIt was better in the past than it is nowcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.Affects or could affect many people, though not necessarily a specific customer.dependency: androidAndroid team may need to help usAndroid team may need to help usfound in release: 1.21Found to occur in 1.21Found to occur in 1.21has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyAndroid applications specificallyt: gradle"flutter build" and "flutter run" on Android"flutter build" and "flutter run" on AndroidtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.
Activity
Zazo032 commentedon May 29, 2020
Building apk also crashes for me. However, building appbundle works.
Running with
--releasealso crashes, but if you run--debugand then--release, it does seem to work (weird one). After succesfully running with--release, you'll be able tobuild apk.jason-simmons commentedon May 30, 2020
The Android Gradle
LintPerVariantTasknow appears to be adding JARs from all build variants to its inputs:https://android.googlesource.com/platform/tools/base/+/1f9787310d64a66370627a2aaefa1e616565c17d
The
libapp.solibraries containing the app's compiled Dart code are packaged in a JAR, and a different JAR is generated for each variant. I'm not sure how dynamically generated per-variant JARs are supposed to be handled if the lint task expects all variants' JARs to be available.As a hack workaround you could change the
lintOptionsinapp/build.gradleto disable the lint task:@blasten
newbieflutter commentedon May 31, 2020
Hi,
It also fails on my side I tried first --debug then --release it fails. I tried checkReleaseBuilds false but many plugin fails like shared_preferences, maps etc all fail to work. What is the best solution ?
sgehrman commentedon May 31, 2020
Malik056 commentedon May 31, 2020
Same here. Recently updated android studio, android sdk, gradle and flutter, And I no longer able to build release apk
newbieflutter commentedon May 31, 2020
Hi,
Looks like this is a big issue then. I upgrade all too. Any one found any solution?
Jwiggiff commentedon May 31, 2020
I wouldn't consider this a solution, but I've found a workaround. I was having the same issue and tried building
--debugand then--releaseand it still didn't work. However, if you look at the path in your specific error, it should either end withdebug/libs.jarorprofile/libs.jar. This indicates which apk you need to build first. In OP's case it isdebug/libs.jarso building--debugfirst and then--releaseworked. In my case, it wasprofile/libs.jarso building--profileand then--releaseworked. I'm pretty sure building the--releaseshouldn't have to access thedebugorprofiledirectories though.TL;DR
If your error says
debug/libs.jar, build--debugthen--release.If your error says
profile/libs.jar, build--profilethen--release.Malik056 commentedon May 31, 2020
I downgraded the android gradle and gradle version, from Android studio Project Structure. And Clean build my project. now it is working.
amelnikov78 commentedon Jun 1, 2020
@Jwiggiff
That works, thanks!
130 remaining items
niktses commentedon May 6, 2021
This is still not working on flutter 2.0.6.
Many packages dont support both gradle 3.+ and null safety and we can still not build apps on release mode on gradle 4.+.
The only solution is keep everything outdated in order to be able to build release apk with 3.+.
How is this not fixed yet?
zanderso commentedon May 6, 2021
@niktses This issue was filed over a year ago, and is marked closed. If you are still having a problem, please file a new issue with full details and instructions to reproduce it. Thanks!
niktses commentedon May 7, 2021
It is marked as closed while it is not fixed and has over a hundred comments. It makes more sense to me to reopen this. And it is a major issue as well. As i see it as of right now no flutter developer can reasonably release their app while having upgraded to flutter 2.0 and gradle 4.0 that has came out a year ago.
pedromassangocode commentedon May 7, 2021
Hi @niktses
This issue was closed as fixed by #71446. If you are still facing it, please file a new issues with the steps to reproduce the issue.
Thank you
niktses commentedon May 7, 2021
This is an issue that has not been fixed for 1.2 year not a new one. This needs to reopen. Me copy pasting the original into a new issue doesn't seem correct.
zanderso commentedon May 7, 2021
@niktses We would like to resolve your issue, but we can't do that without a fairly detailed explanation of what you are doing. See @blasten's comment above in #58247 (comment). The best place to put that information is in a new issue so that it will be visible to the team. Thanks!
niktses commentedon May 8, 2021
I really don't get why you don't reopen it. There is not a single word that i would change if i created a new one.
Run flutter create counter
Update the app to use Android Gradle plugin 4.0.0
Run flutter build apk
You can scroll to the top to see more details.
Gradle expects a ../libs.jar for every combination of flavor - buildType (in new project needs 3 - release - debug - profile, in my project needs 48 so the above 'solutions' of running each one once is out of the question especially with dev-op).
This is not a simple issue as it prevents us from releasing an app as the apk is never generated.
rundun commentedon May 10, 2021
Hi @zanderso if you review my issue I logged #81974
You will be able to reproduce the issue of Flutter supporting AGP 4.0.1.
I am still debugging and trying to figure it out, but the gist of it all is that Flutter Tools does not have a reference to the gradle setup, Gradle seems to be dependant on what location in the directory you run it from.
The Command that fails :
In my issue I also show the use of the same Flutter Tools command (flutter run -v) where it can only work manually if run in the android directory, I believe at this point there is something wrong with the way the command is executed via the process manager in flutter tools.
Also adding the -p flag to the command and running it manually from the project root directory works.
I have tried to manipulate the command on dev channel and it shows that flutter tools cant even read the gradlew tasks from the android directory and reads from the project directory which has a .gradle folder but it only has the boiler plate tasks in it.
atleugim commentedon Jun 7, 2021
This works, I had to do all 3 builds,
first with the --debug flag and then --profile to finally compile in --release mode.
THANKS
elhe26 commentedon Jul 8, 2021
Same issues. I have 2 flavors and when building, the error is this:
This issue is critical since we only need to perform 1 build instead of 2 or 3 (in the case of @niktses, 48).
Edit:
I'm using the "hack" of calling
--debugand--profileand only calling it for the current flavor.Edit 2:
I got it working using this combo:
android/app/build.gradle
android/build.gradle
*android/gradle/wrapper/gradle-wrapper.properties
CI/CD (config per flavor)
This config worked without any issue (yet). @niktses you could try using this if works for you. I haven't tried without using debug or profile.
Edit 3:
We can use the above configuration without this part:
CI/CD (config per flavor)
@niktses, you can use the above config omitting the previous part.
pedromassango commentedon Jul 14, 2021
If you don't want to mess with your CI/CD configs then just upgrade your Gradle version:
User Android Gradle
7.0.0-alpha14in yourandroid/build.gradle:And upgrade your Gradle version to
7.0-rc-1inandroid/gradle/wrapper/gradle-wrapper.properties:distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-rc-1-all.zipcomatory commentedon Jul 15, 2021
@pedromassango This did work for me, the approaches from above did not work for me at all. I'm on Flutter
2.2.2.I don't feel comfortable using
alphaandrcversions though and I'm not sure why this issue is closed since this happens still.My project did not start with flavors, I added them later.
flutter doctoroutput is:pedromassango commentedon Jul 15, 2021
It is closed because this is not a Flutter issue but an Android project issue.
github-actions commentedon Jul 30, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.