>无法确定null的依赖项,无法解析com.android.tools.build:gradle:8.1.1

vsdwdz23  于 2023-11-18  发布在  Android
关注(0)|答案(1)|浏览(307)

我试图用react-native插件在react native上创建一个新项目,但我想知道为什么会抛出这个异常(我假设与正在使用的JDK或类似的东西有关)
例外情况是:
无法确定null的依赖项。无法解析配置“:classpath”的所有任务依赖项。>无法解析com.android.tools.build:gradle:8.1.1。
这是我的建筑。gradle

  1. buildscript {
  2. ext {
  3. buildToolsVersion = "33.0.0"
  4. minSdkVersion = 21
  5. compileSdkVersion = 33
  6. targetSdkVersion = 33
  7. ndkVersion = "23.1.7779620"
  8. }
  9. repositories {
  10. google()
  11. mavenCentral()
  12. }
  13. compileOptions {
  14. sourceCompatibility JavaVersion.VERSION_X
  15. targetCompatibility JavaVersion.VERSION_X
  16. }
  17. dependencies {
  18. classpath("com.android.tools.build:gradle:8.1.1")
  19. classpath("com.facebook.react:react-native-gradle-plugin")
  20. }
  21. }

字符串
在我的应用程序文件夹中

  1. apply plugin: "com.android.application"
  2. apply plugin: "com.facebook.react"
  3. react {
  4. }
  5. def enableProguardInReleaseBuilds = false
  6. def jscFlavor = 'org.webkit:android-jsc:+'
  7. android {
  8. ndkVersion rootProject.ext.ndkVersion
  9. compileSdkVersion rootProject.ext.compileSdkVersion
  10. namespace "com.firstrnapp"
  11. defaultConfig {
  12. applicationId "com.firstrnapp"
  13. minSdkVersion rootProject.ext.minSdkVersion
  14. targetSdkVersion rootProject.ext.targetSdkVersion
  15. versionCode 1
  16. versionName "1.0"
  17. }
  18. signingConfigs {
  19. debug {
  20. storeFile file('debug.keystore')
  21. storePassword 'android'
  22. keyAlias 'androiddebugkey'
  23. keyPassword 'android'
  24. }
  25. }
  26. buildTypes {
  27. debug {
  28. signingConfig signingConfigs.debug
  29. }
  30. release {
  31. // Caution! In production, you need to generate your own keystore file.
  32. // see https://reactnative.dev/docs/signed-apk-android.
  33. signingConfig signingConfigs.debug
  34. minifyEnabled enableProguardInReleaseBuilds
  35. proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
  36. }
  37. }
  38. }
  39. buildscript {
  40. buildToolsVersion = "33.0.0"
  41. minSdkVersion = 21
  42. compileSdkVersion = 33
  43. targetSdkVersion = 33
  44. ndkVersion = "23.1.7779620"
  45. kotlinVersion = "1.8.0"
  46. androidXBrowser = "1.4.0"
  47. }
  48. repositories {
  49. google()
  50. jcenter()
  51. }
  52. dependencies {
  53. // The version of react-native is set by the React Native Gradle Plugin
  54. implementation("com.facebook.react:react-android")
  55. classpath('com.android.tools.build:gradle:8.1.1')
  56. debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
  57. debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
  58. exclude group:'com.squareup.okhttp3', module:'okhttp'
  59. }
  60. debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
  61. if (hermesEnabled.toBoolean()) {
  62. implementation("com.facebook.react:hermes-android")
  63. } else {
  64. implementation jscFlavor
  65. }
  66. }
  67. apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

xkftehaa

xkftehaa1#

在安装最新的React Native 0.72和最新的Android Studio之后Android Studio Giraffe| 2022.3.1补丁2,我得到了非常类似的问题.
虽然我不能100%确定问题的确切来源,但我通过执行以下操作修复了它
第一名:设置正确的JAVA_HOME路径到最新的JDK你有.你可以运行此命令打开环境变量编辑器在windows 10终端/CMD:rundll32.exe sysdm.cpl,EditEnvironmentVariables.然后,添加/编辑JAVA_HOME变量像这样:
x1c 0d1x的数据
此外,我曾经有多个Java版本的路径,我删除了所有的主题从路径!

2在项目运行npx react-native doctor的根文件夹中,它显示了一些有用的信息,如下所示:


  • 注意,我在这里点击了e。我不知道它是否帮助我解决了这个问题 *

3根据这一点,我必须确保安装Android SDK命令行工具版本33.0.0。-注意这个数字可以根据您使用的React版本而有所不同-打开Android Studio Tools->SDK Manager->SDK Tools Tab。

启用“显示程序包详细信息”复选框。



下载SDK命令行工具的正确版本,在我的情况下是33.0.0:


4关闭所有打开的终端/CMD窗口。

5在项目的根文件夹中打开终端并运行以下命令:

  • 5.1 cd android
  • 5.2 gradlew --stop-确保它停止而不提示错误-
  • 5.3 gradlew-它应该说构建成功-
  • 5.4 gradlew clean-它应该说构建成功-

1.就是这样,你只需要使用cd ..回到根文件夹,然后使用npm start运行项目。

展开查看全部

相关问题