Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details

后端 未结 30 1475
野的像风
野的像风 2020-11-22 12:51

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         


        
相关标签:
30条回答
  • 2020-11-22 13:30

    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 AAPT1might 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>
    
    0 讨论(0)
  • 2020-11-22 13:30

    Check and try below things. Issue should be resolved.

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

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

    0 讨论(0)
  • 2020-11-22 13:33

    I had an error in my XML layout. So check your xml layout for errors.

    0 讨论(0)
  • 2020-11-22 13:34

    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
    
    0 讨论(0)
  • 2020-11-22 13:35

    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

    0 讨论(0)
  • 2020-11-22 13:36

    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.

    0 讨论(0)
提交回复
热议问题