【问题标题】:Error after installing react-native-navigation安装 react-native-navigation 后出错
【发布时间】:2023-03-21 01:43:01
【问题描述】:

我已经按照这个链接安装了 react native navigation:

https://wix.github.io/react-native-navigation/#/installation-android

但我在运行 react-native run-android 后遇到错误 命令。

错误如下:

> Task :react-native-navigation:compileDebugJavaWithJavac
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
D8: Program type already present: android.support.design.widget.CoordinatorLayout$Behavior


FAILURE: Build failed with an exception.

我在安装 react native navigation 后尝试了 gradlew clen 命令。构建成功。也试过 multiDexEnabled true,但没有用。 我是本机反应新手,请帮助我解决此错误。

我的 MainApplication.java 文件如下所示:

包 com.prabhujidroid;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.util.List;

import com.reactnativenavigation.NavigationApplication;

public class MainApplication extends NavigationApplication {

    @Override
     public boolean isDebug() {
         // Make sure you are using BuildConfig from your own application
         return BuildConfig.DEBUG;
     }

     protected List<ReactPackage> getPackages() {
         // Add additional packages you require here
         // No need to add RnnPackage and MainReactPackage
         return Arrays.<ReactPackage>asList(
             // eg. new VectorIconsPackage()
             //new VectorIconsPackage()
         );
     }

     @Override
     public List<ReactPackage> createAdditionalReactPackages() {
         return getPackages();
     }

     @Override
    public String getJSMainModuleName() {
        return "index";
    }
}

android 文件夹中的 build.gradle 文件看起来很像 这个(android/build.gradle)

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 21
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
    }
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'

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

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


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

android/app 文件夹中的 build.gradle 文件如下所示:

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]

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

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

    compileSdkVersion 25
    buildToolsVersion "25.0.1"

    defaultConfig {
        multiDexEnabled true
        applicationId "com.prabhujidroid"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // 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]
            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
            }
        }
    }
}

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

    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"
    compile project(':react-native-navigation')
}

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

包,json文件放在这里。

    {
  "name": "rn-course",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "babel-preset-react-native-stage-0": "^1.0.1",
    "jest": "^23.6.0",
    "jest-react-native": "^18.0.0",
    "react-test-renderer": "16.3.1"
  },
  "scripts": {
    "start": "react-native start",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "test": "jest"
  },
  "jest": {
    "preset": "react-native"
  },
  "dependencies": {
    "react": "16.3.1",
    "react-native": "~0.55.2",
    "react-native-navigation": "^1.1.486"
  }
}

【问题讨论】:

  • 请包含package.json 文件,以便我们查看您打算安装的软件包的版本。此外,包括已安装的 React Native 版本(如果与 package.json 中指定的不同)。此外,由于大多数软件包都在不断更新,因此请包括您要安装的 react-native-navigation 版本。最后,尝试在具有最新版本的react-nativereact-native-navigation 的新/干净的RN 项目上安装react-native-navigation,问题可能已经解决。
  • 好的,我正在尝试重新安装它。
  • 同样的事情发生了。我包括 package.json 文件
  • 谁能帮我解决这个问题?我真的被困住了。
  • 您可以尝试通过react-native link再次将库链接到本机并编译

标签: react-native wix-react-native-navigation


【解决方案1】:

最后我解决了。依赖项应该是这样的。

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:23.0.1" <----- should be same
    implementation "com.facebook.react:react-native:+"  // From node_modules

    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1" <------ should be same
    compile "com.facebook.react:react-native:+"
    compile project(':react-native-navigation')
}

对我来说不一样

【讨论】:

    猜你喜欢
    • 2022-12-22
    • 1970-01-01
    • 1970-01-01
    • 2020-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多