'Unity Build Error: Missing 'package' key attribute on element package at [:arcore_client:] AndroidManifest.xml:30:9-54

i am using ARFoundation 4.1.0 preview package and in XR plug-in management in unity project settings i have enabled the Arcore but the problem is when i build it gives me "Missing 'package' key attribute on element package at [:arcore_client:] AndroidManifest.xml:30:9-54". and when i disable the Arcore it works fine but i get black screen camera.



Solution 1:[1]

I have similar question with you, but I was using ARcore SDK.

This issue happens for the combination of:

  • Using Android-SDK's API level 31 (or later),
  • With old Gradle version(s).

Basically, updating build-tools to 31 is not enough to support queries element (of manifest, added since Android 11+). Gradle needs to be updated, too.

I solved it by changing Gradle-plugin in my assets--plugins--android--mainTemplate.gradle file, from 3.4.0 to 3.6.0, like:

dependencies {
  classpath 'com.android.tools.build:gradle:3.6.0'
}

you may need to check "Customer Gradle Templete" in player setting-publishing setting-build, to create this file

Solution 2:[2]

i solved it by reverting back from ar foundation preview 10 4.1.0 to preview-2

Solution 3:[3]

This is due to the gradle file configuration issue. You have to manually make some changes in the custom gradle files in Unity 3D 2019+ versions.

  1. Go to Preferences > External Tools > Android > Gradle, and set the custom Gradle to Gradle 5.6.4 or later. If you are already having it then skip the step.

    enter image description here

  2. Go to Project Settings > Player > Android tab > Publishing Settings > Build, and select both:

    Custom Main Gradle Template

    Custom Launcher Gradle Template.

    enter image description here

  3. Apply the following changes to both generated files:

    Assets/Plugins/Android/mainTemplate.gradle

    Assets/Plugins/Android/launcherTemplate.gradle

    If present, remove the following comment at the top of the file:

    // GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN

Insert the following lines at the top of the file:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.0'
    }
}

allprojects {
   repositories {
      google()
      jcenter()
      flatDir {
        dirs 'libs'
      }
   }
}

Solution 4:[4]

  1. Find the Gradle version that your Unity version uses from here.

  2. Then find the latest Gradle plugin version compatible with the Gradle version found in step one from here.

  3. In the Publishing Settings section in the Player Settings, tick the Custom Gradle Template option. Unity then generates a default mainTemplate.gradle file in Assets/Plugins/Android/ folder.

  4. In the mainTemplate.gradle file, update the com.android.tools.build:gradle plugin version to the newer version found in step 2.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Top-Master
Solution 2 Umer Asghar
Solution 3 Codemaker
Solution 4 Gayan Weerakutti