Ошибка сборки React-родной сборки Android, несоответствие версии компонента react-собственного модуля и версии среды выполнения

#react-native #gradle #react-native-web

#react-native #gradle #react-native-web

Вопрос:

Я создаю приложение для Android для отладки, скрипт запускается с cd ./android amp;amp; ./gradlew app:assembleDebug amp;amp; ./gradlew installDebug не использованием react-native run-android , потому что используется react-native-navigation v2 из рекомендуемого руководства RNN.

Но сборка завершается ошибкой с этой ошибкой.

 > 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
  

Кроме того, другие типы сборки (предварительный выпуск, релиз) не могут быть собраны с такой же ошибкой this.

Не могу понять, почему возникает эта ошибка, потому что она возникает после сборки версии 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' amp;amp; 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. можете ли вы удалить mavelCentral и mavelLocal из buildScript -> раздел репозитории и повторить попытку

2. @warl0ck не работает одинаково..

Ответ №1:

Я решил, и это просто произошло несоответствие версии RN, требующей компиляции, и версии компиляции моего code script.

Пожалуйста, проверьте свою версию RN и версию компиляции Android gradle, если кому-то, как и мне, трудно.