com.android.builder.internal.aapt.v2.Aapt2Exception:android 3.2.1 SDK 28.0.3上的Android资源链接失败 [英] com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed on android 3.2.1 SDK 28.0.3

查看:120
本文介绍了com.android.builder.internal.aapt.v2.Aapt2Exception:android 3.2.1 SDK 28.0.3上的Android资源链接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已修订:升级到AS(3.2.1)和Gradle(4.6)后出现新错误.

REVISED: got a new error after upgrading to AS(3.2.1) and Gradle(4.6).

这是build.gradle代码. Gradle属性具有 android.enableAapt2 = true",并且包装器属性具有"distributionUrl = https://services.gradle.org/distributions/gradle-4.6-all.zip"

Here is build.gradle code. Gradle property has " android.enableAapt2 = true" and wrapper property has "distributionUrl=https://services.gradle.org/distributions/gradle-4.6-all.zip"

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/CHANGES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
    defaultConfig {
        applicationId "com.abc.app"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0.0"
        multiDexEnabled true
        testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "2048M"
    }
    configurations {
        all*.exclude module: 'mediarouter-v7'
        all*.exclude module: 'support-compat'
        compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
    }

    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation 'ch.acra:acra:4.9.1'

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:multidex:1.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:percent:28.0.0'

    implementation 'com.google.android.gms:play-services:10.2.1'
    implementation 'com.google.android.gms:play-services-gcm:10.2.1'
    implementation 'com.google.android.gms:play-services-ads:10.2.1'
    implementation 'com.google.android.gms:play-services-auth:10.2.1'

    implementation 'com.google.maps.android:android-maps-utils:0.3.+'
    implementation 'de.hdodenhof:circleimageview:1.3.0'
    implementation 'com.jakewharton:butterknife:8.5.1'
    implementation 'com.uber.sdk:rides-android:0.5.3'
    implementation 'com.google.code.gson:gson:2.8.1'
    implementation 'org.jsoup:jsoup:1.11.3'
    testImplementation 'junit:junit:4.12'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}


apply plugin: 'com.google.gms.google-services'

新错误是

    Caused by: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed

C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_btn_colored_text_material.xml:20: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_btn_checkable.xml:19: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_default.xml:19: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_edittext.xml:19: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_seek_thumb.xml:19: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_spinner.xml:19: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_switch_track.xml:19: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_switch_track.xml:20: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_switch_track.xml:21: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\design-28.0.0.aar\d2abd1d1eab13b237ffd0fc5d63d6820\res\color\design_tint_password_toggle.xml:19: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media.xml:23: error: resource layout/notification_template_icon_group (aka com.abc.app:layout/notification_template_icon_group) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media.xml:23: error: resource dimen/notification_large_icon_height (aka com.abc.app:dimen/notification_large_icon_height) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media.xml:23: error: resource dimen/notification_large_icon_width (aka com.abc.app:dimen/notification_large_icon_width) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media.xml:34: error: resource dimen/notification_large_icon_width (aka com.abc.app:dimen/notification_large_icon_width) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media.xml:34: error: resource dimen/notification_large_icon_width (aka com.abc.app:dimen/notification_large_icon_width) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media_custom.xml:23: error: resource layout/notification_template_icon_group (aka com.abc.app:layout/notification_template_icon_group) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media_custom.xml:23: error: resource dimen/notification_large_icon_height (aka com.abc.app:dimen/notification_large_icon_height) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media_custom.xml:23: error: resource dimen/notification_large_icon_width (aka com.abc.app:dimen/notification_large_icon_width) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media_custom.xml:34: error: resource dimen/notification_large_icon_height (aka com.abc.app:dimen/notification_large_icon_height) not found.

尝试了许多解决方案,包括使缓存无效/重新启动,关闭和导入项目,删除缓存文件,重新安装Android Studio,清理和升级;重建.它们都无法使项目成功构建.

Tried many solutions including Invalidate Caches/Restart, Close and Import Project, remove cache file, reinstall Android Studio, Clean & Rebuild. None of them could make the project build successfully.

还有其他可能的解决方案吗?

Any other possible solutions?

推荐答案

在找不到错误源的情况下,请尝试创建一个新项目,然后首先将您的.java文件复制到新项目,然后尝试复制您的layoutdrawable文件夹. 然后尝试在每次添加后逐个同步地将dependencies添加到build.gradle文件中,以查看是哪个引起了问题.

In such situations where you can't find the source of bug, try to create a new project and then first, only copy your .java files into the new project then, try to copy your layout and drawable folders. Then try to add your dependencies in the build.gradle file one by one syncing after each add to see which one is causing the problem.

我还要在您的build.gradle中提及一些建议:

Also I should mention some recommendations in your build.gradle:

首先将这一行移到顶部:

First move this line to the top:

apply plugin: 'com.google.gms.google-services'

apply plugin: 'com.android.application'

我还建议您迁移到Androidx而不是支持库.

Also I advise you to migrate to Androidx instead of Support libraries.

我也不再使用杰克沃顿的黄油刀.现在在Android中有View Binding.使用它:此处

Also I wouldn't use jakewharton's butterknife anymore. There is View Binding in Android now. use that: explained here

这篇关于com.android.builder.internal.aapt.v2.Aapt2Exception:android 3.2.1 SDK 28.0.3上的Android资源链接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆