当前位置: 首页 > 知识库问答 >
问题:

react-本机构建android失败不匹配react-本机模块编译版本和运行时版本错误

步胜
2023-03-14

我构建用于调试的android应用程序,使用cd运行脚本。/android

但是,生成失败并出现此错误。

> 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

此外,其他生成类型(预发布、发布)无法生成相同的此错误。

无法预料为什么会出现此错误,因为它发生在构建发布版本android apk之后,并且没有更改任何android代码。

请提供任何提示,你知道什么。

Android配置

  • 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'
}
  • android/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

共有1个答案

葛烨
2023-03-14

我解决了这个问题,它只是与RN的要求编译版本和我的代码脚本编译版本不匹配。

请检查您的 RN 版本和Android gradle 编译版本,如果有人像我一样困难。

 类似资料:
  • 该应用程序运行良好,事实上我已经创建了两个版本的APK。这次我修改了代码,来做,我得到了以下错误: 失败:生成失败,出现异常。 哪里出错了:任务执行失败:app: mergeRelaseResources。 生成准备发布的健康APK。 我已经完成了签名和签名。密钥存储在正确的位置 以下是完整的stacktrace:

  • 单击此处查看错误图像 我有这个错误,当我运行反应本机run-android在我的设备上,我怎么能修复它? 我运行这个: react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --

  • 当我初始化一个新项目,然后启动Xcode仿真器时,会得到以下消息: React-本机版本不匹配 Javascript版本0.50.1本机版本:0.50.0 确保您已经重新构建了本机代码。... 有没有人知道这里发生了什么,可以帮助我?

  • 我在一个反应原生的应用程序,当我试图建立一个签署的版本,我得到这个错误: ps:buildToolsVersion=“28.0.3”minSdkVersion=21 compileSdkVersion=28 targetSdkVersion=28 supportLibVersion=“28.0.0”

  • D:\reactnative\awesomeproject>react-native run-android info运行jetifier将库迁移到AndroidX。您可以使用“--no-jetifier”标志禁用它。Jetifier找到863个文件要转发JEtify。使用4个工作者...信息正在启动JS服务器...信息正在启动仿真程序...错误:无法启动仿真程序。原因:未找到作为输出的仿真器。警

  • 将我的RN版本从0.61.0升级到0.61.2后,当我发布构建版本时,它显示错误信息< code>No bundle url present。然后,我从xcode中删除main.jsBundle,并使用该命令再次创建该文件 发布后构建“无捆绑错误”消失了,但在我的发布版本中没有本地图像或图标。 #React本机版本信息:CPU:(4)x64 Intel(R)Core(TM)i5-3470S CPU