Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
LazyDave76 opened this issue May 10, 2023 · 26 comments · Fixed by #126963 or #128360
Closed
2 tasks done
Assignees
Labels
a: existing-apps Integration with existing apps via the add-to-app flow found in release: 3.7 Found to occur in 3.7 found in release: 3.11 Found to occur in 3.11 has reproducible steps The issue has been confirmed reproducible and is ready to work on P1 High-priority issues at the top of the work list platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@LazyDave76
Copy link

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>
@huycozy huycozy added the in triage Presently being triaged by the triage team label May 10, 2023
@huycozy

This comment was marked as outdated.

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 10, 2023
@huycozy
Copy link
Member

huycozy commented May 10, 2023

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.

@huycozy huycozy added platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. a: existing-apps Integration with existing apps via the add-to-app flow has reproducible steps The issue has been confirmed reproducible and is ready to work on found in release: 3.7 Found to occur in 3.7 found in release: 3.11 Found to occur in 3.11 and removed waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds in triage Presently being triaged by the triage team labels May 10, 2023
@reidbaker
Copy link
Contributor

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

@reidbaker reidbaker added the P1 High-priority issues at the top of the work list label May 10, 2023
@reidbaker
Copy link
Contributor

With master checked out I was able to run

flutter create --project-name=test_app --template=module .
flutter build apk 

And the apk successfully built.

Next I will try on stable.

@reidbaker
Copy link
Contributor

Using the tag 3.10.0-15.0.pre which I think is the latest stable I see the same behavior as master.

mkdir fresh_create
flutter create --project-name=test_app --template=module fresh_create
cd fresh_create
flutter build apk

@stuartmorgan
Copy link
Contributor

You'd need to add the module to a non-Flutter-template app that's using AGP 8.0, if I'm understanding the issue correctly.

@reidbaker
Copy link
Contributor

Other things that probably should be fixed at the same time.

  • Compile/target sdk should be set to api 33
  • settings.gradle.copy.tmpl have evaluate(new File(settingsDir, 'include_flutter.groovy')) which I think wont work with the move of our gradle files
  • Min sdk version should be set to 19 (instead of 16)
  • android:exported="true" in manifest files

@reidbaker
Copy link
Contributor

🤦 there is an example. I will work off that

@reidbaker
Copy link
Contributor

To reproudce failure

@reidbaker
Copy link
Contributor

Additional steps discovered

Modify settings.gradle to include the path to your own dependencies (follow output from flutter build arr)
Fix the host app to have a namespace (this is out of our control) namespace 'com.example.addtoapp_androidnative'

@reidbaker reidbaker assigned camsim99 and unassigned stuartmorgan and reidbaker May 15, 2023
@reidbaker
Copy link
Contributor

Handing over to @camsim99 to keep this moving forward.

@camsim99
Copy link
Contributor

camsim99 commented May 16, 2023

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 believe I'll need to update the following:

I'll work on verifying this and submitting a PR for the fix. I also will find a good place to add a note on the website in case folks run into this issue if anyone knows a good page offhand!

@camsim99
Copy link
Contributor

I'll work on verifying this and submitting a PR for the fix. I also will find a good place to add a note on the website in case folks run into this issue if anyone knows a good page offhand!

Verified that modifying those works, so submitting PRs.

auto-submit bot pushed a commit that referenced this issue May 23, 2023
Adds `namespace` to module `build.gradle` file templates.

Fixes #126403.
@huycozy huycozy added the r: fixed Issue is closed as already fixed in a newer version label May 24, 2023
CaseyHillers pushed a commit to CaseyHillers/flutter that referenced this issue May 24, 2023
…6963)

Adds `namespace` to module `build.gradle` file templates.

Fixes flutter#126403.
@milindgoel15
Copy link

Is this fix for the namespace error pushed to stable?

@reidbaker
Copy link
Contributor

@camsim99 can you follow up on this with cherry picks to beta/stable if this change is not in either?

camsim99 added a commit to camsim99/flutter that referenced this issue Jun 6, 2023
…6963)

Adds `namespace` to module `build.gradle` file templates.

Fixes flutter#126403.
@strongville
Copy link

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.

@camsim99
Copy link
Contributor

camsim99 commented Jun 8, 2023

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!

@Jasguerrero Jasguerrero reopened this Jun 8, 2023
@huycozy huycozy removed the r: fixed Issue is closed as already fixed in a newer version label Jun 9, 2023
@MrCsabaToth
Copy link

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.

@camsim99
Copy link
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.

@camsim99
Copy link
Contributor

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

@AnhDTN
Copy link

AnhDTN commented Jun 14, 2023

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

@MrCsabaToth
Copy link

MrCsabaToth commented Jun 14, 2023

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:

@camsim99
Copy link
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:

@camsim99
Copy link
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!

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: existing-apps Integration with existing apps via the add-to-app flow found in release: 3.7 Found to occur in 3.7 found in release: 3.11 Found to occur in 3.11 has reproducible steps The issue has been confirmed reproducible and is ready to work on P1 High-priority issues at the top of the work list platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
10 participants