45

NOTICE: Please do not post this "android.enableAapt2=false" as an answer. It is not a solution. It is just ignoring the real error which is not causing any problem on runtime.

Solution was simple, just removed mistakenly placed action tag outside of an intent filter in the manifest file.

Have an application which was building by Android Studio 2.3 fine. After updating Android Studio 3.0 Stable, started to having this error and unable to build my project.

Here my manifest.xml

<application
    android:name=".ApplicationClass"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <!--other unrelated stuff-->

    <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

    <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.xxx.xxx" />
        </intent-filter>
    </receiver>
</application>

Error shows this line:

<action android:name="com.google.android.c2dm.intent.REGISTRATION" />

If I comment/remove this action tag line, the project builds fine but it is necessary for GCM and I cannot remove it.

As you see the logs, The error not occurs at main manifest file, occurs at /build/intermediates/manifests/full/debug/AndroidManifest.xml

Tried cleaning, rebuilding, disabling instant run. Is there any solution?

The Error Logs:

/THE_PROJECT_PATH/app/build/intermediates/manifests/full/debug/AndroidManifest.xml
Error:(99) error: unknown element <action> found.
Error:(99) unknown element <action> found.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
Information:BUILD FAILED in 1s
Information:6 errors
Information:0 warnings
Information:See complete output in console
Oğuzhan Döngül
  • 7,856
  • 4
  • 38
  • 52

8 Answers8

40

You have a misplaced tag. The new AAPT (AAPT2) now throws an error on this.

From the docs in here: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

Behavior changes when using AAPT2


To improve incremental resource processing, Android plugin 3.0.0 enables AAPT2 by default. Although AAPT2 should immediately work with older projects, this section describes some behavior changes that you should be aware of.

Element hierarchies in the Android manifest

In previous versions of AAPT, elements nested in incorrect nodes in the Android manifest are either ignored or result in a warning. For example, consider the following sample:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.myname.myapplication">
   <application
       ...
       <activity android:name=".MainActivity">
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
           <action android:name="android.intent.action.CUSTOM" />
       </activity>
   </application>
</manifest>

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

AndroidManifest.xml:15: error: unknown element <action> found.

To resolve the issue, make sure your manifest elements are nested correctly. For more information, read Manifest file structure.

Community
  • 1
  • 1
Raz
  • 8,918
  • 3
  • 27
  • 40
  • thank you! never realized that I forgot the intent filter around my action. But the error message could be a little bit better, perhaps filled with some information from the documentation. – Ben Nov 15 '17 at 22:24
  • For this case, you should change your GCM set up : https://developers.google.com/cloud-messaging/android/client or using Firebase – quangkid Feb 05 '18 at 03:40
16

add this code in gradle.properties in the root project:

android.enableAapt2=false

this worked for me

root 
| 
|--gradle.properties
djsreeraj
  • 639
  • 5
  • 14
  • 5
    This only makes the existing mistake invisible, not an actual solution. Aapt2 is actually useful and I do not want to disable it. – Oğuzhan Döngül Oct 30 '17 at 09:39
  • 1
    Is there any way to update the gradle version without actually disabling the Aapt2 ? – Pradeep Singh Nov 02 '17 at 09:40
  • Android studio says: `The option 'android.enableAapt2' is deprecated and should not be used anymore. Use 'android.enableAapt2=true' to remove this warning. It will be removed at the end of 2018..` – zeroDivider Dec 27 '18 at 10:42
3

Put action content in intent-filter like below as per Manifest file structure.

<intent-filter>
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
 </intent-filter>
Tushar Lathiya
  • 940
  • 9
  • 26
1

In order to summarize and simplify: you should just concentrate on your main AndroidManifest.xml file and check whether it strictly follows the sequence as well as nesting of XML tags as described in https://developer.android.com/guide/topics/manifest/manifest-intro.html. Otherwise the IDE will open up the debug-level AndroidManifest.xml showing a lot of error every time you try to clean/build the project and make you confused!

0

Just rename your manifest file like this: AndroidManifest.xmlold, then create a new XML file and give name: AndoridManifest.xml. Then just copy the content of the old file after you remove line with tag . Build>Clean Project and then Run>debug app again. Then the problem will be disappeared.

0

We have the solution of this problem and solution is that service always comes under child form of <Application <service>> when we write the code outside of <Application> then issue occur. Services are the child part of Application in Manifest... okay... It will sure work..do it

Pradeep Sheoran
  • 493
  • 6
  • 15
0

In my app in AndroidManifest.xml tag receiver was under the application tag and this was cause of build fail with message .../android/app/build/intermediates/manifests/full/debug/AndroidManifest.xml:25: AAPT: error: unknown element <receiver> found. After i have put it in application tag then the project has been compiled successfully. That's all

Dmitriy Grachev
  • 359
  • 2
  • 4
  • 2
    The question was regarding a tag, which does not seem related to the answer you provided a tag. The author resolved the issue by removing the tag. – brianfeucht Jun 19 '18 at 23:28
0

I recently had this fix on my gradle.properties but a warning saying that "The option 'android.enableAapt2' is deprecated..." kept on coming and the solution was to change it to true instead.