Home > Net >  Flutter: Gradle build failed to produce an .apk file. It's likely that this file was generated
Flutter: Gradle build failed to produce an .apk file. It's likely that this file was generated

Time:10-27

We are building flutter application with some native modules. Historically we used flutter as a module for some crossplatform deployments but finally we decided to make it flutter first.

Everything seemed to work as expected until we've came to this error:

Gradle build failed to produce an .apk file. It's likely that this file was generated under C:\Users\user\folder\project\flutter_modules\build but the tool couldn't find it.

There is a working apk generated under C:\Users\user\folder\project\flutter_modules\build\app\outputs\apk\debug but we cannot find a way to setup gradle to find it.

We've tried many recommended fixes such as specifying app flavors, adding splits, updating flutter and gradle but nothing worked. Is there something that we are missing?

Is there any way to specify in which folder gradle should search for generated apk?

We know that if we run flutter run --use-application-binary flutter_modules/build/outputs/apk/debug/app-debug.apk it installs it but doesnt build it before installing. But we can't find a way to build it and install it by using flutter run or by pressing run in Android Atudio.

Did anyone encounter same situation? Is there anything we can do except for building it, letting it fail to find the apk and installing it manually?

CodePudding user response:

After few days of debugging we decided to move generated .apk to where build system expect it after build. In other words we added this to app-level build.gradle.

applicationVariants.all { variant ->
    variant.assemble.doLast {
        copy {
            from '../../build/app/outputs/apk/debug/app-debug.apk'
            into '../../build/host/outputs/apk'
        }
    }
}

Also make sure that this is in project-level build.gradle.

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
  • Related