我试图用react-native插件在react native上创建一个新项目,但我想知道为什么会抛出这个异常(我假设与正在使用的JDK或类似的东西有关)
例外情况是:
无法确定null的依赖项。无法解析配置“:classpath”的所有任务依赖项。>无法解析com.android.tools.build:gradle:8.1.1。
这是我的建筑。gradle
buildscript {
ext {
buildToolsVersion = "33.0.0"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 33
ndkVersion = "23.1.7779620"
}
repositories {
google()
mavenCentral()
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_X
targetCompatibility JavaVersion.VERSION_X
}
dependencies {
classpath("com.android.tools.build:gradle:8.1.1")
classpath("com.facebook.react:react-native-gradle-plugin")
}
}
字符串
在我的应用程序文件夹中
apply plugin: "com.android.application"
apply plugin: "com.facebook.react"
react {
}
def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
namespace "com.firstrnapp"
defaultConfig {
applicationId "com.firstrnapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}
buildscript {
buildToolsVersion = "33.0.0"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 33
ndkVersion = "23.1.7779620"
kotlinVersion = "1.8.0"
androidXBrowser = "1.4.0"
}
repositories {
google()
jcenter()
}
dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
classpath('com.android.tools.build:gradle:8.1.1')
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
implementation jscFlavor
}
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
型
1条答案
按热度按时间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在项目的根文件夹中打开终端并运行以下命令:
cd android
gradlew --stop
-确保它停止而不提示错误-gradlew
-它应该说构建成功-gradlew clean
-它应该说构建成功-1.就是这样,你只需要使用
cd ..
回到根文件夹,然后使用npm start
运行项目。