skip to Main Content

I am trying to build a Flutter app. This is the error resulting from the logs

FAILURE: Build failed with an exception.

* Where:
Build file 'C:UsersfrancDocumentsGithubxandroidbuild.gradle' line: 26

* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
   > Could not create an instance of type com.android.build.api.variant.impl.ApplicationVariantImpl.
      > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.

        If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.

* 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 1s
Exception: Gradle task assembleDebug failed with exit code 1

Here is the android build.gradle file

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        jcenter()
    }

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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

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

I really don’t know how to proceed.

I’ve tried the "AGP Upgrade Assistant button on the "Tools" window on Android Studio but it doesn’t seem to do anything.

I tried building the app, changing the ":app" part on Gradle to the project name and it didn’t work.

2

Answers


  1. This has happened a few times to me while using Visual Studio Code to build my app.

    For some reason, sometimes the build creates an unrecoverable state of the files.

    Possible solution 1:

    Sometimes just running flutter clean solves the problem.

    Possible solution 2:

    If you use Visual Studio Code, closing and reopening the application might solve some build problem.

    Possible solution 3:

    On a few occasions, I was forced to delete the .dart_tool folder within the project.

    Just make sure that after deleting the folder, you run on the terminal flutter pub get to get all of your dependencies before running the build.

    Login or Signup to reply.
  2. To me cleaning project with flutter clean (as @canilho wrote) and cleaning Gradle ($HOME/.gradle) and Flutter ($HOME/.pub-cache) cache didn’t help.
    I’ve created new project, migrated code from old one, upgraded Gradle wrapper and added Flutter packages. All of this I’ve done without opening new project in VS Code to ensure nothing is changed without my consent.

    This is for Linux/MacOS, but I think you’ll get it

    1. create new project flutter create new_project
    2. go into new directory cd new_project
    3. remove lib directory rm -rf lib
    4. copy lib directory from old project mv ../old_project/lib lib
    5. edit android/gradle/wrapper/gradle-wrapper.properties in some other editor than VSC and change distributionUrl to distributionUrl=https://services.gradle.org/distributions/gradle-8.3-bin.zip
    6. add packages flutter pub add <list of packages>
    7. build apk image flutter build apk – instead you could probably build it from VSC

    Hope this helps

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search