while installing any third-party package in Flutter and try to run my code it always to go an error that there is no namespace found in build gradle file
for an example this one
A problem occurred configuring project ':google_mlkit_commons'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
> Namespace not specified. Please specify a namespace in the module's build.gradle file like so:
android {
namespace 'com.example.namespace'
}
If the package attribute is specified in the source AndroidManifest.xml, it can be migrated automatically to the namespace value in the build.gradle file using the AGP Upgrade Assistant; please refer to https://developer.android.com/studio/build/agp-upgrade-assistant for more information.
so to solve it i should go to the mentioned package for example here is ':google_mlkit_commons' and go throw its android files and get the build gradle then adding its namespace in android tag for our example
android {
namespace "com.google_mlkit_text_recognition"
compileSdkVersion 31
....
}
my questions are 1- should I do this step for each package I want to use? 2- why get this error now? is it related to the new flutter version?
flutter doctor -v
[√] Flutter (Channel stable, 3.16.5, on Microsoft Windows [Version 10.0.19045.3930], locale en-US)
• Flutter version 3.16.5 on channel stable at C:\Users\engma\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 78666c8dc5 (4 weeks ago), 2023-12-19 16:14:14 -0800
• Engine revision 3f3e560236
• Dart version 3.2.3
• DevTools version 2.28.4
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at C:\Users\engma\AppData\Local\Android\sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
• Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[X] Visual Studio - develop Windows apps
X Visual Studio not installed; this is necessary to develop Windows apps.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2023.1)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
[√] VS Code (version 1.85.1)
• VS Code at C:\Users\engma\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.80.0
[√] Connected device (4 available)
• DRA LX2 (mobile) • 5LX9K18817915788 • android-arm64 • Android 8.1.0 (API 27)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19045.3930]
• Chrome (web) • chrome • web-javascript • Google Chrome 120.0.6099.217
• Edge (web) • edge • web-javascript • Microsoft Edge 120.0.2210.133
[√] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category.
In newer versions of the Android Gradle Plugin and Gradle, the namespace was shifted from the AndroidManifest.xml to app/build.gradle. Generally, this means the following:
In all three AndroidManifest.xml files (main, debug, profile), remove the package attribute:
<!-- This is how it should look like: -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- YOUR CONTENT HERE -->
</manifest>
In app/build.gradle, add this line:
android {
namespace "com.example.yourpackage"
...
}
However, this requires all modules in your project to add the namespace. It seems like your package does not have this attribute yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With