10

I am trying to create an android app for watchduino2.. When i follow the provided steps i encounter the error

AAPT: error: unexpected element <uses-permission> found in <manifest><application>

Can somebody explain this problem? And also help me to resolve it as well.

Vijay
  • 139
  • 1
  • 1
  • 6

3 Answers3

40

<uses-permission> needs to be a child of the root <manifest> element. You have it as a child of the <application> element. So, move the <uses-permission> element.

So, you have something like:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="net.whatever">
    <application android:icon="@drawable/icon"
                 android:debuggable="true"
                 android:label="@string/app_name">
        <uses-permission android:name="android.permission.INTERNET"/>
      <!-- other stuff here -->
    </application>
</manifest>

It needs to be more like:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="net.whatever">
    <uses-permission android:name="android.permission.INTERNET"/>
    <application android:icon="@drawable/icon"
                 android:debuggable="true"
                 android:label="@string/app_name">
      <!-- other stuff here -->
    </application>
</manifest>
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • But i am unable to make changes in the AndroidManifest.xml mentioned in the error. Every time i make the change and compile , it returns to its previous state – Vijay May 27 '19 at 13:59
  • @Vijay: Then you are editing the wrong manifest file. See [this blog post](https://commonsware.com/blog/2016/04/08/why-cant-edit-manifest-android-studio.html) for more. – CommonsWare May 27 '19 at 14:21
  • I tried the fix explained in your link. Even after applying the fix in AndroidManifest.xml in src directory i am facing with the same problem. @CommonsWare – Vijay May 27 '19 at 15:57
  • @Vijay: Examine your merged manifest using the "Merged Manifest" sub-tab in the Android Studio manifest editor and see where your mis-positioned `` is coming from. You might also consider editing your question and providing a [mcve], including the entire contents of your manifest. – CommonsWare May 27 '19 at 15:59
  • In my case the uses-permission tag was inside of application, whichever I moved to just before the application tab, and works like the butter. – ArifMustafa Aug 06 '22 at 16:20
1

it might be about misplaced tag, make sure your manifest elements are nested correctly

Previous versions of AAPT would simply ignore the misplaced tag. However, with AAPT2, you will get error

read below official document for proper Manifest structure :

Manifest File Structure

Russell Ghana
  • 2,963
  • 3
  • 20
  • 31
0

For the users, try to add user-permission after by default its wrong in the place and commented in file android/app/src/main/AndroidManifest.xml

</application>

  <uses-permission android:name="android.permission.INTERNET" />
</manifest>
Alamgir Khan
  • 87
  • 1
  • 2
  • 9