任务“:react-native-webview:compileDebugKotlin”执行失败

Vl *_*yan 11 android webview gradle react-native react-native-webview

使用 RN 更新助手将 React Native 从 0.61.2 升级到 0.68.2 后,gradle 无法构建应用程序。出现此错误

失败:构建失败并出现异常。

  • 出了什么问题:任务“:react-native-webview:compileDebugKotlin”执行失败。

java.io.IOException:权限被拒绝

尝试所有react-native-webview版本,但结果是相同的。

当我从 package.json 文件中删除 "react-native-webview": "^8.0.3" 这行然后构建成功,但应用程序出现错误,因为应用程序中使用了此依赖项

下面是我使用的依赖版本。

  1. “反应”:“17.0.2”,
  2. “反应本机”:“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
Run Code Online (Sandbox Code Playgroud)

Md.*_*lah 24

如果您从 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"
+               }
+           }
+       }
        // ...
    }
}
Run Code Online (Sandbox Code Playgroud)

此修复将应用一个排他内容解析规则,该规则将强制 React Native Android 库的解析,以使用 node_modules 内的解析。

将应用程序更新到 React Native v0.71.0 后,将不再需要此修复。

修复旧版反应原生 (< 0.63)

上述修复仅适用于 gradle 6.2 及更高版本。较旧的 React-Native 使用较旧的 gradle。

您可以通过查看/android/gradle/wrapper/gradle-wrapper.properties文件来确定您的 gradle 版本。

如果您使用的是使用 gradle 版本 6.1 或更低版本的旧版 React-Native(例如 0.63 或更早版本),则必须使用不同的解决方法,详细信息如下:#35210(评论)

更新于 2022 年 11 月 11 日

如果上述解决方案不适合您,请尝试此解决方案。

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
        }
    }
    // ...
}
Run Code Online (Sandbox Code Playgroud)


小智 4

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

sudo ./gradlewcompileDebugKotlin

这对我有用。