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
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.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
flutter create new_project
cd new_project
rm -rf lib
mv ../old_project/lib lib
android/gradle/wrapper/gradle-wrapper.properties
in some other editor than VSC and changedistributionUrl
todistributionUrl=https://services.gradle.org/distributions/gradle-8.3-bin.zip
flutter pub add <list of packages>
flutter build apk
– instead you could probably build it from VSCHope this helps