Akshat Chawla
Akshat Chawla

Reputation: 71

AAPT2 error in Android Studio 3.0.1

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?

Upvotes: 7

Views: 12348

Answers (8)

Nabin Dhakal
Nabin Dhakal

Reputation: 2202

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

defaultConfig {
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
}

Upvotes: 0

UdayaLakmal
UdayaLakmal

Reputation: 4223

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.

Upvotes: 0

Hidayat Ullah
Hidayat Ullah

Reputation: 31

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.

Upvotes: 0

emilpmp
emilpmp

Reputation: 1736

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

Upvotes: 6

cross19xx
cross19xx

Reputation: 3487

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>

Upvotes: 0

Manish Patiyal
Manish Patiyal

Reputation: 4477

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

Upvotes: 0

Mohammed Rampurawala
Mohammed Rampurawala

Reputation: 3112

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

Upvotes: 0

Izabela Orlowska
Izabela Orlowska

Reputation: 7532

"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.

Upvotes: 2

Related Questions