Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle build failed to produce an .apk file. It's likely that this file was generated under D:\Flutter_App\MYAPP\build, but the tool couldn't find it. #44796

Closed
kimweichew opened this issue Nov 13, 2019 · 124 comments · Fixed by #54328
Labels
customer: crowd Affects or could affect many people, though not necessarily a specific customer. platform-android Android applications specifically t: gradle "flutter build" and "flutter run" on Android tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@kimweichew
Copy link

My flutter app not able to start after upgrade flutter version.

Gradle build failed to produce an .apk file. It's likely that this file was generated under D:\Flutter_App\team37\build, but the tool couldn't find it.
Exited (sigterm)

[√] Flutter (Channel dev, v1.10.16, on Microsoft Windows [Version 10.0.17763.805], locale en-US)
• Flutter version 1.10.16 at C:\src\flutter
• Framework revision 798e427 (6 days ago), 2019-11-06 21:04:17 -0500
• Engine revision 34a40cf
• Dart version 2.7.0

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at C:\Users\User\AppData\Local\Android\Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 28.0.3
• ANDROID_HOME = C:\Users\User\AppData\Local\Android\Sdk
• Java binary at: C:\Program Files\Android\Android Studio1\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 3.4)
• Android Studio at C:\Program Files\Android\Android Studio1
• Flutter plugin version 38.2.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[√] VS Code (version 1.40.0)
• VS Code at C:\Users\User\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.6.0

@kimweichew
Copy link
Author

i have to recreate a new project and import back the file

@waltrump
Copy link

same issue i m also facing after i update flutter yesterday..

The plugin fluttertoast is built using an older version of the Android plugin API which assumes that it's running in a full-Flutter environment. It may have undefined behaviors when Flutter is integrated into an existing app as a module.
The plugin can be updated to the v2 Android Plugin APIs by following https://flutter.dev/go/android-plugin-migration.
Launching lib\main.dart on Android SDK built for x86 in debug mode...
[!] Your app isn't using AndroidX.
To avoid potential build failures, you can quickly migrate your app by following the steps on https://goo.gl/CP92wY.
Running Gradle task 'assembleDebug'...
Finished with error: Gradle build failed to produce an .apk file. It's likely that this file was generated under D:\MyProject\build, but the tool couldn't find it.

is there any solution, why is this?

@ThomasValois

This comment has been minimized.

@chanmyaethu-mn

This comment has been minimized.

@ThomasValois
Copy link

Please can this be re-opened? I have completely removed my pubspec.yaml dependencies and still getting this error message. I don't think this is package related but more Flutter related.

@sujithTSR
Copy link

Yeah.!
Even I wonder why this is happening in the master channel as well.
I am able to see the generated apks in the build/app/outputs/apk/flavor-name/release-type/*.apk

@ArtfulDodgerB92
Copy link

Can you guys seriously sort yourselves out? Honestly, I have never run into so many problems with an SDK before, it is utterly ridiculous and makes you look terrible at your jobs.

I cannot run the "stable" branch because the SDK in that branch builds an appbundle that behaves completely differently to the running app, so that the version on my devices is perfect, and the version on the store is broken. (This is a known issue, where you morons suggest moving to the master branch as the resolution for this).

I can now not run the master branch either because I have the exact issue as everyone else in this thread.

Seriously guys, why are you so bad at this? How can you continue to get it so wrong? There are problems with Flutter literally every month. Every single month we have to spend weeks undoing a mess you guys have made because you have broken something.

Absolute amateurs.

@ThomasValois
Copy link

I agree with @ArtfulDodgerB92. On one hand I absolutely love the Flutter framework and Dart language but the fact that I can easily spend 40% of my time every week troubleshooting environment issues it gets very boring very quickly. I'd like this issue to stay opened or moved if possible because I don't understand how my app is working then I get back from holiday and it's broken again 🤷‍♂️

@ArtfulDodgerB92
Copy link

When ThomasValois says 40% this is no exaggeration either guys. I literally spend most of my development time trying to work around failures in a broken environment. I am a coder that spends less than half his time actually coding. No other platform has been anything like this. In fact, I have never had the environment ruin my app before coming to flutter and now it is actually constant.

@DyaryRaoof

This comment has been minimized.

@jp1017
Copy link

jp1017 commented Dec 12, 2019

same issue with flutter sdk v1.12.13+hotfix.6

@softmarshmallow
Copy link

Still having same issue. for to run the app, i can via pure android. but no debugging & hotreloading etc..

@golanir
Copy link

golanir commented Dec 16, 2019

got it in the last update - Flutter 1.13.3-pre.23 • channel master, working with firebase vision

@lordzyx

This comment has been minimized.

@jj-hoeksema

This comment has been minimized.

@nmboyle

This comment has been minimized.

@softmarshmallow

This comment has been minimized.

@nandychu

This comment has been minimized.

@ashkryab

This comment has been minimized.

1 similar comment
@Dangtrungphu

This comment has been minimized.

@ThomasValois
Copy link

I'm amazed that this ticket hasn't been re-opened. This is such a crippling error for someone who just wants to get on with developing and not troubleshooting. One point to make personally is that I've noticed that creating a new VM seems to fix the issue for me flutter emulators --create but I'd still rather not have to create 4 VMs a day!

@hyystudy
Copy link

hyystudy commented Dec 20, 2019

I have this issue because I change some settings in build.gradle, Now I edit it then that issue not happened

@Sepehr13

This comment has been minimized.

@sbd2
Copy link

sbd2 commented Dec 22, 2019

Managed to make it work by downgrading to stable 1.9.1+hotfix.6

Relevant link

@jj-hoeksema
Copy link

jj-hoeksema commented Dec 22, 2019 via email

@yashvenrakumar

This comment has been minimized.

@nguyenhuutinh
Copy link

nguyenhuutinh commented Dec 23, 2019

looks like you added multi flavors. try --flavor 'flavor name'

@nbwithlb

This comment has been minimized.

@BytesZero
Copy link

My solution

  • Edit Configurations

image

  • Add Build flavor

image

@tcking
Copy link

tcking commented Apr 10, 2020

background:
flutter is add to exits app,the app enable splits apks and multiple flavors

1.with flutter v1.9.1+hotfix.6

  1. disable splits
splits {
        abi {
            enable false  //disable when run by flutter run
            reset()
            include SUPPORT_ABI_LIST
            universalApk true
        }
    }
  1. add --flavor flavorName parameter

with flutter 1.9.1 , after this two steps ,flutter run --flavor flavorName works fine.

2.with flutter v1.12.13+hotfix.9
no luck,disable splits and add --flavor parameter does not work.

the apks build in flutter_dir/android/app/build/outputs/apk/${falovr}/${buildType}/app-${falovr}-${buildType}.apk
the console show the error

Gradle build failed to produce an .apk file. It's likely that this file was generated under /Users/xx/flutter_dir/build, but the tool couldn't find it.

@tcking
Copy link

tcking commented Apr 10, 2020

I have a solution with flutter v1.12, add this in host app's build.gradle

applicationVariants.all { variant ->
        variant.outputs.all {
            def assembleTaskName = "assemble${variant.name.capitalize()}"
            if (rootProject.childProjects['flutter']!=null && tasks.findByName(assembleTaskName)) {
                def linkAPKTask = tasks.create(name: "linkFlutterApk${variant.name.capitalize()}").doLast {
                    //soft link apk to flutter module build dir build/host
                    ant.symlink(resource: new File(rootProject.projectDir.path+'/app/build'), link: new File(rootProject.childProjects['flutter'].projectDir.parentFile.parent+'/build/host'))
                }
                tasks[assembleTaskName].finalizedBy = [linkAPKTask]
            }
        }
    }

@ArtfulDodgerB92
Copy link

I managed to make it work after commenting out the flavors in app/build.gradle

    // productFlavors {
    //     debug {
    //         dimension "default"
    //         applicationIdSuffix ".debug"
    //     }
    //     staging {
    //         dimension "default"
    //         applicationIdSuffix ".staging"
    //     }
    //     prod {
    //         dimension "default"
    //     }
    // }

The output was rightfully built in build/app/outputs/apk/debug/app-debug.apk.

Of course I'm not commiting these to source control. It's just until there isn't a fix.

Not a definitive solution, but at least I can work.

I have no flavours at all in my build.gradle. This may be 'a' cause of this issue, but it is not 'the' cause. We really need a fix on the all the critical stability issues for this platform.

@Im-Kevin

This comment has been minimized.

@HassanAthmani
Copy link

HassanAthmani commented May 30, 2020

I had the same problem. I'm using Windows 7.
I updated my PowerShell to version 5.1 and downloaded the new flutter stable version 1.17
Then within PowerShell after setting flutter/bin to PATH I ran

flutter config --android-sdk C:\Users\User\AppData\Local\Android\Sdk
(setting the location of my android sdk within flutter config)

N.B.: I am using PowerShell as my default terminal.

@JStevens127
Copy link

I was able to build the signed bundle with:

flutter build appbundle -t lib/main.dart --flavor <flavor>

@Laxman-Kumar
Copy link

I think the problem is due to the broken path in plugins
Goto File - > Project Structure -> and look for errors (last option on the left side)
Try to fix the broken path

Another solution which worked for me is
Try creating a new project with androidX and move the files to the new project.

@Fatimamostafa
Copy link

My solution

  • Edit Configurations

image

  • Add Build flavor

image

Worked for me!

@timolehto
Copy link

timolehto commented Jul 9, 2020

This has become a junkyard of reposts about various ways to specify the flavor.. Yeah you need to specify the flavor if you're using flavors. I wonder if we could have some up-front validation to check that flavor is set before doing anything with a flavorful setup and give a more informative error message than just "apk could not be found" e.g. "You have flavors configured, but you did not specify which flavor to build".. which leads all of these poor ppl googling their way to here and trash this issue with completely unrelated chatter about how you configure the flavor in various IDEs, editors or command line...

@Blankeer
Copy link

Solution:

applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "${project.archivesBaseName}-${variant.productFlavors.name.join()}-${variant.buildType.name}.apk"
        }
    }
flutter run -t lib/main_dev.dart --flavor test

@smac89
Copy link

smac89 commented Aug 1, 2020

I was getting this error because I had defined the splits configuration inside my build.gradle, so that I can build for multiple architectures.

I guess flutter gets confused when there are multiple generated apks, so it does not know which one to use for the device. Removing the configuration and doing a ./gradlew clean inside the android folder, then running again in Android Studio, fixed the issue for me.

@sochychoeun
Copy link

I was able to build the signed bundle with:

flutter build appbundle -t lib/main.dart --flavor <flavor>

This is working find for me when I configure deference Flavor

@Flucadetena
Copy link

My solution

  • Edit Configurations

image

  • Add Build flavor

image

Worked for me!

This worked for me perfectly, I configured the same flavors I had in VsCode and no problem anymore. If anyone has any question how to do this, just mention me ;)

@jerryzhoujw
Copy link

My solution

  • Edit Configurations

image

  • Add Build flavor

image

Do you know how to do this in vscode ?

@jerryzhoujw
Copy link

Ok, I found that it's args in launch.json if you use vscode

enter image description here

@maripbekoff
Copy link

I had the same problem. I solved it by renaming the apk file name. When I created Flavor, apk files were saved in lowercase when it should have been in Camel Case. This is why the build tool was unable to find this apk.

  1. Flavor's name
    Screenshot_20200827_213345

  2. How was it built
    Screenshot_20200827_213439

  3. Running the flavor: flutter run --flavor picturesWithQuotes -t lib/main-picturesWithQuotes.dart

Hope that will help someone)

@BenjiFarquhar
Copy link

looks like you added multi flavors. try --flavor 'flavor name'

Perfect thank you! My error was while running an integration test.

Adding the flavor fixed it: --flavor='flavor name'

full test command:

flutter drive
--driver=test_driver/integration_test_driver.dart
--target=integration_test/user_registration_entity_test.dart
--flavor=development

@duyhungtnn
Copy link

duyhungtnn commented Jan 23, 2021

Another solution is to check your pubspec.yaml for

  module:
    androidX: true
    androidPackage: com.example.app_x
    iosBundleIdentifier: com.example.appX

Just delete this configuration and it works fine.

Thank you , it work :)) @tomrozb

@cntoss
Copy link

cntoss commented Feb 5, 2021

in my case it was fixed by doing following command through terminal where staging is current flavor
flutter run --flavor staging -t lib/main_staging.dart

@tazik561
Copy link

tazik561 commented Mar 1, 2021

I just commnted debuggable true in buildTypes release

   buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            //debuggable true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.debug
        }
    }

And the problem gone :->

1 similar comment
@tazik561
Copy link

tazik561 commented Mar 1, 2021

I just commnted debuggable true in buildTypes release

   buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            //debuggable true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.debug
        }
    }

And the problem gone :->

@jcazalELPAKOMICHI
Copy link

Bueno espero que pueda ayudar, pero resulta ser que cuando tenemos varios flavors, debemos de especificar de que flavor queremos generar la apk release de nuestra aplicacion:

flutter build apk --release --flavor <your flavor> -t lib/<your main>.dart
Con esto generamos nuestra apk release.

@SungHyun22
Copy link

I was able to build the signed bundle with:

flutter build appbundle -t lib/main.dart --flavor <flavor>

This is working find for me when I configure deference Flavor

it's work for me :)

@github-actions
Copy link

github-actions bot commented Aug 4, 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 -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
customer: crowd Affects or could affect many people, though not necessarily a specific customer. platform-android Android applications specifically t: gradle "flutter build" and "flutter run" on Android tool Affects the "flutter" command-line tool. See also t: labels.
Projects
Tools - Gradle review
  
Engineer reviewed
Development

Successfully merging a pull request may close this issue.