Home > Software design >  AAPT: error: attribute type (aka com.example.androidtrivia:type) not found
AAPT: error: attribute type (aka com.example.androidtrivia:type) not found

Time:11-07

I am using Android Studio Arctic Fox | 2020.3.1 Patch 1 of August 7, 2021.

As per the following note in https://developer.android.com/codelabs/kotlin-android-training-start-external-activity?index=../..android-kotlin-fundamentals#3

Note: If you're using Android Studio 3.2 or lower, you might have to change app:type = "integer" to app:argType = "integer" in the navigation.xml file

and assuming that I am using AS higher than 3.2, I changed the app:argType="integer" to app:type="integer" in the navigation argument type.

Now the following error occurs:

AAPT: error: attribute type (aka com.example.androidtrivia:type) not found.

If I keep app:argType the project compiles and runs correctly.

Is app:type not correct to use?

project gradle:

dependencies {
    classpath "com.android.tools.build:gradle:7.0.1"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"

    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0-alpha10"

}

module gradle

plugins {
  id 'com.android.application'
  id 'kotlin-android'
  id 'kotlin-kapt'
  id 'androidx.navigation.safeargs.kotlin'
}


dependencies {

  implementation 'androidx.core:core-ktx:1.6.0'
  implementation 'androidx.appcompat:appcompat:1.3.1'
  implementation 'com.google.android.material:material:1.4.0'
  implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
  implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  testImplementation 'junit:junit:4.13.2'
  androidTestImplementation 'androidx.test.ext:junit:1.1.3'
  androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

  implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0-alpha10'
  implementation 'androidx.navigation:navigation-ui-ktx:2.4.0-alpha10'

  implementation "com.google.android.material:material:1.4.0"
}

error section

   <argument
        android:name="numQuestions"
        app:type="integer" />

CodePudding user response:

The note:

Note: If you're using Android Studio 3.2 or lower, you might have to change app:type = "integer" to app:argType = "integer" in the navigation.xml file

Means that Android Studio 3.2 or lower is going to add app:type, which is wrong. You need to manually correct it to app:argType. On Android Studio 4.0 , it already uses the correct app:argType, which is what you should be using.

So just change the incorrect app:type to app:argType.

  • Related