Skip to content

flutter build apk fails on an app using Android Gradle plugin 4.0 #58247

Description

@MaikuB

Canonical Issue

https://issuetracker.google.com/issues/141126614

Steps to Reproduce

  1. Run flutter create counter
  2. Update the app to use Android Gradle plugin 4.0.0
  3. 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

Activity

  1. Zazo032 commented on May 29, 2020

    @Zazo032
    Contributor

    Building apk also crashes for me. However, building appbundle works.
    Running with --release also crashes, but if you run --debug and then --release, it does seem to work (weird one). After succesfully running with --release, you'll be able to build apk.

  2. jason-simmons commented on May 30, 2020

    @jason-simmons
    Member

    The Android Gradle LintPerVariantTask now appears to be adding JARs from all build variants to its inputs:
    https://android.googlesource.com/platform/tools/base/+/1f9787310d64a66370627a2aaefa1e616565c17d

    The libapp.so libraries 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 lintOptions in app/build.gradle to disable the lint task:

    lintOptions {
        checkReleaseBuilds false
    }
    

    @blasten

  3. newbieflutter commented on May 31, 2020

    @newbieflutter

    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 ?

  4. sgehrman commented on May 31, 2020

    @sgehrman
  5. Malik056 commented on May 31, 2020

    @Malik056

    Same here. Recently updated android studio, android sdk, gradle and flutter, And I no longer able to build release apk

  6. newbieflutter commented on May 31, 2020

    @newbieflutter

    Hi,
    Looks like this is a big issue then. I upgrade all too. Any one found any solution?

  7. Jwiggiff commented on May 31, 2020

    @Jwiggiff

    I wouldn't consider this a solution, but I've found a workaround. I was having the same issue and tried building --debug and then --release and it still didn't work. However, if you look at the path in your specific error, it should either end with debug/libs.jar or profile/libs.jar. This indicates which apk you need to build first. In OP's case it is debug/libs.jar so building --debug first and then --release worked. In my case, it was profile/libs.jar so building --profile and then --release worked. I'm pretty sure building the --release shouldn't have to access the debug or profile directories though.

    TL;DR
    If your error says debug/libs.jar, build --debug then --release.
    If your error says profile/libs.jar, build --profile then --release.

  8. Malik056 commented on May 31, 2020

    @Malik056

    I downgraded the android gradle and gradle version, from Android studio Project Structure. And Clean build my project. now it is working.

  9. amelnikov78 commented on Jun 1, 2020

    @amelnikov78

    @Jwiggiff

    TL;DR
    If your error says debug/libs.jar, build --debug then --release.
    If your error says profile/libs.jar, build --profile then --release.

    That works, thanks!

  10. added
    customer: crowdAffects or could affect many people, though not necessarily a specific customer.
    platform-androidAndroid applications specifically
    c: crashStack traces logged to the console
    t: gradle"flutter build" and "flutter run" on Android
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Jun 1, 2020
  11. 130 remaining items

  12. niktses commented on May 6, 2021

    @niktses

    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?

  13. zanderso commented on May 6, 2021

    @zanderso
    Member

    @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!

  14. niktses commented on May 7, 2021

    @niktses

    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.

  15. pedromassangocode commented on May 7, 2021

    @pedromassangocode

    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

  16. niktses commented on May 7, 2021

    @niktses

    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.

  17. zanderso commented on May 7, 2021

    @zanderso
    Member

    @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!

  18. niktses commented on May 8, 2021

    @niktses

    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.

  19. rundun commented on May 10, 2021

    @rundun

    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 :

    /home/gotama/Documents/test_project/android/gradlew -Pverbose=true -Ptarget-platform=android-x86
    -Ptarget=/home/gotama/Documents/test_project/lib/main.dart
    -Pdart-defines=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ== -Pdart-obfuscation=false -Ptrack-widget-creation=true
    -Ptree-shake-icons=false -Pfilesystem-scheme=org-dartlang-root assembleDebug
    

    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.

  20. atleugim commented on Jun 7, 2021

    @atleugim

    @Jwiggiff

    TL;DR
    If your error says debug/libs.jar, build --debug then --release.
    If your error says profile/libs.jar, build --profile then --release.

    That works, thanks!

    This works, I had to do all 3 builds,
    first with the --debug flag and then --profile to finally compile in --release mode.

    THANKS

  21. elhe26 commented on Jul 8, 2021

    @elhe26

    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.

    Same issues. I have 2 flavors and when building, the error is this:

    * What went wrong:
    
    Execution failed for task ':app:lintVitalDevelopmentRelease'.
    
    > Could not resolve all artifacts for configuration ':app:productionReleaseRuntimeClasspath'.
    
       > 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/builder/clone/build/app/intermediates/flutter/productionRelease/libs.jar.
    
             > Transform's input file does not exist: /Users/builder/clone/build/app/intermediates/flutter/productionRelease/libs.jar. (See https://issuetracker.google.com/issues/158753935)
    

    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 --debug and --profile and only calling it for the current flavor.

    Edit 2:

    I got it working using this combo:

    android/app/build.gradle

    ...
    
    project.ext.envConfigFiles = [
            developmentdebug: ".env.development",
            developmentprofile: ".env.development",
            developmentrelease: ".env.development",
            productiondebug: ".env.production",
            productionprofile: ".env.production",
            productionrelease: ".env.production",
    ]
    
    ...
    
        // TODO: Temp measure - Add 'checkReleaseBuilds false' 
        lintOptions {
            disable 'InvalidPackage'
            checkReleaseBuilds false
        }
    ...

    android/build.gradle

         ...
         dependencies {
            classpath 'com.android.tools.build:gradle:4.1.2' // <-- using gradle +4.0 instead of downgrade
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
             ...
        }
    ...

    *android/gradle/wrapper/gradle-wrapper.properties

    ...
    distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

    CI/CD (config per flavor)

    # Build (Debug & profile)
    
    flutter build apk --debug --flavor <flavor>
    flutter build apk --profile --flavor <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)

    # Build (Debug & profile)
    
    flutter build apk --debug --flavor <flavor>
    flutter build apk --profile --flavor <flavor>

    @niktses, you can use the above config omitting the previous part.

  22. pedromassango commented on Jul 14, 2021

    @pedromassango
    Member

    If you don't want to mess with your CI/CD configs then just upgrade your Gradle version:

    User Android Gradle 7.0.0-alpha14 in your android/build.gradle:

    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0-alpha14'
    }
    

    And upgrade your Gradle version to 7.0-rc-1 in android/gradle/wrapper/gradle-wrapper.properties:
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-rc-1-all.zip

  23. comatory commented on Jul 15, 2021

    @comatory

    If you don't want to mess with your CI/CD configs then just upgrade your Gradle version:

    User Android Gradle 7.0.0-alpha14 in your android/build.gradle:

    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0-alpha14'
    }
    

    And upgrade your Gradle version to 7.0-rc-1 in android/gradle/wrapper/gradle-wrapper.properties:
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-rc-1-all.zip

    @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 alpha and rc versions 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 doctor output is:

    [✓] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-x64, locale en-CZ)
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    [✓] Xcode - develop for iOS and macOS
    [✓] Chrome - develop for the web
    [✓] Android Studio (version 4.2)
    [✓] IntelliJ IDEA Community Edition (version 2020.2.1)
    [✓] VS Code (version 1.54.3)
    [✓] Connected device (2 available)
    
    • No issues found!
    
  24. pedromassango commented on Jul 15, 2021

    @pedromassango
    Member

    If you don't want to mess with your CI/CD configs then just upgrade your Gradle version:

    User Android Gradle 7.0.0-alpha14 in your android/build.gradle:

    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0-alpha14'
    }
    

    And upgrade your Gradle version to 7.0-rc-1 in android/gradle/wrapper/gradle-wrapper.properties:
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-rc-1-all.zip

    @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 alpha and rc versions 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 doctor output is:

    [✓] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-x64, locale en-CZ)
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    [✓] Xcode - develop for iOS and macOS
    [✓] Chrome - develop for the web
    [✓] Android Studio (version 4.2)
    [✓] IntelliJ IDEA Community Edition (version 2020.2.1)
    [✓] VS Code (version 1.54.3)
    [✓] Connected device (2 available)
    
    • No issues found!
    

    It is closed because this is not a Flutter issue but an Android project issue.

  25. github-actions commented on Jul 30, 2021

    @github-actions

    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 -v and a minimal reproduction of the issue.

  26. locked as resolved and limited conversation to collaborators on Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listc: crashStack traces logged to the consolec: regressionIt was better in the past than it is nowcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.dependency: androidAndroid team may need to help usfound in release: 1.21Found to occur in 1.21has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyt: gradle"flutter build" and "flutter run" on AndroidtoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions