任务 ':react-native-webview:compileDebugKotlin' 的执行失败



使用RN update helper将react native从0.61.2升级到0.68.2后,gradle无法构建应用程序。得到此错误

FAILURE: Build failed with a exception.

  • 哪里出错了:任务':react-native-webview:compileDebugKotlin'执行失败。

. io .IOException: Permission denied

尝试了所有react-native-webview版本,但结果都是一样的。

当我删除"react-native-webview"; "^8.0.3"这一行来自包装。Json文件然后构建成功,但是app得到错误,因为这个依赖项在app

中使用

  1. "react"17.0.2",
  2. "react-native"0.68.2",
  3. "@babel/core":"^ 7.12.9",
  4. "@babel/runtime":"^ 7.12.5",
  5. "@react-native-community/eslint-config":"^ 2.0.0",
  6. "babel-jest"^ 26.6.3",
  7. "eslint"^ 7.32.0",

distributionUrl = https://services.gradle.org/distributions/gradle-7.3.3-all.zip

android/build.gralde

buildscript {
ext {
buildToolsVersion = "31.0.0"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
if (System.properties['os.arch'] == "aarch64") {
// For M1 Users we need to use the NDK 24 which added support for aarch64
ndkVersion = "24.0.8215888"
} else {
// Otherwise we default to the side-by-side NDK version from AGP.
ndkVersion = "21.4.7075529"
}
}
dependencies {
classpath("com.android.tools.build:gradle:7.0.4")
classpath 'com.google.gms:google-services:4.3.8'
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("de.undercouch:gradle-download-task:4.1.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

如果你从2022年11月4日开始面临这个问题,

修复react-native>= 0.63和小于0.67的问题

android/buld.gradle文件中

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
// ...
}

allprojects {
repositories {
+       exclusiveContent {
+           // We get React Native's Android binaries exclusively through npm,
+           // from a local Maven repo inside node_modules/react-native/.
+           // (The use of exclusiveContent prevents looking elsewhere like Maven Central
+           // and potentially getting a wrong version.)
+           filter {
+               includeGroup "com.facebook.react"
+           }
+           forRepository {
+               maven {
+                   // NOTE: if you are in a monorepo, you may have "$rootDir/../../../node_modules/react-native/android"
+                   url "$rootDir/../node_modules/react-native/android"
+               }
+           }
+       }
// ...
}
}

这个修复将做的是应用一个排他内容解析规则,强制React Native Android库的解析,使用node_modules中的解析。

一旦你更新你的应用到React Native v0.71.0,这个修复将不再需要了。

修复旧的react-native (<0.63)

上面的修复只适用于gradle 6.2及更高版本。旧的react-native使用旧的gradle。

你可以通过查看/android/gradle/wrapper/gradle-wrapper来确定你的gradle版本。属性文件。

如果你使用的是旧的react-native(例如0.63或更早),使用gradle 6.1或以下版本,你必须使用不同的解决方案,详细信息如下:#35210(注释)

更新于11/11/2022

如果上面的解决方案对你不起作用,那么试试这个。

android/buld.gradle文件中

def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects {
configurations.all {
resolutionStrategy {
// Remove this override in 0.66, as a proper fix is included in react-native itself.
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
// ...
}

尝试在android文件夹上运行这个命令。

sudo ./gradlew compileDebugKotlin

这对我很有用。

android/buld.gradle文件中,您必须指定kotlinVersion为"1.6.0";

buildscript {
ext {
//... other fields
kotlinVersion = "1.6.0" //1 <- here is solution
RNNKotlinVersion = kotlinVersion //2 <- here is solution
}
dependencies {
// kotlinVersion you have defined above dot this to koltin version // solution next line
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")//3 <- here is solution

}
}

如果你不想在你的项目中使用,那么通过uninstall lib不仅从package.json中删除它

npm uninstall react-native-webview

如果您想使用,请更新到最新版本:

"react-native-webview": "^11.17.2",

ios:

删除并重新安装pod

cd ios && pod install

为Android:删除构建并重新构建它

希望它能起作用!

升级你的react native版本可以工作0.63.X = 0.63.50.65.X到0.65.30.66.X到0.66.50.68.X到0.68.50.69.X到0.69.70.70.X = 0.700.5

您可以在android/build中尝试以下设置。gradle文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
kotlin_version = '1.6.10'
}
repositories {
mavenCentral()
google()
jcenter()
maven { url "https://dl.bintray.com/android/android-tools/"  }
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.2")
classpath 'com.google.gms:google-services:4.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// Add the Crashlytics Gradle plugin (be sure to add version
// 2.0.0 or later if you built your app with Android Studio 4.1).
//         classpath 'com.google.firebase:firebase-crashlytics-gradle:2.3.0'
//          classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
}
}
allprojects {
repositories {
exclusiveContent {
// We get React Native's Android binaries exclusively through npm,
// from a local Maven repo inside node_modules/react-native/.
// (The use of exclusiveContent prevents looking elsewhere like Maven Central
// and potentially getting a wrong version.)
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
// NOTE: if you are in a monorepo, you may have "$rootDir/../../../node_modules/react-native/android"
url "$rootDir/../node_modules/react-native/android"
}
}
}
mavenCentral()
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../../../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../../../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}

我使用的是react-native版本0.64.0,然后基于这个问题,我升级到0.64.4,现在一切都很好。

这是问题解决方案中有用的部分:

📢>= 0.63的补丁我们已经为所有主要的带有hotfix的react-native版本:

🛳0.70.5:https://github.com/facebook/react-native/releases/tag/v0.70.5🛳️0.69.7: https://github.com/facebook/react-native/releases/tag/v0.69.7网络版0.68.5:https://github.com/facebook/react-native/releases/tag/v0.68.5🛳️0.67.5: https://github.com/facebook/react-native/releases/tag/v0.67.5网络版️0.66.5:https://github.com/facebook/react-native/releases/tag/v0.66.5🛳️0.65.3: https://github.com/facebook/react-native/releases/tag/v0.65.3网络版️0.64.4:https://github.com/facebook/react-native/releases/tag/v0.64.4🛳️0.63.5: https://github.com/facebook/react-native/releases/tag/v0.63.5

通过更新到这些补丁版本,您的Android构建应该开始工作了。

这样做,在您的包中。Json将react-native的版本更改为相关的新补丁(例如,如果您在0.64.3上,请更改为0.64.4)和运行yarn install。不需要其他更改,但您可能会这样做想要用CD清理你的机器人工件吗?。/gradlew在尝试重新运行Android应用程序之前清理。

相关内容

最新更新