问题
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?
回答1:
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
回答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.
回答3:
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.
回答4:
In your gradle.properties
add this line android.enableAapt2=false
回答5:
Disable Instant Run and it may work for you. For me it worked
回答6:
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>
回答7:
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.
回答8:
This helped me. Adding these in build.gradle(Module:app)
defaultConfig {
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
}
来源:https://stackoverflow.com/questions/48528614/aapt2-error-in-android-studio-3-0-1