可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
回答1:
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
Update:
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.
回答2:
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>
回答3:
I had an error in my XML layout. So check your xml layout for errors.
回答4:
Check gradle console tab in android studio (by default in bottom right corner). In my case there were errors like this:
C:\\Users\\Jozef Bar??k\\.gradle\\caches\\transforms-1\\files-1.1\\appcompat-v7-25.4.0.aar\\d68bb9d2059935a7891196f4dfb81686\\res\\drawable-hdpi-v4\\abc_ic_menu_share_mtrl_alpha.png: error: file not found.
Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
:app:mergeDebugResources FAILED
I solved the issue setting gradle user home to another location without white or special characters:
C:\\Android\\.gradle
You can configure it setting \"Service directory path\" in Gradle settings dialog. In my case it was necessary to delete old .gradle directory on previous location and restart android studio.
回答5:
Having the same issue here. As pointed out by @Izabela Orlowska, this problem is most likely caused by special characters in path (android grandle files, resources etc..).
For me: having ří
in folder name caused all the problems. Make sure you do not have any special characters in paths. Disabling AAPT2 is only a temporary \"solution\". Your project path contains non-ASCII characters android studio
回答6:
My problem was due to an image file name ending with .9.png. I changed the ending to .png and the problem disappeared. I got the hint from the stack trace in Gradle console: The top message was \"Execution failed for task :app:mergeDebugResources\" and the bottom message was \"com.android.builder.png.AaptProcess$NotifierProcessOutput.out\"
I look forward to the day when Gradle outputs more helpful error messages...
回答7:
I just had this problem when trying to use data bind and declaring the layout tag. I know it is a bit late but for the sake of anyone encountering this problem, What I did to resolve the issue after so many attempts was that on your root layout when you are not using data bind say for example this
<android.support.constraint.ConstraintLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
xmlns:app=\"http://schemas.android.com/apk/res-auto\"
xmlns:tools=\"http://schemas.android.com/tools\"
android:layout_width=\"match_parent\"
android:layout_height=\"match_parent\"
tools:context=\".MainActivity\"> </android.support.constraint.ConstraintLayout>
remove the
xmlns:android=\"http://schemas.android.com/apk/res/android\"
xmlns:app=\"http://schemas.android.com/apk/res-auto\"
xmlns:tools=\"http://schemas.android.com/tools\"
and just put it on your layout tag(that is if you are using data binding)
<layout xmlns:android=\"http://schemas.android.com/apk/res/android\"
xmlns:app=\"http://schemas.android.com/apk/res-auto\"
xmlns:tools=\"http://schemas.android.com/tools\">
</layout>
and hopefully it will work. the android.enableAapt2=false
didn\'t work for me so I have to remove everything and try to figure out why I get the error when I put layout tag and use data binding thus I came up with the solution. Hope it helps
回答8:
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.
回答9:
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.
回答10:
I also encountered this error. For me, it was when changing the target SDK from 26 down to 25. I was able to fix the problem by changing the appcompat dependency version from
implementation \'com.android.support:appcompat-v7:26.1.0\'
to
implementation \'com.android.support:appcompat-v7:25.4.0\'
This will allow the compiler to access the styling attributes that it is currently unable to find. This will actually fix the problem instead of masking the real issue as Enzokie suggested.
回答11:
In my case i was using wrong color code #CC00000
which is invalid because it has 7 digit but color code should have 3 or 6 or 8 digit plus # prefix
回答12:
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.
回答13:
Important Update
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
That\'s All! Sync and Run, Bingo!
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.
回答14:
Sometimes ! be careful with property depth of the image ! and name for image
exemple : ic_xxxxx_xxxx - Copie
回答15:
Looks like a resources related error. I would start there.
I got this (\"Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details\") first time related to pictures. Resize solved it. Or another time just repaired the links to resources.
回答16:
I got this error
com.android.tools.aapt2.Aapt2Exception: AAPT2 error
due to wrong filename of one of my /drawable item in layer-list.
And I resolved it by changing the filename to correct one.
回答17:
As @Izabela Orlowska pointed out: In my case the problem occurred due to some files that could not be found inside the gradle cache folder. (Windows OS)
The default gradle path was inside my user folder. the path contained umlauts and a space.
I moved the gradle folder by setting GRADLE_HOME
and GRADLE_USER_HOME
environment variable to some newly created folder without umlauts or spaces in path.
This fixed the problem for me.
回答18:
I tried everything suggested on here and many other sites, I eventually figured out that the problem was with Bitdefender blocking aapt....
If you have Bitdefender installed then you need to turn aapt & aapt2 \"Application Access\" on individually.
Hope this is of use.
回答19:
I have also had such a problem, the original is my computer\'s system tray this path :
C: \\ Users \\ \'appear special characters\' \\ .android appeared in Chinese,
and now I changed the path to :
C: \\ Users \\ hjc \\ .android.
The reason is the problem of special characters.It is for this reason that leads to gravel appt2Exception problems
回答20:
I had a very similar problem. It was solved by deleting gradle\'s cache (~/.gradle/caches on linux), which forced android studio to re download and re generate everything.
回答21:
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.
回答22:
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)}
回答23:
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.
回答24:
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.
回答25:
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
回答26:
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\'
回答27:
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$\'
回答28:
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:
回答29:
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.
回答30:
Disabling the AAPT2 mght cause issue in further development, In my case the error was generated when I created the app icon.
<vector xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:width=\"108dp\"
android:height=\"108dp\"
android:viewportWidth=\"Infinity\"
android:viewportHeight=\"Infinity\">
<path android:fillColor=\"#26A69A\"
android:pathData=\"M0,0h108v108h-108z\"/>
<path android:fillColor=\"#00000000\" android:pathData=\"M79,19L79,89\"
android:strokeColor=\"#33FFFFFF\" android:strokeWidth=\"0.8\"/>
I solve it by removing this line
android:viewportWidth=\"Infinity\"
android:viewportHeight=\"Infinity\"