新建项目报错 > Task :app:processDebugResources FAILED Execution failed for task
具体报错:
Task :app:processDebugResources FAILED Execution failed for task ‘:app:processDebugResources’. > A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction > Android resource linking failed error: failed to open APK: Invalid file.
百度了很久,只说了了gradle的版本对应不上,没有别的提示,所以只能按照可以运行的就想买设置
buildscript {
ext {
agp_version = '7.4.2'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.0.1' apply false
id("org.jetbrains.kotlin.android") version "1.6.21" apply false
}
defaultConfig {
applicationId "com.example.testwebsocket"
minSdk 28
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
然后又报错:
issues were found when checking AAR metadata:1. Dependency ‘androidx.appcompat:appcompat-resources:1.6.1’ requires libraries and applications that
depend on it to compile against version 33 or later of the
Android APIs. :app is currently compiled against android-31.
Recommended action: Update this project to use a newer compileSdkVersion
of at least 33, for example 33.
Note that updating a library or application’s compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
on).
Dependency ‘androidx.appcompat:appcompat:1.6.1’ requires libraries and applications that
depend on it to compile against version 33 or later of the
Android APIs.
:app is currently compiled against android-31.
Recommended action: Update this project to use a newer compileSdkVersion
of at least 33, for example 33.
Note that updating a library or application’s compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
on).
minSdkVersion (which determines which devices the app can be installed
换到旧依赖代码
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.appcompat:appcompat-resources:1.4.0'
implementation 'androidx.emoji2:emoji2-views-helper:1.1.0'
implementation 'androidx.emoji2:emoji2:1.1.0'
implementation 'androidx.core:core:1.6.0'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.annotation:annotation-experimental:1.1.0'
implementation 'com.google.android.material:material:1.5.0'
// 其他依赖...
}
最后又报资源问题:
Execution failed for task ‘:app:processDebugResources’.
A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
Android resource linking failed
com.example.testwebsocket.app-mergeDebugResources-16:/values/values.xml:1723: error: resource attr/colorPrimaryVariant (aka com.example.testwebsocket:attr/colorPrimaryVariant) not found.
error: resource style/Theme.MaterialComponents.DayNight.DarkActionBar (aka com.example.testwebsocket:style/Theme.MaterialComponents.DayNight.DarkActionBar) not found.
解决:针对不对的地方进行添加,再重新构建即可