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

disho6za  于 2022-11-14  发布在  React
关注(0)|答案(5)|浏览(216)

使用RN更新助手将react native从0.61.2升级到0.68.2后,Gradle无法构建应用程序。
失败:生成失败,出现异常.

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

java.io.IOException:权限被拒绝
尝试所有react-native-webview版本,但结果相同。
当我删除“react-native-webview”时:package.json文件中的“^8.0.3”此行,然后生成成功,但应用程序出现错误,因为应用程序中使用了此依赖项
在我使用的相依性版本之下。
1.“React”:“17.0.2”,
1.“原生React”:“0.68.2”,
1.“@巴别塔/核心”:“^7.12.9”,
1.“@巴别塔/运行时”:“^7.12.5”,
1.“@React本地社区/eslint配置”:“^2.0.0”,
1.“胡言乱语”:“^26.6.3”,
1.“eslint文件”:“^7.32.0,”
发布网址=https:services.gradle.org/distributions/gradle-7.3.3-all.zip
android/构建版本.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
ktca8awb

ktca8awb1#

如果您在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"
+               }
+           }
+       }
        // ...
    }
}

此修复程序将应用一个exclusiveContent解析规则,强制解析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.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
        }
    }
    // ...
}
fae0ux8s

fae0ux8s2#

尝试在android文件夹上运行此命令。
sudo ./gradlew编译调试代码
这对我很有效。

z2acfund

z2acfund3#

如果您不想在项目中使用,则不仅要从package.json中卸载lib,

npm uninstall react-native-webview

如果您要使用,请将其更新为最新版本:

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

对于ios:

删除Pod并重新安装Pod

cd ios && pod install

**对于Android:**删除构建并重新构建

希望它能起作用!

tcomlyy6

tcomlyy64#

升级您的react原生版本可以从0.63.x升级到0.63.5 0.65.x升级到0.65.3 0.66.x升级到0.66.5 0.68.x升级到0.68.5 0.69.x升级到0.69.7 0.70.x升级到0.70.5

dl5txlt9

dl5txlt95#

您可以在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' }
    }
}

相关问题