7

I'm trying to get a "hello world" application running using Android Studio 3.0.1 and get the following AAPT2 error output:

Error:(16) error: not well-formed (invalid token).
Error:(16) not well-formed (invalid token).
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:mergeDebugResources'.
> Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details...

I was not able to find a solution, could someone please help me?

Droidman
  • 10,609
  • 14
  • 85
  • 134
Akshat Chawla
  • 71
  • 1
  • 1
  • 3
  • Look here: https://stackoverflow.com/questions/46988102/errorcom-android-tools-aapt2-aapt2exception-aapt2-error-check-logs-for-detail – Black.Jack Jan 30 '18 at 18:58

8 Answers8

6

android.enableAapt2=false Don't do this step to temporarily hide the issue. Aapt1 is going to be deprecated soon and Aapt2 has to be used by 2018 end.

This is just an issue with the gradle build tools. Just update your gradle and the gradle tools.

I am using classpath 'com.android.tools.build:gradle:3.3.0-alpha02'' inside dependency tag in Project level gradle and I am using gradle version 4.8 . This fixed the issue for me.

Additional Disable Instant run, if this didn't fix for you

emilpmp
  • 1,404
  • 10
  • 25
2

"not well-formed" error from AAPT2 means one of your XML files is not well formed, probably missing a closing bracket or something similar. Above the error it should say which file it comes from. Have a look at your res/ directory and the files inside.

Izabela Orlowska
  • 6,846
  • 2
  • 17
  • 32
0

In your gradle.properties add this line android.enableAapt2=false

Mohammed Rampurawala
  • 2,837
  • 2
  • 20
  • 32
  • 2
    AAPT1 will be deprecated soon, so it's really not the best thing to just go and disable AAPT2 when there's no good reason to. Like in this case, it's just a malformed XML file, which in all true possibility AAPT1 won't be able to parse either. – Izabela Orlowska Feb 05 '18 at 12:05
  • This is just to hide the real issue. – emilpmp Jul 06 '18 at 04:46
0

Disable Instant Run and it may work for you. For me it worked

Manish Patiyal
  • 4,148
  • 4
  • 18
  • 35
0

In my case, the solution was a bit tricky and funny. I had a RelativeLayout with a TextView and a ProgressBar. The Progressbar sits on top of the TextView, like so:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1"
    tools:context="com.caoa.yakokoe.yakokoe.ui.splash.SplashActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:contentDescription="@string/content_desc_logo_green"
            android:src="@drawable/logo_green" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5">

        <ProgressBar
            android:id="@+id/splash_progress_bar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/splash_text"
            android:layout_centerHorizontal="true"
            android:indeterminate="true"
            android:visibility="gone" />

        <TextView
            android:id="@+id/splash_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="24dp"
            android:layout_marginTop="16dp"
            android:text="@string/splash_text_default"
            android:textAlignment="center"
            android:visibility="gone" />
    </RelativeLayout>
</LinearLayout>

This threw a sort of error (forgotten what it was, but it was in the lines of 'cannot find id of layout_above').

The solution was simply to flip the ProgressBar and TextView Locations, like so:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1"
    tools:context="com.caoa.yakokoe.yakokoe.ui.splash.SplashActivity">

    <!-- Content here -->

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5">

        <TextView
            android:id="@+id/splash_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="24dp"
            android:layout_marginTop="16dp"
            android:text="@string/splash_text_default"
            android:textAlignment="center"
            android:visibility="gone" />

        <ProgressBar
            android:id="@+id/splash_progress_bar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/splash_text"
            android:layout_centerHorizontal="true"
            android:indeterminate="true"
            android:visibility="gone" />
    </RelativeLayout>
</LinearLayout>
cr05s19xx
  • 1,796
  • 1
  • 14
  • 34
0

I had the same issue, I changed

compileSdkVersion 22 to compileSdkVersion 25

targetSdkVersion 22 to targetSdkVersion 25

implementation 'com.android.support:appcompat-v7:22' to implementation 'com.android.support:appcompat-v7:25'

That fixed the problem for me.

0

This is old question, seems no body provide correct way to find AAPt2 error

AAPT2 error: check logs for details

it will different for each case.

So find correct error you should run assembelDebug as suggest in here

Reference following image for run assembleDebug.

enter image description here

in My case actually corrupted png file and only failed with release build. so i have to run assembleRelese for find that issue.

UdayaLakmal
  • 3,547
  • 4
  • 25
  • 40
0

This helped me. Adding these in build.gradle(Module:app)

defaultConfig {
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
}
Nbn
  • 456
  • 1
  • 10
  • 24