AAPT2 error in Android Studio 3.0.1

元气小坏坏 提交于 2019-12-05 09:24:08

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

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

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.

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

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

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

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>

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.

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

defaultConfig {
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!