React Native Android构建报错:无法找到io.jsonwebtoken:jjwt-api:0.10.7
React Native Android 构建错误:
:app:compileDebugJavaWithJavac 依赖解析失败 此前项目构建正常,甚至成功执行过./gradlew bundleRelease,修复了:app:checkDebugDuplicateClasses错误后,现在出现:app:compileDebugJavaWithJavac错误,核心问题是依赖解析失败,无法找到多个必要的依赖包。
当前项目配置
buildToolsVersion = "31.0.0" minSdkVersion = 21 compileSdkVersion = 31 targetSdkVersion = 31
具体错误信息
* What went wrong: Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'. > Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'. > Could not find io.jsonwebtoken:jjwt-api:0.10.7. Required by: project :app > project :@notifee_react-native project :app > project :notifee_react-native > Could not find com.google.guava:listenablefuture:1.0. Required by: project :app > androidx.browser:browser:1.5.0-rc01 > Could not find com.facebook.infer.annotation:infer-annotation:0.11.2. Required by: project :app > com.facebook.react:react-native:0.61.5 > Could not find javax.inject:javax.inject:1. Required by: project :app > com.facebook.react:react-native:0.61.5 > Could not find com.facebook.fresco:fresco:2.0.0. Required by: project :app > com.facebook.react:react-native:0.61.5 > Could not find com.facebook.fresco:imagepipeline-okhttp3:2.0.0. Required by: project :app > com.facebook.react:react-native:0.61.5 > Could not find com.facebook.soloader:soloader:0.6.0. Required by: project :app > com.facebook.react:react-native:0.61.5 > Could not find com.google.code.findbugs:jsr305:3.0.2. Required by: project :app > com.facebook.react:react-native:0.61.5 > Could not find com.squareup.okhttp3:okhttp:3.12.1. Required by: project :app > com.facebook.react:react-native:0.61.5 > Could not find com.squareup.okhttp3:okhttp-urlconnection:3.12.1. Required by: project :app > com.facebook.react:react-native:0.61.5 > Could not find com.squareup.okio:okio:1.15.0. Required by: project :app > com.facebook.react:react-native:0.61.5 > Could not find org.jetbrains.kotlin:kotlin-stdlib:1.8.0. Required by: project :app > androidx.annotation:annotation-jvm:1.6.0-beta01
当前buildscript配置
buildscript { ext { buildToolsVersion = "31.0.0" minSdkVersion = 21 compileSdkVersion = 31 targetSdkVersion = 31 kotlinVersion = "1.4.0" RNNKotlinVersion = kotlinVersion playServicesVersion = "16.0.0" googlePlayServicesVersion = "17.0.0" } repositories { google() maven { url 'https://maven.fabric.io/public' } mavenLocal() mavenCentral() } dependencies { classpath "com.android.tools.build:gradle:4.0.1" // after classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" classpath "com.google.gms:google-services:4.2.0" classpath "io.fabric.tools:gradle:1.+" classpath "io.jsonwebtoken:jjwt-api:0.10.7" } }
解决方案
1. 修正错误的依赖声明位置
io.jsonwebtoken:jjwt-api:0.10.7是应用依赖,不是Gradle插件依赖,需要从buildscript.dependencies中移除,将其添加到app模块的build.gradle的dependencies块中:
// app/build.gradle dependencies { // 其他依赖保持不变 implementation "io.jsonwebtoken:jjwt-api:0.10.7" implementation "io.jsonwebtoken:jjwt-impl:0.10.7" implementation "io.jsonwebtoken:jjwt-jackson:0.10.7" // 配套实现包,按需添加 }
2. 确保项目级仓库配置完整
在项目根目录的build.gradle中,检查allprojects.repositories是否包含所有必要的仓库,确保依赖能被正确拉取:
allprojects { repositories { google() mavenCentral() mavenLocal() maven { url "https://www.jitpack.io" } maven { url "https://maven.google.com" } // React Native 相关依赖仓库 maven { url "$rootDir/../node_modules/react-native/android" } maven { url "$rootDir/../node_modules/jsc-android/dist" } } }
3. 对齐Kotlin版本
错误中要求kotlin-stdlib:1.8.0,但当前配置的Kotlin插件版本是1.4.0,版本不匹配会导致依赖解析失败。将buildscript.ext.kotlinVersion改为1.8.0:
buildscript { ext { // 其他配置不变 kotlinVersion = "1.8.0" RNNKotlinVersion = kotlinVersion } // ... }
4. 清理缓存并重新构建
执行以下命令清理Gradle缓存,避免缓存导致的依赖问题:
./gradlew clean ./gradlew build --refresh-dependencies
5. 显式声明缺失的依赖(可选)
如果上述步骤后仍有依赖找不到,可以在app模块的build.gradle中显式添加所有缺失的依赖:
dependencies { // 补充缺失的依赖 implementation "com.google.guava:listenablefuture:1.0" implementation "com.facebook.infer.annotation:infer-annotation:0.11.2" implementation "javax.inject:javax.inject:1" implementation "com.facebook.fresco:fresco:2.0.0" implementation "com.facebook.fresco:imagepipeline-okhttp3:2.0.0" implementation "com.facebook.soloader:soloader:0.6.0" implementation "com.google.code.findbugs:jsr305:3.0.2" implementation "com.squareup.okhttp3:okhttp:3.12.1" implementation "com.squareup.okhttp3:okhttp-urlconnection:3.12.1" implementation "com.squareup.okio:okio:1.15.0" }
内容的提问来源于stack exchange,提问作者Suleiman Zhukov
相关产品推荐
相关产品推荐

