Error: attribute 'package' in <manifest> tag is not a valid Android package name
Asked Answered
S

7

14

I am trying to write an android app, which used to build once upon a time. Now, everytime I build, I get the following error:

Caused by: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
C:\Users\Jay\AndroidStudioProjects\DndTools-App\app\build\intermediates\merged_manifests\debug\AndroidManifest.xml:2: AAPT: 
error: attribute 'package' in <manifest> tag is not a valid Android package name: 'dndtools'.

I originally started off with an android-kotlin tutorial as the base, since I wanted to familiarize myself with kotlin and android, if that might be relevant. Also, "Merged Manifest" has package = dndtools instead of com.dndtools.android.dndtools listed, also not sure if relevant.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.dndtools.android.dndtools">

  <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name" //dndtools
...

build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
def androidSupportVersion = '28.0.0'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"
    defaultConfig {
        applicationId "dndtools"
        minSdkVersion 21
        targetSdkVersion 28
...

I have searched the internet, and others who had this error usually had an underscore at the start or end of their applicationId (which is not the case here), so I am really at a loss

Socialization answered 9/4, 2019 at 19:23 Comment(0)
B
18

Change applicationId "dndtools" to applicationId "com.dndtools.android.dndtools".

applicationId in your build.gradle file is what is used as the real package, that's why you can see it in the merged manfiest as well. Update it to match the one you have in your Android Manfiest and it should work fine.

As for why it's an invalid package - it needs to have at least one dot in it to be installable on Android.

Bladdernut answered 10/4, 2019 at 11:48 Comment(1)
I havefigured it out myself at this point, but this is the correct answer. Thank you!Socialization
I
12

My problem was with uncorrect naming of the package id. I put something like com.example.3d. You can't start with the number like 3d.

Ineffectual answered 22/9, 2021 at 21:29 Comment(1)
thanks, so stupid by androidStutz
P
4

In my Case, I have updated the Android studio to version 3.5.3, and while project setup, by mistake I have added applicationIdSuffix = kotlin_version, so this is what causing the problem.

So simply removing this line helped me to fix this issue.

Pescara answered 29/1, 2020 at 7:36 Comment(1)
I too had a similar issue. I had to remove the applicationIdSuffix and VersionNameSuffix from apps's build.gradle.Saltzman
O
4

A full Java-language-style package name for the Android app. The name may contain uppercase or lowercase letters ('A' through 'Z'), numbers, and underscores ('_'). However, individual package name parts may only start with letters

Overcloud answered 12/1, 2022 at 12:51 Comment(0)
S
3

in my case, i build app use default config

compileSdkVersion 30

defaultConfig {
    applicationId "com.webview.app"
    minSdkVersion 23
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    applicationIdSuffix kotlin_version
}

when i add productFlavors

  flavorDimensions "default"
  productFlavors {
    test01{
        dimension "default"
        applicationIdSuffix ".test"
        versionNameSuffix "-test00"
    }

    test01{
        dimension "default"
        applicationIdSuffix ".test"
        versionNameSuffix "-test01"
    }

    test01{
        dimension "default"
        applicationIdSuffix ".test"
        versionNameSuffix "-test02"
    }
}

then i'm runing my app, i got this message

tag is not a valid Android package name: 'com.webview.app.1.4.21.jb'

i think the problem shoud be number and point(.) can not be package name, so i delete code

applicationIdSuffix kotlin_version

it's work for me, because kotlin_version value it's ext.kotlin_version = "1.4.21", when my appid contain number and point(.) it cannot working. in android the appid(pacakege name) should be like this 'come.domain.project' it is reverse domain name.

Solley answered 10/12, 2020 at 8:32 Comment(0)
R
1

Starting with Android Gradle Plugin (AGP) 7.3, even the compiler showed invalid manifest package name, you should look at your module's build.gradle.kts file applicationId property. The Android naming rules for the application ID are:

  1. It must have at least two segments (one or more dots).
  2. Each segment must start with a letter.
  3. All characters must be alphanumeric or an underscore [a-zA-Z0-9_].

applicationId dndtools breaks rule # 1.

Bonus: Most developers prefer to use the same identifier by reversing their domain name for both Apple and Android apps. Apple official documentation (for iOS 2.0+, iPadOS 2.0+, macOS 10.0+, tvOS 9.0+, visionOS 1.0+ and watchOS 2.0+) lists the allowed characters for bundle IDs:

  1. alphanumeric characters (A–Z, a–z, and 0–9),
  2. hyphens (-), and
  3. periods (.).

Apple allows hyphen (-), but Android allows underscores (_). For domain names that have hyphen (-), it is suggested to remove this character to make the identifier compliant with both systems.

Rozina answered 4/7 at 1:16 Comment(0)
R
0

In my case the problem was in the applicationId of app/build.gradle. I used a "-" character in the applicationId property. It was "domainname.site-name". After changing to "domainname.sitename" the problem with package name gone away.

Reeva answered 7/6 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.