android - 尝试在 React Native 中编译时出错:无法执行 aapt
问题描述
尝试在 React Native 中编译时出现此错误,我已在 27.0.3 中修复了 SDK 的版本,但它不起作用。对可能发生的事情有任何想法吗?
错误:
C:\Users\devan.gradle\caches\transforms-1\files-1.1\appcompat-v7-
27.1.1.aar\750a91892d2e2f437e111b8d6039bfbe\res\values-v24\values-v24.xml:3:5-157:AAPT:检索项目的父项时出错:找不到与给定名称匹配的资源 'android:TextAppearance.Material.Widget .Button.Borderless.Colored'。
C:\Users\devan.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\750a91892d2e2f437e111b8d6039bfbe\res\values-v24\values-v24.xml:4:5-135: AAPT :检索项目的父项时出错:找不到与给定名称“android:TextAppearance.Material.Widget.Button.Colored”匹配的资源。
C:\Users\devan.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\750a91892d2e2f437e111b8d6039bfbe\res\values-v26\values-v26.xml:13:5-16:13 :AAPT:找不到与给定名称匹配的资源:attr 'android:keyboardNavigationCluster'。
FAILURE: Build failed with an exception.
- 出了什么问题:任务':react-native-orientation:verifyReleaseResources'执行失败。com.android.ide.common.process.ProcessException:无法执行 aapt
我的 build.gradle:
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.yojma"
minSdkVersion 21
targetSdkVersion 27
versionCode 3
versionName "3.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
compile project(':react-native-orientation')
compile project(':react-native-video')
compile project(':react-native-vector-icons')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:27.0.3"
implementation "com.facebook.react:react-native:+" // From node_modules
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
我一直在尝试编译一天。这变得非常令人沮丧。
解决方案
将此添加到项目 gradle 文件中为我解决了这个问题:
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion 27
buildToolsVersion "27.1.1"
}
}
}
}
按照这里的建议React native Android Generate Signed APK 给出资源错误,迫使 android 子项目使用 gradle 构建工具 27。我的假设是您项目中的某些库正在使用构建工具版本 26 或更低版本,这会生成损坏的 apk。例如,我会检查 react-native-orientation ':react-native-orientation:verifyReleaseResources' 的 gradle 构建工具。
推荐阅读
- python - 在子列表的大树中查找特定值
- karma-jasmine - Angular 11 茉莉花测试 NullInjectorError:没有 HttpClient 的提供者!即使添加了 HttpClientTestingModule
- docker - elasticsearch gke上的错误imagepullbackoff
- python - 如何让 Python 脚本在 Windows 10 上打开和执行?
- haskell - 如何连接和打印整数列表?
- django - SerializerMethodField 的 DRF Serializer 访问值
- bazel - bazel 在不同的测试目标之间共享文件
- javascript - 如何使用 Javascript 永久突出显示?
- azure - Azure BlobStorage 连接器无法连接到启用防火墙的 blob
- mysql - 如何在数据库中查询以检查 Groovy 中是否存在 Phrase 这个字符