Skip to content

[add-to-app] error : Namespace not specified. Please specify a namespace in the module's build.gradle #126403

Description

@LazyDave76

Is there an existing issue for this?

Steps to reproduce

Create a new android app and add a new flutter module to it using steps in option 2 : https://docs.flutter.dev/add-to-app/android/project-setup

run 'flutter pub get' in module to build .android folder

sync project in android studio

Expected results

build is successful

Actual results

app fails to build.

Android studio is looking for 'namespace' setting in .android/build.gradle. adding a value manually makes the app build but this is a generated .android folder so any further runs of 'flutter pub get' to update dependencies remove any edits.

Error happens with 3.7.12-stable and 3.10.0-1.5.pre-beta

error output:


* What went wrong:
A problem occurred configuring root project 'Android'.
> A problem occurred configuring project ':flutter'.
   > 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.

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

### Code sample

<details><summary>Code sample</summary>

```dart
[Paste your code here]

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.7.12, on macOS 13.2 22D49 darwin-arm64, locale en-GB)
    • Flutter version 3.7.12 on channel stable at /Users/xxxx/.asdf/installs/flutter/3.7.12-stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4d9e56e694 (3 weeks ago), 2023-04-17 21:47:46 -0400
    • Engine revision 1a65d409c7
    • Dart version 2.19.6
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/xxxx/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.78.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.62.0

[✓] Connected device (3 available)
    • iPhone 14 Pro (mobile) • D4CEE1AF-4892-48B9-A9D2-80C1D5F6175A • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 13.2 22D49 darwin-arm64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 112.0.5615.137

[✓] HTTP Host Availability
    • All required HTTP hosts are available```

</details>

Activity

  1. added
    in triagePresently being triaged by the triage team
    on May 10, 2023
  2. huycozy commented on May 10, 2023

    @huycozy
  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on May 10, 2023
  4. huycozy commented on May 10, 2023

    @huycozy
    Member

    It seems you are using AGP and Gradle version from 8.0 because I can see this issue when upgrading AGP to 8.0.0 and Gradle to 8.0. Meanwhile, the worked version is AGP 7.2.0/Gradle 7.3.3.

    This issue is reproducible on the latest stable and master channels. Labeling the issue for further insights.

    Sample code: namespace-gradle-issue

    flutter doctor -v (stable and master)
    [✓] Flutter (Channel stable, 3.7.12, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
        • Flutter version 3.7.12 on channel stable at /Users/huynq/Documents/GitHub/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 4d9e56e694 (2 days ago), 2023-04-17 21:47:46 -0400
        • Engine revision 1a65d409c7
        • Dart version 2.19.6
        • DevTools version 2.20.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-33, build-tools 32.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14E222b
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.1)
        • Android Studio at /Applications/Android Studio.app/Contents
        • 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 11.0.15+0-b2043.56-8887301)
    
    [✓] IntelliJ IDEA Community Edition (version 2022.1.1)
        • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
        • 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
    
    [✓] VS Code (version 1.77.3)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.62.0
    
    [✓] Connected device (3 available)
        • SM T225 (mobile) • R9JT3004VRJ • android-arm64  • Android 13 (API 33)
        • macOS (desktop)  • macos       • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
        • Chrome (web)     • chrome      • web-javascript • Google Chrome 112.0.5615.137
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    [!] Flutter (Channel master, 3.11.0-2.0.pre.73, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
        • Flutter version 3.11.0-2.0.pre.73 on channel master at /Users/huynq/Documents/GitHub/flutter_master
        ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 8c5a1ea728 (7 hours ago), 2023-05-08 14:00:20 -0700
        • Engine revision 8d3a8162b3
        • Dart version 3.1.0 (build 3.1.0-86.0.dev)
        • DevTools version 2.23.1
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-33, build-tools 32.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14E222b
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • 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.6+0-17.0.6b802.4-9586694)
    
    [✓] VS Code (version 1.78.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.62.0
    
    [✓] Connected device (2 available)
        • macOS (desktop) • macos  • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
        • Chrome (web)    • chrome • web-javascript • Google Chrome 112.0.5615.137
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
  5. added
    platform-androidAndroid applications specifically
    toolAffects the "flutter" command-line tool. See also t: labels.
    a: existing-appsIntegration with existing apps via the add-to-app flow
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    in triagePresently being triaged by the triage team
    on May 10, 2023
  6. reidbaker commented on May 10, 2023

    @reidbaker
    Contributor

    Related to #125621
    I think this will be fixed by #126354.

  7. added
    P1High-priority issues at the top of the work list
    on May 10, 2023
  8. 22 remaining items

  9. strongville commented on Jun 7, 2023

    @strongville

    Sorry for commenting on a closed issue, but this still seems not included in stable version.

    changelog for Flutter 3.10.4

    The changelog for Flutter 3.10.4 mentions this as an included hotfix, but the error stated above still applies on this version, even when deleting manually the .android folder and running pub get again.

  10. camsim99 commented on Jun 8, 2023

    @camsim99
    Contributor

    Sorry for commenting on a closed issue, but this still seems not included in stable version.

    changelog for Flutter 3.10.4

    The changelog for Flutter 3.10.4 mentions this as an included hotfix, but the error stated above still applies on this version, even when deleting manually the .android folder and running pub get again.

    I believe this is true and the fix is not part of Flutter 3.10.4. Sorry about the confusion!

  11. removed
    r: fixedIssue is closed as already fixed in a newer version
    on Jun 9, 2023
  12. MrCsabaToth commented on Jun 12, 2023

    @MrCsabaToth

    I was able to reproduce the issue and thanks to the reproduction example above and @reidbaker's suggestion to try the AGP upgrade assistant in Android Studio. I can confirm we need to add namespace to all of the build.gradle files in the module and in the build.gradle file for the app itself.

    I'm battling with this, I have a Flutter app. The upgrade agent / scripts removed the namespace from the manifest and added it to the app's build.gradle. The "namespace" is also present in the same build.gradle under the android > defaultConfig > applicationId. What module are we talking about? My app is not complicated but I count 18 modules, which are effectively Flutter plugins I depend on which that native Android parts. I'm afraid to ask (or even think about it) but am I supposed to interfere and fiddle with those 18 build.gradle files of those plugins to make this error go away?

    All of the StackOverflow entries I found so far are garbage, I suspected my case would be quite common. People advise to simply remove the namespace (going against the error message) and similar things.

  13. camsim99 commented on Jun 12, 2023

    @camsim99
    Contributor

    I'm battling with this, I have a Flutter app. The upgrade agent / scripts removed the namespace from the manifest and added it to the app's build.gradle. The "namespace" is also present in the same build.gradle under the android > defaultConfig > applicationId. What module are we talking about? My app is not complicated but I count 18 modules, which are effectively Flutter plugins I depend on which that native Android parts. I'm afraid to ask (or even think about it) but am I supposed to interfere and fiddle with those 18 build.gradle files of those plugins to make this error go away?

    All of the StackOverflow entries I found so far are garbage, I suspected my case would be quite common. People advise to simply remove the namespace (going against the error message) and similar things.

    In Flutter modules, you need to ensure that .andriod/build.gradle, .android/app/build.gradle, and .android/Flutter/build.gradle files have the namespace property in the android block to get rid of the error. I'm not sure if your Flutter plugins are part of the issue. Plugin templates should have received a similar fix in #126354 as plugins also need the property in the android block in their build.gradle file for AGP 8 compatibility.

  14. camsim99 commented on Jun 12, 2023

    @camsim99
    Contributor

    Closing this issue as this is fixed in master. #128136 filed for the cherry-pick to stable.

  15. AnhDTN commented on Jun 14, 2023

    @AnhDTN

    @camsim99 i was checkout master branch and still got the same error

  16. MrCsabaToth commented on Jun 14, 2023

    @MrCsabaToth

    In Flutter modules, you need to ensure that .andriod/build.gradle, .android/app/build.gradle, and .android/Flutter/build.gradle files have the namespace property in the android block to get rid of the error. I'm not sure if your Flutter plugins are part of the issue. Plugin templates should have received a similar fix in #126354 as plugins also need the property in the android block in their build.gradle file for AGP 8 compatibility.

    Maybe this is off-topic because I landed here mostly as an app developer. I don't have a .android/Flutter/build.gradle file. namespace in .andriod/build.gradle is relevant for plugins only I think, so whoever is an app developer (not plugin), the .android/app/build.gradle will be the valid place for namespace and the AGP update scripts already supplement that.

    In my case when the error complains about modules it is about some subset of plugins which lack the namespace. The main issue could be that looking at the error from a mile in Android Studio it is generic and does not tell if it's about the app itself or a plugin, and which plugin exactly. Only when looking at details turns out that it's about some plugins.

    Community plugins and SDK plugins have now conditional namespace in the build.gradle (in the form of if (project.android.hasProperty("namespace")) { namespace ... }) however some of these might not be available if the plugin is prevented to be at the required version due to other plugins' transitive dependencies holding them back (such as constraint about the http package being 0.13 vs 1.0, package_info_plus, device_info_plus).

    App developers might land here. Newer Android studio will advise them of the AGP 8.0+ upgrade. Once they go through with it some lagging plugins which drag their feet could hold their whole project back. This ("outside" lagging plugins) is out of jurisdiction of the SDK and the community plugins repositories, but I just document this here because it could be an issue overall.

    Just a few examples:

  17. camsim99 commented on Jun 16, 2023

    @camsim99
    Contributor

    @MrCsabaToth Thank you for in-depth explanation! You make a great point about developers discovering this issue in ways not directly related to using Flutter in an add-to-app context.

    If you would be open to it, we would be greatly appreciative for you to answer questions about this with essentially your explanation above if you run into them so that developers can see the solution more clearly. For example:

  18. camsim99 commented on Jun 16, 2023

    @camsim99
    Contributor

    @camsim99 i was checkout master branch and still got the same error

    This is a fix for the build.gradle templates. You may need to re-create your Flutter modules if you still see the issue. If you are not using Flutter in an add-to-app context, see @MrCsabaToth's explanation above!

  19. github-actions commented on Jun 30, 2023

    @github-actions

    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.

  20. locked as resolved and limited conversation to collaborators on Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work lista: existing-appsIntegration with existing apps via the add-to-app flowfound in release: 3.11Found to occur in 3.11found in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallytoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions