├── .watchmanconfig
├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ └── layout
│ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── kenny
│ │ └── embedded
│ │ ├── RNPackage.java
│ │ ├── ReactNativeActivity.java
│ │ ├── MainActivity.java
│ │ └── RNIntentModule.java
├── proguard-rules.pro
├── build.gradle
└── app.iml
├── settings.gradle
├── screenshot
├── 1.png
├── 2.png
├── 3.png
├── 4.png
└── 9.png
├── .buckconfig
├── package.json
├── local.properties
├── .gitignore
├── embedded.iml
├── gradle.properties
├── gradlew.bat
├── index.android.js
├── .flowconfig
├── README.md
└── gradlew
/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | !app.iml
3 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/screenshot/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kennytian/embedded/HEAD/screenshot/1.png
--------------------------------------------------------------------------------
/screenshot/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kennytian/embedded/HEAD/screenshot/2.png
--------------------------------------------------------------------------------
/screenshot/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kennytian/embedded/HEAD/screenshot/3.png
--------------------------------------------------------------------------------
/screenshot/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kennytian/embedded/HEAD/screenshot/4.png
--------------------------------------------------------------------------------
/screenshot/9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kennytian/embedded/HEAD/screenshot/9.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 植入原生应用
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kennytian/embedded/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kennytian/embedded/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kennytian/embedded/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kennytian/embedded/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kennytian/embedded/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.buckconfig:
--------------------------------------------------------------------------------
1 |
2 | [android]
3 | target = Google Inc.:Google APIs:23
4 |
5 | [maven_repositories]
6 | central = https://repo1.maven.org/maven2
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "EmbeddedApp",
3 | "version": "0.0.1",
4 | "private": true,
5 | "scripts": {
6 | "start": "node node_modules/react-native/local-cli/cli.js start"
7 | },
8 | "dependencies": {
9 | "react": "^0.14.7",
10 | "react-native": "^0.26.2"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | ## This file is automatically generated by Android Studio.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 | #
7 | # Location of the SDK. This is only used by Gradle.
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | #Tue May 31 10:10:02 CST 2016
11 | sdk.dir=D\:\\Development\\Android\\sdk
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # Xcode
6 | #
7 | build/
8 | *.pbxuser
9 | !default.pbxuser
10 | *.mode1v3
11 | !default.mode1v3
12 | *.mode2v3
13 | !default.mode2v3
14 | *.perspectivev3
15 | !default.perspectivev3
16 | xcuserdata
17 | *.xccheckout
18 | *.moved-aside
19 | DerivedData
20 | *.hmap
21 | *.ipa
22 | *.xcuserstate
23 | project.xcworkspace
24 |
25 | # Android/IJ
26 | #
27 | .idea
28 | .gradle
29 | local.properties
30 | gradle/
31 |
32 | # node.js
33 | #
34 | node_modules/
35 | npm-debug.log
36 |
37 | # BUCK
38 | buck-out/
39 | \.buckd/
40 | android/app/libs
41 | android/keystores/debug.keystore
42 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/kenny/Downloads/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.kenny.embedded"
9 | minSdkVersion 16
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | //注意:react-native 0.22.2 对应支持v7的版本是23.0.1
25 | compile "com.android.support:appcompat-v7:23.0.1"
26 | compile "com.facebook.react:react-native:0.20.+"
27 | }
28 |
--------------------------------------------------------------------------------
/embedded.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | android.useDeprecatedNdk=true
21 | org.gradle.jvmargs=-Xmx2048M
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kenny/embedded/RNPackage.java:
--------------------------------------------------------------------------------
1 | package com.kenny.embedded;
2 |
3 | import com.facebook.react.ReactPackage;
4 | import com.facebook.react.bridge.JavaScriptModule;
5 | import com.facebook.react.bridge.NativeModule;
6 | import com.facebook.react.bridge.ReactApplicationContext;
7 | import com.facebook.react.uimanager.ViewManager;
8 |
9 | import java.util.Arrays;
10 | import java.util.Collections;
11 | import java.util.List;
12 |
13 | /**
14 | * Created by kenny on 16/3/25.
15 | */
16 | public class RNPackage implements ReactPackage {
17 |
18 | @Override
19 | public List createNativeModules(ReactApplicationContext reactContext) {
20 | return Arrays.asList(
21 | new RNIntentModule(reactContext)
22 | );
23 | }
24 |
25 | @Override
26 | public List> createJSModules() {
27 | return Collections.emptyList();
28 | }
29 |
30 | @Override
31 | public List createViewManagers(ReactApplicationContext reactContext) {
32 | return Collections.emptyList();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
18 |
19 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kenny/embedded/ReactNativeActivity.java:
--------------------------------------------------------------------------------
1 | package com.kenny.embedded;
2 |
3 | import com.facebook.react.BuildConfig;
4 | import com.facebook.react.ReactActivity;
5 | import com.facebook.react.ReactPackage;
6 | import com.facebook.react.shell.MainReactPackage;
7 |
8 | import java.util.Arrays;
9 | import java.util.List;
10 |
11 | /**
12 | * Created by kenny on 16/3/24.
13 | */
14 | public class ReactNativeActivity extends ReactActivity {
15 | /**
16 | * Returns the name of the main component registered from JavaScript.
17 | * This is used to schedule rendering of the component.
18 | */
19 | @Override
20 | protected String getMainComponentName() {
21 | return "EmbeddedApp";
22 | }
23 |
24 |
25 | /**
26 | * Returns whether dev mode should be enabled.
27 | * This enables e.g. the dev menu.
28 | */
29 | @Override
30 | protected boolean getUseDeveloperSupport() {
31 | return BuildConfig.DEBUG;
32 | }
33 |
34 | /**
35 | * A list of packages used by the app. If the app uses additional views
36 | * or modules besides the default ones, add more packages here.
37 | */
38 | @Override
39 | protected List getPackages() {
40 | return Arrays.asList(
41 | new MainReactPackage(),
42 | new RNPackage()
43 | );
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kenny/embedded/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.kenny.embedded;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.widget.TextView;
9 |
10 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
11 |
12 | private TextView mReactValue = null;
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 |
19 | findViewById(R.id.tv_native).setOnClickListener(this);
20 | mReactValue = (TextView) findViewById(R.id.tv_react);
21 | }
22 |
23 | @Override
24 | public void onClick(View v) {
25 | Intent intent = new Intent(this, ReactNativeActivity.class);
26 | intent.putExtra("fromAndroid", "我是来自Android Intent的消息");
27 | startActivityForResult(intent, 0);
28 | }
29 |
30 | @Override
31 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
32 | super.onActivityResult(requestCode, resultCode, data);
33 | if (requestCode == 0 && data != null) {
34 | String result = data.getStringExtra("fromReact");
35 | mReactValue.setText(result);
36 | mReactValue.setTextColor(Color.RED);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kenny/embedded/RNIntentModule.java:
--------------------------------------------------------------------------------
1 | package com.kenny.embedded;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.text.TextUtils;
6 |
7 | import com.facebook.react.bridge.Callback;
8 | import com.facebook.react.bridge.ReactApplicationContext;
9 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
10 | import com.facebook.react.bridge.ReactMethod;
11 |
12 |
13 | /**
14 | * Created by kenny on 16/3/25.
15 | */
16 | public class RNIntentModule extends ReactContextBaseJavaModule {
17 |
18 | public RNIntentModule(ReactApplicationContext reactContext) {
19 | super(reactContext);
20 | }
21 |
22 | @Override
23 | public String getName() {
24 | return getClass().getSimpleName();
25 | }
26 |
27 | @ReactMethod
28 | public void getDataFromIntent(Callback successBack, Callback errorBack) {
29 | try {
30 | Activity currentActivity = getCurrentActivity();
31 | String result = currentActivity.getIntent().getStringExtra("fromAndroid");
32 | if (TextUtils.isEmpty(result)) {
33 | result = "注意:数据为空!";
34 | }
35 | successBack.invoke(result);
36 | } catch (Exception e) {
37 | errorBack.invoke(e.getMessage());
38 | }
39 | }
40 |
41 | @ReactMethod
42 | public void backActivity(int count) {
43 | if (count > 0) {
44 | try {
45 | Activity currentActivity = getCurrentActivity();
46 | currentActivity.finish();
47 | } catch (Exception e) {
48 | e.printStackTrace();
49 | }
50 | }
51 | }
52 |
53 |
54 | @ReactMethod
55 | public void finishActivity(String result) {
56 | try {
57 | Activity currentActivity = getCurrentActivity();
58 | Intent intent = new Intent();
59 | intent.putExtra("fromReact", result);
60 | currentActivity.setResult(0, intent);
61 | currentActivity.finish();
62 | } catch (Exception e) {
63 | e.printStackTrace();
64 | }
65 | }
66 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/index.android.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Sample React Native App
3 | * https://github.com/facebook/react-native
4 | */
5 |
6 | import React, {
7 | AppRegistry,
8 | Component,
9 | StyleSheet,
10 | TouchableOpacity,
11 | Text,
12 | View
13 | } from 'react-native';
14 |
15 | class EmbeddedApp extends Component {
16 | constructor(props){
17 | super(props);
18 |
19 | this.state = {
20 | text: 'Welcome to React Native!',
21 | navigateCount: 0
22 | };
23 | }
24 |
25 | componentWillMount() {
26 | if (React.Platform.OS === 'android') {
27 | React.BackAndroid.addEventListener('hardwareBackPress', ()=>this._backButton());
28 | }
29 | }
30 |
31 | _backButton(){
32 | const {navigateCount} = this.state;
33 | if (navigateCount) {
34 | React.NativeModules.RNIntentModule.backActivity(navigateCount)
35 | return true;
36 | }
37 | return false;
38 | }
39 |
40 | _clickButton(){
41 | React.NativeModules.RNIntentModule.finishActivity('我是来自React Native的消息');
42 | }
43 |
44 | render() {
45 | return (
46 |
47 |
48 | {this.state.text}
49 |
50 |
51 |
52 | 点击我,给Android Native点颜色看看
53 |
54 |
55 |
56 | Shake or press menu button for dev menu
57 |
58 |
59 | );
60 | }
61 |
62 | componentDidMount() {
63 | React.NativeModules.RNIntentModule.getDataFromIntent(
64 | successMsg => this.setState({text: successMsg, navigateCount: 1}),
65 | errorMsg => this.setState({text: errorMsg, navigateCount: 1})
66 | );
67 | }
68 |
69 | componentWillUnmount() {
70 | if (React.Platform.OS === 'android') {
71 | React.BackAndroid.removeEventListener('hardwareBackPress', ()=>this._backButton());
72 | }
73 | }
74 | }
75 |
76 | const styles = StyleSheet.create({
77 | container: {
78 | flex: 1,
79 | justifyContent: 'center',
80 | alignItems: 'center',
81 | backgroundColor: '#F5FCFF',
82 | },
83 | welcome: {
84 | fontSize: 20,
85 | textAlign: 'center',
86 | margin: 10,
87 | color: 'red'
88 | },
89 | instructions: {
90 | textAlign: 'center',
91 | color: '#333333',
92 | marginTop: 15,
93 | marginBottom: 5,
94 | fontSize: 14,
95 | },
96 | });
97 |
98 | AppRegistry.registerComponent('EmbeddedApp', () => EmbeddedApp);
99 |
--------------------------------------------------------------------------------
/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 |
3 | # We fork some components by platform.
4 | .*/*.web.js
5 | .*/*.android.js
6 |
7 | # Some modules have their own node_modules with overlap
8 | .*/node_modules/node-haste/.*
9 |
10 | # Ugh
11 | .*/node_modules/babel.*
12 | .*/node_modules/babylon.*
13 | .*/node_modules/invariant.*
14 |
15 | # Ignore react and fbjs where there are overlaps, but don't ignore
16 | # anything that react-native relies on
17 | .*/node_modules/fbjs/lib/Map.js
18 | .*/node_modules/fbjs/lib/ErrorUtils.js
19 |
20 | # Flow has a built-in definition for the 'react' module which we prefer to use
21 | # over the currently-untyped source
22 | .*/node_modules/react/react.js
23 | .*/node_modules/react/lib/React.js
24 | .*/node_modules/react/lib/ReactDOM.js
25 |
26 | .*/__mocks__/.*
27 | .*/__tests__/.*
28 |
29 | .*/commoner/test/source/widget/share.js
30 |
31 | # Ignore commoner tests
32 | .*/node_modules/commoner/test/.*
33 |
34 | # See https://github.com/facebook/flow/issues/442
35 | .*/react-tools/node_modules/commoner/lib/reader.js
36 |
37 | # Ignore jest
38 | .*/node_modules/jest-cli/.*
39 |
40 | # Ignore Website
41 | .*/website/.*
42 |
43 | # Ignore generators
44 | .*/local-cli/generator.*
45 |
46 | # Ignore BUCK generated folders
47 | .*\.buckd/
48 |
49 | .*/node_modules/is-my-json-valid/test/.*\.json
50 | .*/node_modules/iconv-lite/encodings/tables/.*\.json
51 | .*/node_modules/y18n/test/.*\.json
52 | .*/node_modules/spdx-license-ids/spdx-license-ids.json
53 | .*/node_modules/spdx-exceptions/index.json
54 | .*/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json
55 | .*/node_modules/resolve/lib/core.json
56 | .*/node_modules/jsonparse/samplejson/.*\.json
57 | .*/node_modules/json5/test/.*\.json
58 | .*/node_modules/ua-parser-js/test/.*\.json
59 | .*/node_modules/builtin-modules/builtin-modules.json
60 | .*/node_modules/binary-extensions/binary-extensions.json
61 | .*/node_modules/url-regex/tlds.json
62 | .*/node_modules/joi/.*\.json
63 | .*/node_modules/isemail/.*\.json
64 | .*/node_modules/tr46/.*\.json
65 |
66 |
67 | [include]
68 |
69 | [libs]
70 | node_modules/react-native/Libraries/react-native/react-native-interface.js
71 | node_modules/react-native/flow
72 | flow/
73 |
74 | [options]
75 | module.system=haste
76 |
77 | esproposal.class_static_fields=enable
78 | esproposal.class_instance_fields=enable
79 |
80 | munge_underscores=true
81 |
82 | module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
83 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
84 |
85 | suppress_type=$FlowIssue
86 | suppress_type=$FlowFixMe
87 | suppress_type=$FixMe
88 |
89 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-4]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
90 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-4]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
91 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
92 |
93 | [version]
94 | 0.24.0
95 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### 将React Native集成至Android原生应用
2 | ##### Android Studio 2.1 生成的空项目
3 | ##### react-native 环境 0.22.2
4 |
5 | 初次编译后apk有1.1M,还算可以接受。 默认依赖的lib如下图所示:
6 |
7 |
8 | 
9 |
10 | 1.***app/build.gradle***里添加如下代码:
11 |
12 | compile 'com.facebook.react:react-native:0.20.+'
13 |
14 | 再次编译后apk竟然有10.3M,太夸张了,我们来看看倒底都是什么占用了这么大的空间,仔细看一下其中包含:
15 |
16 | 
17 |
18 | 我们一起来认识一下这个库是起什么作用的:
19 | * android-jsc-r174650:Android 里的 jsc 引擎
20 | * appcompat-v7-23.0.1:appcompat v7 支持库
21 | * bolts-android-1.1.4:Facebook 开发的 Android 的底层库集合,主要是处理 Task
22 | * drawee-0.8.1:fresco 控件中的一个负责显示的底层库,包含在 fresco 里
23 | * fbcore-0.8.1:Facebook 内核库
24 | * fresco-0.8.1:Facebook 开发的一款强大的 Android 图片处理库
25 | * imagepipeline-0.8.1:负责完成加载图片(网络、本地文件,本地资源),包含在fresco里
26 | * imagepipeline-okhttp-0.8.1:负责完成加载图片前的网络请求,包含在 fresco 里
27 | * jackson-core-2.2.3:负责处理 JSON 数据
28 | * jsr-305:供检查软件缺陷用的注解
29 | * library-2.4.0:nineoldandroids 开源动画库
30 | * okhttp-2.5.0:强大的网络请求库
31 | * okhttp-ws-2.5.0:okhttp 的 web sockets 功能库
32 | * okio-1.5.0:Square 公司开发的补充 java.io 和 java.nio 的不足,用于更加方便,快速的访问、存储和处理你的数据
33 | * react-native-0.20.1:react native 库,上面和下面这些库都是被带进来的 :)
34 | * recyclerview-v7-23.0.1:Android 5.0 v7 RecyclerView 扩展库
35 | * stetho-1.2.0:Facebook 开发的 Chrome Developer 工具,用来调试React Native程序
36 | * stetho-okhttp-1.2.0:stetho 的网络请求支持库
37 | * support-annotations-23.0.1:帮助 Android Studio 检测代码中可能存在的错误
38 | * support-v4-23.0.1:Android v4 支持库
39 |
40 | 如果原Android项目应用了这些插件,那恭喜你,可以复用了,反之就要算办法精减(我也还在研究)。
41 |
42 | 2.在MainActivity里添加跳转至ReactNativeActivity的代码(模拟业务场景)
43 |
44 | 
45 |
46 | 3.添加ReactNativeActivity页面,向里面添加代码(官网那些代码太老了,这个版本是最曼妙的)
47 |
48 | 
49 |
50 | 4.向AndroidManifest.xml里添加 ***.ReactNativeActivity*** 和 ***com.facebook.react.devsupport.DevSettingsActivity***
51 | '
52 |
54 |
55 |
56 |
57 | 5.拷贝如下文件夹及文件到Android项目根目录
58 |
59 | * node_modules(文件夹。从之前 init React Native 项目里拷一份过来。因为 npm install 成功率很低,就算是用taobao的源,也很慢)
60 |
61 | * .flowconfig (JavaScript 静态类型检查工具配置文件)
62 |
63 | * .watchmanconfig(Facebook 开发的用来监视文件并且记录文件的改动情况,当文件变更就触发一些操作, 如:Enable Live Reload的功能)
64 |
65 | * index.android.js(文件。操作方式同上,注意 class 名称与下面 register 时名称要一致)
66 |
67 | * package.json(文件。操作方式同上,注意文件内容里的 name 和 react-native 版本号)
68 |
69 | 6.修改如下文件
70 |
71 | * .gitignore(在该文件里添加排除项,node_modules/ 和 npm-debug.log)
72 |
73 | * app/build.gradle (将 'com.android.support:appcompat-v7:23.2.1' 改为 'com.android.support:appcompat-v7:23.0.1')
74 |
75 | * gradle.properties (在文件末尾添加,android.useDeprecatedNdk=true)
76 |
77 | 注意:小坑一个,如果遇到。请按第6项修改,并且要保证 react-native 版本是0.21.0以上
78 |
79 | 歪果朋友也深受其害,https://github.com/facebook/react-native/issues/6152#issuecomment-200759453
80 |
81 | java.lang.IllegalAccessError: Method 'void android.support.v4.net.ConnectivityManagerCompat.()' is inaccessible to class 'com.facebook.react.modules.netinfo.NetInfoModule' (declaration of 'com.facebook.react.modules.netinfo.NetInfoModule' appears in /data/app/package.name-2/base.apk)
82 |
83 | at com.facebook.react.modules.netinfo.NetInfoModule.(NetInfoModule.java:55)
84 |
85 | at com.facebook.react.shell.MainReactPackage.createNativeModules(MainReactPackage.java:62)
86 |
87 | at com.facebook.react.ReactInstanceManagerImpl.processPackage(ReactInstanceManagerImpl.java:751)
88 |
89 | at com.facebook.react.ReactInstanceManagerImpl.createReactContext(ReactInstanceManagerImpl.java:688)
90 |
91 | at com.facebook.react.ReactInstanceManagerImpl.access$600(ReactInstanceManagerImpl.java:84)
92 |
93 | 
94 |
95 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | generateDebugSources
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
--------------------------------------------------------------------------------