Reputation: 2261
This is the output of my Gradle console, I am unable to build my project
D:\Android Projects\....\app\src\main\res\layout\topic_view_header.xml
Error:error: resource attr/?? (aka -packagename- :attr/??) not found.
Error:error: resource attr/?? (aka -packagename-:attr/??) not found.
Error:error: resource attr/?? (aka -packagename-:attr/??) not found.
Error:resource attr/?? (aka -packagename-:attr/??) not found.
Error:resource attr/?? (aka -packagename-:attr/??) not found.
Error:resource attr/?? (aka -packagename-:attr/??) not found.
Error:failed linking file resources.
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 27s
Information:11 errors
Information:0 warnings
Android Studio 3.0 RC 2
Upvotes: 140
Views: 425131
Reputation: 1159
This worked for me.
Its gradle issue. Upgrade your gradle to version 6
https://services.gradle.org/distributions/gradle-6.5-all.zip
If you using cordova then update android version to 9
Ex : cordova platform add android@9.0.0
Upvotes: 0
Reputation: 138
In my case I have update compile SDK and build SDK version to 30 and added
requestLegacyPermission=true
in android manifest file, as I was accessing the storage for reading and writing. later when I edited the compile SDK and build SDK version and get back to version 26 then I forgot to remove
requestLegacyPermission=true
in Manifest file.
Reason:
requestLegacyPermission was introduced in Android 10 so that's the reason Manifest was not recognizing this as I updated Compile SDK and Build SDK to 26.
Upvotes: 0
Reputation: 395
I encountered the same issue, searched on google, tried a lot of solutions, none worked.
Until I found the golden key of solving this: ./gradlew assembleDebug
.
Try this command in git bash
, the console will tell exactly which line has errors.
Then you improve it, and run the command again, until compilation succeeds.
Upvotes: 1
Reputation: 270
I had this issue
AAPT2 error: check logs for details
because i have added Quotation Marks(')
to my string file without using Backslash(\)
error text
<string name="no_internet">You don't have internet connection </string>
fixed text
<string name="no_internet">You don\'t have internet connection </string>
so, check special character correctly added to your string file
Upvotes: 0
Reputation: 409
Click on the Gradle tab in right side of Android Studio -> Open the projects build directory as shown in below image -> Run the assembleDebug
-- The error will be shown like in below image
Upvotes: 2
Reputation: 384
I was using on wrong way an coordinator layout attribute, I removed that and it works. Check your layout
app:layout_constraintVertical_bias="parent"
That should be a numeric value not literal :/ tiny mistake
Upvotes: 1
Reputation: 5316
In my case removing the pre-existing build folder and retrying solved the problem.
Upvotes: 1
Reputation: 5325
Update 2 (Follow this approach)
You shouldn't do this now. Instead fix all the errors. This is only a workaround until it's removed. After that, you'll need to fix errors manually anyways.
Try to update your gradle plugin to 3.3.0-alpha06
to check if that fixes your issue.
Update 1:
Non-ascii characters issues have been fixed in AAPT2 and android gradle plugin now (yay!). Instead of disabling AAPT2 now you can just use android gradle plugin version 3.2.0-alpha11 or newer and you should not encounter this error anymore.
Original Answer
Aapt2 is enabled by default when you use android plugin for gradle 3.0.
This is to
improve incremental resource processing
as stated here.
But if you are facing issues with it, you can switch back to previous version by adding this in gradle.properties
android.enableAapt2=false
Upvotes: 113
Reputation: 479
Delete the .idea
folder, and then try again. Make sure that you are using an open network.
Upvotes: 2
Reputation: 2585
Add build.gradle in-app level aaptOptions { cruncherEnabled = false }
Upvotes: 2
Reputation: 4644
I solved this issue by downgrading classpath 'com.android.tools.build:gradle:3.2.1'
and distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Upvotes: 2
Reputation: 1645
Don`t use this android.enableAapt2=false, this is not a solution . find out the error which is exactly show in your Build Output box , click on Toggle view to find exact error or exception use
compileSdkVersion 28
buildToolsVersion "28.0.3"
use this on gradel-wrapper:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
and follow the instruction delete or update external library or dependencies
Upvotes: 2
Reputation: 59004
Do not add this line to your project as other answers. Because it is already resolved in newer Gradle versions.
You can update your build gradle version in Project level build.gradle
to latest.
buildscript {
dependencies {
// choose latest if available
classpath 'com.android.tools.build:gradle:3.3.0-alpha06'
}
}
and gradle-wrapper.properties
// choose latest if available
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
More info Android Documentation
If you add, you will get an warning android.enableAapt2=false
WARNING: 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.
Upvotes: 4
Reputation: 7415
UPDATE
A new version of Gradle and Android-gradle-plugin is available that fixes these issues.
build.gradle (top level)
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip
PREVIOUS ANSWER
If you disable AAPT2 you are just hiding the real issue.
Please be aware that AAPT1
might be removed in the future therefore you are forced to use AAPT2
. Actually the migration guide isn't hard to follow since you don't see that much changes at the same time this way is future proof.
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>
Therefore you must check first if your really follow the correct Manifest structure as showed below.
Manifest file structure
The code snippet below shows the general structure of the manifest file and every element that it can contain. Each element, along with all of its attributes, is fully documented in a separate file.
<manifest> <uses-permission /> <permission /> <permission-tree /> <permission-group /> <instrumentation /> <uses-sdk /> <uses-configuration /> <uses-feature /> <supports-screens /> <compatible-screens /> <supports-gl-texture /> <application> <activity> <intent-filter> <action /> <category /> <data /> </intent-filter> <meta-data /> </activity> <activity-alias> <intent-filter> . . . </intent-filter> <meta-data /> </activity-alias> <service> <intent-filter> . . . </intent-filter> <meta-data/> </service> <receiver> <intent-filter> . . . </intent-filter> <meta-data /> </receiver> <provider> <grant-uri-permission /> <meta-data /> <path-permission /> </provider> <uses-library /> </application> </manifest>
Upvotes: 103
Reputation: 479
I also face this problem. "AAPT2 error: check logs for details" with studio version 3.1.2 when first time building app.
I was using 'com.android.support:appcompat-v7:26.1.0'and some styles were not found when i see the error logs. So changed it to 'com.android.support:appcompat-v7:25.3.1' from my working project and issue got resolved.
Try it.
If still you face problem try for v7:26+ in place of exact version. This will definitely resolve issue.
Upvotes: 2
Reputation: 1824
For AAPT2 error: check logs for details or error: failed linking file resources. errors:
Check your .xml files that contains android:background="" and remove this empty attribute can solve your problem.
Upvotes: 2
Reputation: 2333
Check if any of your new XML files has an issue. Go to Android issues and see if there are XML files there. However, the error doesn't show on the right XML file that has the problem.
In my case, I added two headers in the same XML file.
Something like that:
Upvotes: 2
Reputation: 429
The Resource Exception means there is an error with your resources, any resource folder file is corrupted, try to open all images in drawable folder to see if these are opening fine.
There is a good command to check for corrupted resource pngs.
f -name "*.png" | xargs -L 1 -I{} file -I {} | grep -v 'image/png; charset=binary$'
Upvotes: 2
Reputation: 62419
Check following things in your project:
Make sure any XML file doesn't have blank space at starting of the file.
Make sure that any drawable file doesn't have any issue like capital letters or any special symbols in name.
If your aapt2.exe is missing continuously then please scan your full PC, May be there is a virus which is removing adb.exp or aapt2.exe
Hope you will get solution.
Upvotes: 2
Reputation: 1535
In my case it was fixed by adding a reference to the constraint-layout package
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
Upvotes: 1
Reputation: 111
I got same error AAPT2 error: check logs for details, and i applied above solutions, as per most common solution, i was opened gradle.properties and add line
android.enableAapt2=false
for solution, but i got an error Process 'command 'D:\Android\sdk\Sdk\build-tools\27.0.3\aapt.exe'' finished with non-zero exit value 1
But after many searches i found that there is problem in layout's xml file that i was repeat lines in layout's xml file which is as below:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
Remove Repeat lines from xml file and rebuild project and Done.
Upvotes: 2
Reputation: 7532
Since at some point in the future the support for AAPT(1) will be deprecated, it would be good to identify the reason for the error you reported.
Could you provide the contents of the \app\src\main\res\layout\topic_view_header.xml file?
From the question marks it is possible that you are using non-ASCII characters, which AAPT2 still has some trouble with. If it's indeed non-ASCII characters then please follow the bug on https://issuetracker.google.com/68262818.
Update: The issue is fixed in android gradle plugin version 3.2.0-alpha11 or newer.
Upvotes: 5
Reputation: 7557
If you are using Kotlin getting error because of some mistakes in xml files. In kotlin its very hard to find xml errors, build getting fail simply . To know the exact error log run below command in Android Studio Terminal and it is easy to fix the errors.
./gradlew clean
./gradlew assemble
Upvotes: 2
Reputation: 19290
Check and try below things. Issue should be resolved.
First of all check your log from bottom of the build window whether any error related to project showing or not. If error showing then fix all of those. Now build and run again fix all of the error comes up. It will eliminate aapt2 issue without changing android gradle plugin to 3.2.0.
Secondly if there is not any project related error showing in the build log but still showing aapt2 error then you can fix it by following below steps.
Update your android gradle plugin in your project level build.gradle
file like below:
classpath 'com.android.tools.build:gradle:3.2.0-alpha13'
Now update android.enableAapt2=true
. Then check and build your project.
Any of these steps should work to fix aapt related issues.
Upvotes: 2
Reputation: 340
In my case the real problem was that after generating Image Asset to generate launcher mipmap icon for my project, the generated file ic_launcher_foreground.xml had error inside (was wrongly generated). There was missing closing xml tag in the end of file, < / vector> was missing.
Upvotes: 2
Reputation: 52534
This error message (AAPT2 error: check logs for details ) is not helpful because it doesn't tell you what the real problem is.
In my case, it was due to a missing resource XML drawable file.
error: failed linking file resources.
org.gradle.tooling.BuildException: Failed to process resources, see aapt output above for details.
I only figured out because I undid the changes in the XML file, and this time I got a more helpful message:
error: resource drawable/ic_filter_off (aka com.xxx:drawable/ic_filter_off) not found.
Message{kind=ERROR, text=error: resource drawable/ic_filter_off (aka com.xxx:drawable/ic_filter_off) not found., sources=[C:\code\xxx\app\src\main\res\layout\app_bar_main.xml:69], original message=, tool name=Optional.of(AAPT)}
Upvotes: 2
Reputation: 161
I had exactly the same issue: After updating to Android Studio 3.1.2 my project wouldn't compile with an AAPT2 error telling me some of my drawables which are referenced by styles.xml
could not be found. Disabling AAPT2 isn't a solution anymore, since the setting is deprecated and will be removed at the end of 2018.
Culprit was an empty line just before the xml decleration in a totally unrelated layout.xml
file... So the layout.xml
file started like this:
//empty line//
<?xml version="1.0" encoding="utf-8"?>
Removed the empty line and everything worked like a charm again. Unbelievable and unlikely, but true.
Android Studio actually gave a warning because the file didn't start with the xml decleration (because of the empty line). But the warning is only visible when the file is opened in the editor.
Upvotes: 2
Reputation: 2574
I fixed the ERROR with three steps
1. I checked for the problem SOURCE
2. Provided the correct string/text, it was the CAUSE
3. I cleaned the project, you will find it under BUILD.
Upvotes: 5
Reputation: 7685
Ensure that you use valid file types in your src/main/res/raw
directory. In my case I had copied a .mov file along with a bunch of other files into my res/raw directory. I suspect the issue was that aapt was trying to process the .mov file and did not know what to do with it.
Upvotes: 2
Reputation: 223
I am not sure if this has been answered yet for you but allow me to weigh in. I confronted a similar problem recently and I was able to pinpoint the exact problem from the build tab next to the logcat. My problem was caused by a fontfamily error in the XML. I am using the latest version of Android Studio with the March 2018 update.
Upvotes: 2