Android Studio 3.0 unknown element <library> found

佐手、 提交于 2021-02-18 10:58:20

问题


After I updated Android Studio, one of my projects cannot be built. The error message is:

Error:(20) error: unknown element <library> found.
Error:(20) unknown element <library> found.
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

My SDK version is 25. I have tried to invalidate cache and add distributionUrl=https://services.gradle.org/distributions/gradle-4.1-rc-2-all.zip, and both of them don't work for me.

Here is my dependencies:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-v4:25.4.0'
compile 'de.hdodenhof:circleimageview:2.2.0'
testCompile 'junit:junit:4.12'

annotationProcessor "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}"
compile "com.github.Raizlabs.DBFlow:dbflow:${dbflow_version}"

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:design:25.4.0'

compile 'com.microsoft.projectoxford:face:1.3.0'
}

This is the error log after removing DBFlow:

Error:(20) error: unknown element <library> found.
Error:(20) unknown element <library> found.
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

回答1:


Add this code in gradle.properties in the root project:

android.enableAapt2=false




回答2:


In android studio version 3.1.2 the solution

android.enableAapt2=false

is no longer working.

The root cause of this problem is the Manifest MERGE, which happens when you try to include other dependencies in your project.

To inspect the error

  1. Open AndroidManifest.xml

  2. On bottom of the window select Merged Manifest Tab

  3. Browse your manifest file now, and check the portion of manifest being in the slightly red background or lookup for library tag.

  4. Right click and select Go To Declaration. Inspect the file and check which library/depencency it belongs to.

  5. Either remove that library or update it from the repo.

Hope this helps.




回答3:


This is a reported issue on Github. The issue in the projectoxford seems to be fixed already at v.1.0.395




回答4:


Try removing the annotation processor that you have added this line annotationProcessor "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}" if you have used any other remove that also

As in studio 3.0 onwards they have inbuilt annotation processor




回答5:


You need simply to add this to your Android manifest

<library tools:node="removeAll" />

hope it helps :)




回答6:


It requires to append xmlns:tools="http://schemas.android.com/tools" into manifest, so I wrote:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"   <!-- ADD THIS LINE -->
    package="com.microsoft.projectoxford.visionsample" >

    <!-- ... -->

    <library tools:node="removeAll" />
</manifest>


来源:https://stackoverflow.com/questions/47062866/android-studio-3-0-unknown-element-library-found

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