首页 > 解决方案 > 尝试在 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'
}

我一直在尝试编译一天。这变得非常令人沮丧。

标签: androidreact-nativebuildsdk

解决方案


将此添加到项目 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 构建工具。


推荐阅读