31

According to this doc we no longer need to provide package name in AndroidManifest.xml and instead use namespace in build.gradle and there we can define our package name.

package="org.sample.domain" found in source AndroidManifest.xml: C:\Users\user\Desktop\Projects\Sample\app\libs\sample\src\main\AndroidManifest.xml.
Setting the namespace via a source AndroidManifest.xml's package attribute is deprecated.
Please instead set the namespace (or testNamespace) in the module's build.gradle file, as described here: https://developer.android.com/studio/build/configure-app-module#set-namespace
This migration can be done automatically using the AGP Upgrade Assistant, please refer to https://developer.android.com/studio/build/agp-upgrade-assistant for more information.

But upon doing it the Merged Manifest tab shows error stating that I am not providing a package name. I tried both at the same time but the warning build shows again.

enter image description here

Bitwise DEVS
  • 2,858
  • 4
  • 24
  • 67
  • On that doc there is no line stating that you can totally exclude package attribute from Manifest file. Your Merged Manifest package attribute might change depending upon namespace or applicationId but it does not state to remove package attribute all together. – nitinkumarp Apr 07 '22 at 03:35
  • @nitinkumarp if the package attribute is deprecated what is the replacement for it? – Bitwise DEVS Apr 07 '22 at 03:40
  • Please check this doc https://developer.android.com/guide/topics/manifest/manifest-element Its not deprecated. – nitinkumarp Apr 07 '22 at 03:46
  • @nitinkumarp yes but it's weird that Gradle build is complaining about it – Bitwise DEVS Apr 07 '22 at 03:52
  • Could you add that error here? – nitinkumarp Apr 07 '22 at 03:57
  • @nitinkumarp not an error but a log, the above log is the lint warning itself, it shows during build – Bitwise DEVS Apr 07 '22 at 03:58
  • @nitinkumarp From that doc: "In the Gradle-based build system, starting with AGP 7.3, don't set the package value in the source manifest file directly. For more information, see [Set the application ID](https://developer.android.com/build/configure-app-module#set-application-id)." – Ian MacDonald Jun 19 '23 at 14:34
  • @IanMacDonald yes that could be the issue if they had not used applicationId and going for namespace changes. – nitinkumarp Jun 23 '23 at 16:02

3 Answers3

30

Remove package="com.your.unique.package.name" attribute from the <manifest> element in the AndroidManifest.xml file of your app module

Add it to the app module build.gradle i.e build.gradle(:app) using namespace

android {
     ...
     namespace 'com.your.unique.package.name'
}

Note: You have to do this for every other module if your project is multi-module.

Robin
  • 904
  • 8
  • 16
  • Have you checked on other modules? @AlexMandelias – Robin May 02 '23 at 09:16
  • Coming back to this question I see that, in a moment of gradle-build-related desperation I clicked on it for a slightly different problem what OP asked, and your answer doesn't correspond to my problem. I'll just strikethrough the original comment to avoid any confusion, my apologies. EDIT: turns out I can't edit my other comment. EDIT 2: meh I'll just delete it – Alex Mandelias May 03 '23 at 18:20
14

Remove package element from manifest and insert it into §build.gradle§(:app) as namespace:

android {
    ...
    ...
    namespace 'your.package.name'
}
CybeX
  • 2,060
  • 3
  • 48
  • 115
guenter47
  • 457
  • 5
  • 13
0

Above both answers are right but if you are using any other module so please also declare the namespace there. I am using the native templates module.

Note: Open Project as Files then you will see other module or its build file.