6

I have looked at the previous answers for this question but the AAPT error still occurs.

error: attribute 'package' in <manifest> tag is not a valid Android package name: 'org.emarti202.gcu.mpd-cw-em'.

Despite my applicationId in the build.gradle and the package names in the AndroidManifest.xml match, they still do not work. Is there a solution for this? Apologies is this is a simple fix, I cant seem to wrap my head around it.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.emarti202.gcu.mpd-cw-em">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="MPD-CW-EM"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <meta-data android:name="com.google.android.geo.API_KEY"
            android:value="@string/map_key" />

        <activity android:name="org.emarti202.gcu.mpd-cw-em.MainActivity2"></activity>
        <activity android:name="org.emarti202.gcu.mpd-cw-em.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "org.emarti202.gcu.mpd-cw-em"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.android.gms:play-services:+'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    // implementation 'com.alespero:expandable-cardview:0.6'
    // implementation 'com.google.android.gms:play-services-maps:16.1.0'
}

2 Answers 2

8

Unfortunately the hyphen '-' is not acceptable in a package name. Please reference this docs.

https://developer.android.com/guide/topics/manifest/manifest-element.html#package

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. While building your app into the an application package (APK), the build system uses the package attribute for two things

Please change your package name to 'org.emarti202.gcu.mpd_cw_em'.

2
  • Ah I see! Sorry about that Daniel, thank you for helping me out!
    – RoxyM
    Commented Mar 5, 2021 at 15:29
  • no problem, So, you can't use anything else except for letters, digits, the character "." and the character "_" . Commented Mar 5, 2021 at 15:31
0

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:

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

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:

  • alphanumeric characters (A–Z, a–z, and 0–9),
  • hyphens (-), and
  • 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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.