简体   繁体   English

React Native 集成到现有的 android 项目

[英]React native integrate to existing android project

i'm trying react native integrate to existing android project but throwed below exception when build project in android studio.我正在尝试将本机集成到现有的 android 项目,但在 android 工作室中构建项目时抛出异常。

Caused by: java.lang.Exception: React Native CLI failed to determine Android project configuration.原因:java.lang.Exception:React Native CLI 无法确定 Android 项目配置。 This is likely due to misconfiguration.这很可能是由于配置错误。 Config output: [root:/Users/muratoner/Desktop/backup/Sabanci.Projects/Mobile/hrweb-react-native/android, reactNativePath:/Users/muratoner/Desktop/backup/Sabanci.Projects/Mobile/hrweb-react-native/node_modules/react-native, dependencies:[:], commands:[], assets:[], platforms:[:], haste:[providesModuleNodeModules:[], platforms:[]], project:[:]] at ReactNativeModules.getReactNativeConfig(/Users/muratoner/Desktop/backup/Sabanci.Projects/Mobile/hrweb-react-native/node_modules/@react-native-community/cli-platform-android/native_modules.gradle:212) at ReactNativeModules$getReactNativeConfig.callCurrent(Unknown Source) at ReactNativeModules.(/Users/muratoner/Desktop/backup/Sabanci.Projects/Mobile/hrweb-react-native/node_modules/@react-native-community/cli-platform-android/native_modules.gradle:84) at native_modules_8dnp0y65ugw2tp4vo89t6lw0x.run(/Users/muratoner/Desktop/backup/Sabanci.Projects/Mobile/hrweb-react配置 output: [root:/Users/muratoner/Desktop/backup/Sabanci.Projects/Mobile/hrweb-react-native/android, reactNativePath:/Users/muratoner/Desktop/backup/Sabanci.Projects/Mobile/hrweb-react- native/node_modules/react-native,依赖项:[:],命令:[],资产:[],平台:[:],急速:[providesModuleNodeModules:[],平台:[]],项目:[:]]在 ReactNativeModules.getReactNativeConfig(/Users/muratoner/Desktop/backup/Sabanci.Projects/Mobile/hrweb-react-native/node_modules/@react-native-community/cli-platform-android/native_modules.gradle:212) 在 ReactNativeModules$ getReactNativeConfig.callCurrent(Unknown Source) at ReactNativeModules.(/Users/muratoner/Desktop/backup/Sabanci.Projects/Mobile/hrweb-react-native/node_modules/@react-native-community/cli-platform-android/native_modules.gradle :84) 在 native_modules_8dnp0y65ugw2tp4vo89t6lw0x.run(/Users/muratoner/Desktop/backup/Sabanci.Projects/Mobile/hrweb-react -native/node_modules/@react-native-community/cli-platform-android/native_modules.gradle:244) at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:91)... 148 more -native/node_modules/@react-native-community/cli-platform-android/native_modules.gradle:244) at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:91)...还有 148 个

React native package.json反应原生 package.json

{
  "name": "MyApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "yarn react-native start"
  },
  "dependencies": {
    "@react-native-community/cli-platform-android": "^3.0.3",
    "react": "^16.9.0",
    "react-native": "^0.61.5"
  }
}

android/build.gradle安卓/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
        // Add Maven repo
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        //classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        google()
        maven { url 'https://jitpack.io' }
        maven { 
            // All of React Native (JS, 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")
        }
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

android/settings.gradle安卓/settings.gradle

include ':app'

apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle");
applyNativeModulesSettingsGradle(settings);

android/app/build.gradle android/app/build.gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        maven { url 'https://plugins.gradle.org/m2/' }
    }

    dependencies {
    }
}

apply plugin: 'com.android.application'
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)


repositories {
    maven { url 'https://maven.google.com' }
}

android {
    compileSdkVersion 29
    buildToolsVersion '29.0.2'

    defaultConfig {
        applicationId "com.myapp.android"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 111
        versionName "1.1.1"
        multiDexEnabled true
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'

    implementation "com.facebook.react:react-native:+" // From node_modules
    implementation "org.webkit:android-jsc:+"
}

I was tried different methods but still same exception throwing.我尝试了不同的方法,但仍然抛出相同的异常。

Just add package name in your AndroidManifest.xml只需在您的 AndroidManifest.xml 中添加 package 名称

<manifest 
 xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="example"
>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在现有项目 startActivityForResult 和 onActivityResult android 上集成 git 项目 - Integrate git project on an existing project startActivityForResult and onActivityResult android 将Native android SDK集成到React-Native应用程序中 - Integrate Native android sdk into React-Native app 在android项目中集成Liblinphone 4 - Integrate Liblinphone 4 in android project 将本机应用程序与联系人集成 - Integrate an react native app with the contacts 从集成到现有 Android 应用程序中的 React Native 应用程序获取结果 - Get a result from a react native app integrated into an existing android app 无法将 Java 代码集成到我的 React Native 项目中 - 错误:类型不兼容:ReactApplicationContext 无法转换为 Activity - Unable to integrate java code to my react native project - error: incompatible types: ReactApplicationContext cannot be converted to Activity 如何将swagger集成到我现有的java项目中? - How to integrate swagger to my existing java project ? 在react-native项目中更改android和ios的条目文件路径 - Change entry file path of android and ios in react-native project React-Native 项目不会在 ios 或 android 上构建 - React-Native Project won't build on ios or android JAVA 错误:反应原生基本项目在 android 工作室中不起作用 - JAVA ERROR: React native basic project not working in android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM