好吧 网上资料一大堆 ,我就来记录我自己的坑吧。

国内提供的· http://reactnative.cn/docs/0.42/integration-with-existing-apps.html#content

还有一个填坑的:http://xujinyang.github.io/2016/09/13/%E8%A7%A3%E5%86%B3React-Native-Attached-DialogModule-to-host-with-pending-alert-but-no-FragmentManager/

好吧 我的坑s google了一中午 哎我的青春..

1.index.android.js文件 注意红色位置

'use strict';

import React,{
    Component
} from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';

class HelloWorld extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.hello}>Hello, Soong  sad</Text>
      </View>
    )
  }
}
var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
  },
  hello: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
});

AppRegistry.registerComponent('HelloWorld', () => HelloWorld);

2.废话补多少 直接粘上app的build.gradle

一开始依赖是添加不上去的 因为在as的project structure 里面搜到最新的是0.20.0 但是现在最新的是0.40.2  填+ 就是最新的(可以去控制台 npm info react-native查看)

是永久版本的结果解释在嵌入的Activity方法中 mReactinasanceManager.onHostPause等方法找不到 运行后也打不开相应的界面

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.anytest.soong.helloworld2"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.facebook.react:react-native:+'
}

 3.project的build.gradle文件 添加代码 强制使用指定版本

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

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'

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

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

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





Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐