gpt4 book ai didi

react-native build android failed mismatch react-native模块编译版本和运行时版本错误

转载 作者:行者123 更新时间:2023-12-03 05:37:19 25 4
gpt4 key购买 nike

我构建 android 应用程序进行调试,脚本运行cd ./android && ./gradlew app:assembleDebug && ./gradlew installDebug不使用 react-native run-android因为使用来自 RNN recommend guide 的 react-native-navigation v2 .

但是,构建失败并出现此错误。

> Configure project :react-native-navigation
downloadRobolectricDependencies into /Users/ddinggu/test/android/build/robolectric-3.5.1-dependencies

> Configure project :react-native-webview
:react-native-webview:reactNativeAndroidRoot /Users/ddinggu/test/node_modules/react-native/android
> Task :app:preReleaseBuild FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preReleaseBuild'.
> Android dependency 'com.facebook.react:react-native' has different version for the compile (0.58.4) and runtime (0.20.1) classpath.
You should manually set the same version via DependencyResolution

此外,其他构建类型(preRelease,release)无法构建相同的此错误。

不能指望为什么会出现这个错误,因为它发生在构建发布版本 android apk 之后并且没有更改任何 android 代码。

请任何提示您所知道的。

安卓配置
  • 安卓/app/build.gradle
  • project.ext.react = [
    entryFile: "index.js"
    ]

    apply from: "../../node_modules/react-native/react.gradle"

    // React-native-vectoricons
    project.ext.vectoricons = [
    iconFontNames: [ 'EvilIcons.ttf', 'Entypo.ttf' ] // Name of the font files you want to copy
    ]

    apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

    /**
    * Set this to true to create two separate APKs instead of one:
    * - An APK that only works on ARM devices
    * - An APK that only works on x86 devices
    * The advantage is the size of the APK is reduced by about 4MB.
    * Upload all the APKs to the Play Store and people will download
    * the correct one based on the CPU architecture of their device.
    */
    def enableSeparateBuildPerCPUArchitecture = false

    /**
    * Run Proguard to shrink the Java bytecode in release builds.
    */
    def enableProguardInReleaseBuilds = false

    android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
    applicationId "com.chopchopclient"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    missingDimensionStrategy "RNN.reactNativeVersion", "reactNative57_5"
    versionCode 16
    versionName "1.1.1"
    }

    signingConfigs {
    release {
    if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
    storeFile file(MYAPP_RELEASE_STORE_FILE)
    storePassword MYAPP_RELEASE_STORE_PASSWORD
    keyAlias MYAPP_RELEASE_KEY_ALIAS
    keyPassword MYAPP_RELEASE_KEY_PASSWORD
    }
    }
    }

    compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }

    splits {
    abi {
    reset()
    enable enableSeparateBuildPerCPUArchitecture
    universalApk false // If true, also generate a universal APK
    include "armeabi-v7a", "x86", "arm64-v8a"
    }
    }

    subprojects { subproject ->
    afterEvaluate {
    if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
    android {
    variantFilter { variant ->
    def names = variant.flavors*.name
    if (names.contains("reactNative51") || names.contains("reactNative55")) {
    setIgnore(true)
    }
    }
    }
    }
    }
    }

    buildTypes {
    release {
    minifyEnabled enableProguardInReleaseBuilds
    proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"

    signingConfig signingConfigs.release
    }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
    variant.outputs.each { output ->
    // For each separate APK per architecture, set a unique version code as described here:
    // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
    def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3]
    def abi = output.getFilter(OutputFile.ABI)
    if (abi != null) { // null for the universal-debug, universal-release variants
    output.versionCodeOverride =
    versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
    }
    }
    }
    }

    // resolve problem : transformDexArchiveWithExternalLibsDexMergerForDebug
    configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    def requested = details.requested
    if (requested.group == 'com.android.support' && requested.name != 'multidex') {
    details.useVersion "${rootProject.ext.supportLibVersion}"
    }
    }
    }

    dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+" // From node_modules
    implementation project(':react-native-navigation')
    implementation project(':react-native-inappbrowser-reborn')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-device-info')
    implementation project(':react-native-webview')
    implementation project(':react-native-splash-screen')
    implementation project(':react-native-version-check')
    }

    // Run this once to be able to run the application with BUCK
    // puts all compile dependencies into folder libs for BUCK to use
    task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
    }
  • 安卓/build.gradle
  • // Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {
    ext {
    buildToolsVersion = "28.0.2"
    minSdkVersion = 19
    compileSdkVersion = 27
    targetSdkVersion = 28
    supportLibVersion = "28.0.0"
    }
    repositories {
    google()
    mavenLocal()
    mavenCentral()
    jcenter()
    }
    dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    }
    }

    allprojects {
    repositories {
    google()
    mavenCentral()
    mavenLocal()
    jcenter()
    maven {
    // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
    url "$rootDir/../node_modules/react-native/android"
    }
    maven { url 'https://jitpack.io' }
    }
    }

    task wrapper(type: Wrapper) {
    gradleVersion = '4.7'
    distributionUrl = distributionUrl.replace("bin", "all")
    }

    环境
    React Native Environment Info:
    System:
    OS: macOS High Sierra 10.13.6
    Binaries:
    Node: 10.14.2 - ~/.nvm/versions/node/v10.14.2/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v10.14.2/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
    Android SDK:
    API Levels: 23, 25, 26, 27, 28
    Build Tools: 23.0.1, 26.0.3, 27.0.3, 28.0.2, 28.0.3
    IDEs:
    Android Studio: 3.2 AI-181.5540.7.32.5056338
    npmPackages:
    react: ^16.8.4 => 16.8.4
    react-native: 0.58.4 => 0.58.4

    最佳答案

    我解决了,它只是与 RN 的 require 编译版本和我的代码脚本编译版本不匹配。

    如果有人像我一样辛苦,请检查您的 RN 版本和 android gradle 编译版本。

    关于react-native build android failed mismatch react-native模块编译版本和运行时版本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55163925/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com