You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native编译报错:找不到android:keyboardNavigationCluster属性求解决方案

解决React Native编译错误:找不到android:keyboardNavigationCluster属性

这个错误的核心原因很明确:你当前的compileSdkVersion是25,但项目中某个依赖库引入了API 26(Android 8.0)才新增的android:keyboardNavigationCluster属性,而编译SDK版本低于26时,AAPT工具无法识别这个属性,导致编译失败。

下面是一步到位的解决方案:

1. 升级编译SDK与构建工具版本

打开android/app/build.gradle,修改android块中的以下配置:

android {
    compileSdkVersion 26 // 从25升级到26
    buildToolsVersion "26.0.2" // 匹配compileSdkVersion的稳定构建工具版本
    defaultConfig {
        // ...其他配置保持不变
        targetSdkVersion 26 // 建议与compileSdkVersion保持一致,提升兼容性
        // ...其他配置保持不变
    }
    // ...其他配置保持不变
}

2. 更新支持库版本到匹配compileSdkVersion

同样在android/app/build.gradle的dependencies块中,更新AppCompat支持库版本,确保版本号与compileSdkVersion对应:

dependencies {
    // ...其他依赖保持不变
    compile "com.android.support:appcompat-v7:26.1.0" // 版本需与compileSdkVersion匹配
    // ...其他依赖保持不变
}

3. 升级Google Play Services与Firebase版本

你当前使用的10.0.1版本的Google Play Services和Firebase与API 26兼容性较差,建议升级到支持API 26的稳定版本(比如11.8.0):

dependencies {
    // ...其他依赖保持不变
    compile ("com.google.android.gms:play-services-base:11.8.0") { force = true; }
    compile ("com.google.android.gms:play-services-maps:11.8.0") { force = true; }
    compile ("com.google.android.gms:play-services-gcm:11.8.0") { force = true; }
    compile ('com.google.firebase:firebase-core:11.8.0') { force = true; }
    compile ('com.google.firebase:firebase-messaging:11.8.0') { force = true; }
    // ...其他依赖保持不变
}

4. 升级Gradle构建插件版本

打开android/build.gradle,更新buildscript中的gradle插件版本(旧版本2.2.3对API 26支持不足):

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3' // 从2.2.3升级到兼容API26的版本
        classpath 'com.google.gms:google-services:3.2.1' // 同步升级Google服务插件版本
    }
}

最后一步:清理并重新构建

完成上述修改后,执行以下操作确保生效:

  • 在Android Studio中点击「Sync Project with Gradle Files」同步配置
  • 在终端的android目录下执行清理命令:./gradlew clean
  • 重新编译项目

为什么这些修改能解决问题?

android:keyboardNavigationCluster是Android 8.0(API 26)系统新增的属性,只有当compileSdkVersion设置为26或更高时,Android编译工具才能识别并处理这个属性。同时,支持库、Google Play Services等依赖的版本必须与compileSdkVersion保持兼容,否则会引发新的版本冲突问题。

内容的提问来源于stack exchange,提问作者Leo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:16:21