本文为老曾原创。转载需注明出处:

viewmode=contents">http://blog.csdn.net/minimicall?viewmode=contents

在上一节中,我们通过一个相冊的制作来学习了React Native编写。这一节我们须要開始学习React Native的源代码。

学习源代码,从编译源代码開始。

首先。我们须要把代码从github中克隆下来。

https://github.com/facebook/react-native.git

然后,我们能够切换到它的稳定分支,2016-03-30是我的操作时间,这个时候0.23-stable是最新的稳定版本号。

git checkout -b 0.23-stable remotes/origin/0.23-stable

我们首先升级一下我们的react-native。由于等下创建项目最好使用最新版本号的。

首先。我们须要查询最新版本号:

nam info react-native

得到最新版本号是0.22.2

npm install --save react-native@0.22.2

接下来,创建一个项目:

react-native init videolegend

好,等待漫长的初始化过程。

完事之后,打开项目顶层的package.json文件:

{
"name": "videolegend",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"react": "^0.14.8",
"react-native": "^0.22.2"
}
}

能够看出我们的一个版本号的基本信息。

接下来,我们来进行源代码的编译。编译源代码。官网有一个页面,我们的过程呢,也是基于它的,但假设你全然基于它,那么你是会吃亏的。

所以,为什么我要写一篇文章出来,给大家作为參考。

官网源代码编译地址:点击打开链接

前置条件:

1、SDK : compileSdkVersion 23

2、SDK build tools : 23.0.1

3、Android Support Repository >=17

4 、 NDK (4.8哦就是 ndk-r10b,,4.9都不行,会坑出非常多问题,假设NDK版本号不正确。)

使用AndroidStudio打开项目。

1、项目顶层build.grade的配置:

// 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:1.3.1'
//加以下这一行
classpath 'de.undercouch:gradle-download-task:2.0.0'
// 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 "$projectDir/../../node_modules/react-native/android"
}
}
}

2、加入ReactAndroid模块,在顶层的setting.grade文件里。配置例如以下:

rootProject.name = 'videolegend'

include ':app'
include ':ReactAndroid'
project(':ReactAndroid').projectDir = new File('/Users/zengjinlong/workplace/react/reactnativesrc/react-native/ReactAndroid')

那个绝对文件夹是我的,你仅仅须要改成你的即可。

3、更改项目依赖:在应用模块的build.gradle里面更改依赖部分:

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

凝视掉原来的,更改为模块依赖。

官网到这里。就叫你能够run啦。呵呵,too young too simple。

首先。ReactAndroid里面的有些下载任务你给它再多时间都不可能完毕。所以。

。。

我们须要离线下载好。

然后更改其脚本,进行编译。

1、离线下载好

boost_1_57_0

double_conversion-1.1.1

folly-deprecate-dynamic-initializer

glog-0.3.3

jsc头文件

然后依照文件夹放到ReactAndroid的build/downloads/文件夹以下。大概有450M内容。

2、改动ReactAndroid的build.grade脚本

主要是删掉那些下载任务的脚本。直接进入拷贝任务和编译任务。

来,我们来感受一下改动前和改动后的差别。

首先。改动前:

// Copyright 2015-present Facebook. All Rights Reserved.

apply plugin: 'com.android.library'
apply plugin: 'maven' apply plugin: 'de.undercouch.download' import de.undercouch.gradle.tasks.download.Download
import org.apache.tools.ant.taskdefs.condition.Os
import org.apache.tools.ant.filters.ReplaceTokens // We download various C++ open-source dependencies into downloads.
// We then copy both the downloaded code and our custom makefiles and headers into third-party-ndk.
// After that we build native code from src/main/jni with module path pointing at third-party-ndk. def downloadsDir = new File("$buildDir/downloads")
def thirdPartyNdkDir = new File("$buildDir/third-party-ndk") task createNativeDepsDirectories {
downloadsDir.mkdirs()
thirdPartyNdkDir.mkdirs()
}
//下载boost 超级慢。所以自己下好吧
task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
// Use ZIP version as it's faster this way to selectively extract some parts of the archive
src 'https://downloads.sourceforge.net/project/boost/boost/1.57.0/boost_1_57_0.zip'
// alternative
// src 'http://mirror.nienbo.com/boost/boost_1_57_0.zip'
onlyIfNewer true
overwrite false
dest new File(downloadsDir, 'boost_1_57_0.zip')
}
//下载好boost后,复制到指定文件夹
task prepareBoost(dependsOn: downloadBoost, type: Copy) {
from zipTree(downloadBoost.dest)
from 'src/main/jni/third-party/boost/Android.mk'
include 'boost_1_57_0/boost/**/*.hpp', 'Android.mk'
into "$thirdPartyNdkDir/boost"
}
//下载
task downloadDoubleConversion(dependsOn: createNativeDepsDirectories, type: Download) {
src 'https://github.com/google/double-conversion/archive/v1.1.1.tar.gz'
onlyIfNewer true
overwrite false
dest new File(downloadsDir, 'double-conversion-1.1.1.tar.gz')
}
//
task prepareDoubleConversion(dependsOn: downloadDoubleConversion, type: Copy) {
from tarTree(downloadDoubleConversion.dest)
from 'src/main/jni/third-party/double-conversion/Android.mk'
include 'double-conversion-1.1.1/src/**/*', 'Android.mk'
filesMatching('*/src/**/*', {fname -> fname.path = "double-conversion/${fname.name}"})
includeEmptyDirs = false
into "$thirdPartyNdkDir/double-conversion"
} task downloadFolly(dependsOn: createNativeDepsDirectories, type: Download) {
src 'https://github.com/facebook/folly/archive/deprecate-dynamic-initializer.tar.gz'
onlyIfNewer true
overwrite false
dest new File(downloadsDir, 'folly-deprecate-dynamic-initializer.tar.gz');
} task prepareFolly(dependsOn: downloadFolly, type: Copy) {
from tarTree(downloadFolly.dest)
from 'src/main/jni/third-party/folly/Android.mk'
include 'folly-deprecate-dynamic-initializer/folly/**/*', 'Android.mk'
eachFile {fname -> fname.path = (fname.path - "folly-deprecate-dynamic-initializer/")}
includeEmptyDirs = false
into "$thirdPartyNdkDir/folly"
} task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) {
src 'https://github.com/google/glog/archive/v0.3.3.tar.gz'
onlyIfNewer true
overwrite false
dest new File(downloadsDir, 'glog-0.3.3.tar.gz')
} // Prepare glog sources to be compiled, this task will perform steps that normally shoudl've been
// executed by automake. This way we can avoid dependencies on make/automake
task prepareGlog(dependsOn: downloadGlog, type: Copy) {
from tarTree(downloadGlog.dest)
from 'src/main/jni/third-party/glog/'
include 'glog-0.3.3/src/**/*', 'Android.mk', 'config.h'
includeEmptyDirs = false
filesMatching('**/*.h.in') {
filter(ReplaceTokens, tokens: [
ac_cv_have_unistd_h: '1',
ac_cv_have_stdint_h: '1',
ac_cv_have_systypes_h: '1',
ac_cv_have_inttypes_h: '1',
ac_cv_have_libgflags: '0',
ac_google_start_namespace: 'namespace google {',
ac_cv_have_uint16_t: '1',
ac_cv_have_u_int16_t: '1',
ac_cv_have___uint16: '0',
ac_google_end_namespace: '}',
ac_cv_have___builtin_expect: '1',
ac_google_namespace: 'google',
ac_cv___attribute___noinline: '__attribute__ ((noinline))',
ac_cv___attribute___noreturn: '__attribute__ ((noreturn))',
ac_cv___attribute___printf_4_5: '__attribute__((__format__ (__printf__, 4, 5)))'
])
it.path = (it.name - '.in')
}
into "$thirdPartyNdkDir/glog"
} task downloadJSCHeaders(type: Download) {
def jscAPIBaseURL = 'https://svn.webkit.org/repository/webkit/!svn/bc/174650/trunk/Source/JavaScriptCore/API/'
def jscHeaderFiles = ['JSBase.h', 'JSContextRef.h', 'JSObjectRef.h', 'JSRetainPtr.h', 'JSStringRef.h', 'JSValueRef.h', 'WebKitAvailability.h']
def output = new File(downloadsDir, 'jsc')
output.mkdirs()
src(jscHeaderFiles.collect { headerName -> "$jscAPIBaseURL$headerName" })
onlyIfNewer true
overwrite false
dest output
} // Create Android.mk library module based on so files from mvn + include headers fetched from webkit.org
task prepareJSC(dependsOn: downloadJSCHeaders) << {
copy {
from zipTree(configurations.compile.fileCollection { dep -> dep.name == 'android-jsc' }.singleFile)
from {downloadJSCHeaders.dest}
from 'src/main/jni/third-party/jsc/Android.mk'
include 'jni/**/*.so', '*.h', 'Android.mk'
filesMatching('*.h', { fname -> fname.path = "JavaScriptCore/${fname.path}"})
into "$thirdPartyNdkDir/jsc";
}
} def getNdkBuildName() {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
return "ndk-build.cmd"
} else {
return "ndk-build"
}
} def findNdkBuildFullPath() {
// we allow to provide full path to ndk-build tool
if (hasProperty('ndk.command')) {
return property('ndk.command')
}
// or just a path to the containing directory
if (hasProperty('ndk.path')) {
def ndkDir = property('ndk.path')
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
}
if (System.getenv('ANDROID_NDK') != null) {
def ndkDir = System.getenv('ANDROID_NDK')
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
}
def ndkDir = android.hasProperty('plugin') ? android.plugin.ndkFolder :
plugins.getPlugin('com.android.library').sdkHandler.getNdkFolder()
if (ndkDir) {
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
}
return null
} def getNdkBuildFullPath() {
def ndkBuildFullPath = findNdkBuildFullPath()
if (ndkBuildFullPath == null) {
throw new GradleScriptException(
"ndk-build binary cannot be found, check if you've set " +
"\$ANDROID_NDK environment variable correctly or if ndk.dir is " +
"setup in local.properties",
null)
}
if (!new File(ndkBuildFullPath).canExecute()) {
throw new GradleScriptException(
"ndk-build binary " + ndkBuildFullPath + " doesn't exist or isn't executable.\n" +
"Check that the \$ANDROID_NDK environment variable, or ndk.dir in local.proerties, is set correctly.\n" +
"(On Windows, make sure you escape backslashes in local.properties or use forward slashes, e.g. C:\\\\ndk or C:/ndk rather than C:\\ndk)",
null)
}
return ndkBuildFullPath
} task buildReactNdkLib(dependsOn: [prepareJSC, prepareBoost, prepareDoubleConversion, prepareFolly, prepareGlog], type: Exec) {
inputs.file('src/main/jni/react')
outputs.dir("$buildDir/react-ndk/all")
commandLine getNdkBuildFullPath(),
'NDK_PROJECT_PATH=null',
"NDK_APPLICATION_MK=$projectDir/src/main/jni/Application.mk",
'NDK_OUT=' + temporaryDir,
"NDK_LIBS_OUT=$buildDir/react-ndk/all",
"THIRD_PARTY_NDK_DIR=$buildDir/third-party-ndk",
'-C', file('src/main/jni/react/jni').absolutePath,
'--jobs', project.hasProperty("jobs") ? project.property("jobs") : Runtime.runtime.availableProcessors()
} task cleanReactNdkLib(type: Exec) {
commandLine getNdkBuildFullPath(),
'-C', file('src/main/jni/react/jni').absolutePath,
'clean'
} task packageReactNdkLibs(dependsOn: buildReactNdkLib, type: Copy) {
from "$buildDir/react-ndk/all"
exclude '**/libjsc.so'
into "$buildDir/react-ndk/exported"
} task packageReactNdkLibsForBuck(dependsOn: packageReactNdkLibs, type: Copy) {
from "$buildDir/react-ndk/exported"
into "src/main/jni/prebuilt/lib"
} android {
compileSdkVersion 23
buildToolsVersion "23.0.1" defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0" ndk {
moduleName "reactnativejni"
} buildConfigField 'boolean', 'IS_INTERNAL_BUILD', 'false'
testApplicationId "com.facebook.react.tests.gradle"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir "$buildDir/react-ndk/exported"
res.srcDirs = ['src/main/res/devsupport', 'src/main/res/shell', 'src/main/res/views/modal']
java {
srcDirs = ['src/main/java', 'src/main/libraries/soloader']
exclude 'com/facebook/react/processing'
}
} tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn packageReactNdkLibs
} clean.dependsOn cleanReactNdkLib lintOptions {
abortOnError false
}
} dependencies {
compile fileTree(dir: 'src/main/third-party/java/infer-annotations/', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.facebook.fresco:fresco:0.8.1'
compile 'com.facebook.fresco:imagepipeline-okhttp:0.8.1'
compile 'com.facebook.stetho:stetho:1.2.0'
compile 'com.facebook.stetho:stetho-okhttp:1.2.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.2.3'
compile 'com.google.code.findbugs:jsr305:3.0.0'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.squareup.okhttp:okhttp-ws:2.5.0'
compile 'com.squareup.okio:okio:1.6.0'
compile 'org.webkit:android-jsc:r174650' testCompile "junit:junit:${JUNIT_VERSION}"
testCompile "org.powermock:powermock-api-mockito:${POWERMOCK_VERSION}"
testCompile 'com.fasterxml.jackson.core:jackson-databind:2.2.3'
testCompile "org.powermock:powermock-module-junit4-rule:${POWERMOCK_VERSION}"
testCompile "org.powermock:powermock-classloading-xstream:${POWERMOCK_VERSION}"
testCompile "org.mockito:mockito-core:${MOCKITO_CORE_VERSION}"
testCompile "org.easytesting:fest-assert-core:${FEST_ASSERT_CORE_VERSION}"
testCompile "org.robolectric:robolectric:${ROBOLECTRIC_VERSION}" androidTestCompile "com.android.support.test:testing-support-lib:0.1"
} apply from: 'release.gradle'

改动完以后:

// Copyright 2015-present Facebook. All Rights Reserved.

apply plugin: 'com.android.library'
apply plugin: 'maven' apply plugin: 'de.undercouch.download' import de.undercouch.gradle.tasks.download.Download
import org.apache.tools.ant.taskdefs.condition.Os
import org.apache.tools.ant.filters.ReplaceTokens // We download various C++ open-source dependencies into downloads.
// We then copy both the downloaded code and our custom makefiles and headers into third-party-ndk.
// After that we build native code from src/main/jni with module path pointing at third-party-ndk. def downloadsDir = new File("$buildDir/downloads")
def thirdPartyNdkDir = new File("$buildDir/third-party-ndk") task createNativeDepsDirectories {
downloadsDir.mkdirs()
thirdPartyNdkDir.mkdirs()
}
//
//task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
// // Use ZIP version as it's faster this way to selectively extract some parts of the archive
// src 'https://downloads.sourceforge.net/project/boost/boost/1.57.0/boost_1_57_0.zip'
// // alternative
// // src 'http://mirror.nienbo.com/boost/boost_1_57_0.zip'
// onlyIfNewer true
// overwrite false
// dest new File(downloadsDir, 'boost_1_57_0.zip')
//} task prepareBoost( type: Copy) {
from 'build/downloads/'
from 'src/main/jni/third-party/boost/Android.mk'
include 'boost_1_57_0/boost/**/*.hpp', 'Android.mk'
into "$thirdPartyNdkDir/boost"
} //task downloadDoubleConversion(dependsOn: createNativeDepsDirectories, type: Download) {
// src 'https://github.com/google/double-conversion/archive/v1.1.1.tar.gz'
// onlyIfNewer true
// overwrite false
// dest new File(downloadsDir, 'double-conversion-1.1.1.tar.gz')
//} task prepareDoubleConversion(type: Copy) {
from 'build/downloads/'
from 'src/main/jni/third-party/double-conversion/Android.mk'
include 'double-conversion-1.1.1/src/**/*', 'Android.mk'
filesMatching('*/src/**/*', {fname -> fname.path = "double-conversion/${fname.name}"})
includeEmptyDirs = false
into "$thirdPartyNdkDir/double-conversion"
} //task downloadFolly(dependsOn: createNativeDepsDirectories, type: Download) {
// src 'https://github.com/facebook/folly/archive/deprecate-dynamic-initializer.tar.gz'
// onlyIfNewer true
// overwrite false
// dest new File(downloadsDir, 'folly-deprecate-dynamic-initializer.tar.gz');
//} task prepareFolly(type: Copy) {
from 'build/downloads/'
from 'src/main/jni/third-party/folly/Android.mk'
include 'folly-deprecate-dynamic-initializer/folly/**/*', 'Android.mk'
eachFile {fname -> fname.path = (fname.path - "folly-deprecate-dynamic-initializer/")}
includeEmptyDirs = false
into "$thirdPartyNdkDir/folly"
} //task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) {
// src 'https://github.com/google/glog/archive/v0.3.3.tar.gz'
// onlyIfNewer true
// overwrite false
// dest new File(downloadsDir, 'glog-0.3.3.tar.gz')
//} // Prepare glog sources to be compiled, this task will perform steps that normally shoudl've been
// executed by automake. This way we can avoid dependencies on make/automake
task prepareGlog( type: Copy) {
from 'build/downloads/'
from 'src/main/jni/third-party/glog/'
include 'glog-0.3.3/src/**/*', 'Android.mk', 'config.h'
includeEmptyDirs = false
filesMatching('**/*.h.in') {
filter(ReplaceTokens, tokens: [
ac_cv_have_unistd_h: '1',
ac_cv_have_stdint_h: '1',
ac_cv_have_systypes_h: '1',
ac_cv_have_inttypes_h: '1',
ac_cv_have_libgflags: '0',
ac_google_start_namespace: 'namespace google {',
ac_cv_have_uint16_t: '1',
ac_cv_have_u_int16_t: '1',
ac_cv_have___uint16: '0',
ac_google_end_namespace: '}',
ac_cv_have___builtin_expect: '1',
ac_google_namespace: 'google',
ac_cv___attribute___noinline: '__attribute__ ((noinline))',
ac_cv___attribute___noreturn: '__attribute__ ((noreturn))',
ac_cv___attribute___printf_4_5: '__attribute__((__format__ (__printf__, 4, 5)))'
])
it.path = (it.name - '.in')
}
into "$thirdPartyNdkDir/glog"
} task downloadJSCHeaders(type: Download) {
def jscAPIBaseURL = 'https://svn.webkit.org/repository/webkit/!svn/bc/174650/trunk/Source/JavaScriptCore/API/'
def jscHeaderFiles = ['JSBase.h', 'JSContextRef.h', 'JSObjectRef.h', 'JSRetainPtr.h', 'JSStringRef.h', 'JSValueRef.h', 'WebKitAvailability.h']
def output = new File(downloadsDir, 'jsc')
output.mkdirs()
src(jscHeaderFiles.collect { headerName -> "$jscAPIBaseURL$headerName" })
onlyIfNewer true
overwrite false
dest output
} // Create Android.mk library module based on so files from mvn + include headers fetched from webkit.org
task prepareJSC(dependsOn: downloadJSCHeaders) << {
copy {
from zipTree(configurations.compile.fileCollection { dep -> dep.name == 'android-jsc' }.singleFile)
from {downloadJSCHeaders.dest}
from 'src/main/jni/third-party/jsc/Android.mk'
include 'jni/**/*.so', '*.h', 'Android.mk'
filesMatching('*.h', { fname -> fname.path = "JavaScriptCore/${fname.path}"})
into "$thirdPartyNdkDir/jsc";
}
} def getNdkBuildName() {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
return "ndk-build.cmd"
} else {
return "ndk-build"
}
} def findNdkBuildFullPath() {
// we allow to provide full path to ndk-build tool
if (hasProperty('ndk.command')) {
return property('ndk.command')
}
// or just a path to the containing directory
if (hasProperty('ndk.path')) {
def ndkDir = property('ndk.path')
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
}
if (System.getenv('ANDROID_NDK') != null) {
def ndkDir = System.getenv('ANDROID_NDK')
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
}
def ndkDir = android.hasProperty('plugin') ? android.plugin.ndkFolder :
plugins.getPlugin('com.android.library').sdkHandler.getNdkFolder()
if (ndkDir) {
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
}
return null
} def getNdkBuildFullPath() {
def ndkBuildFullPath = findNdkBuildFullPath()
if (ndkBuildFullPath == null) {
throw new GradleScriptException(
"ndk-build binary cannot be found, check if you've set " +
"\$ANDROID_NDK environment variable correctly or if ndk.dir is " +
"setup in local.properties",
null)
}
if (!new File(ndkBuildFullPath).canExecute()) {
throw new GradleScriptException(
"ndk-build binary " + ndkBuildFullPath + " doesn't exist or isn't executable.\n" +
"Check that the \$ANDROID_NDK environment variable, or ndk.dir in local.proerties, is set correctly.\n" +
"(On Windows, make sure you escape backslashes in local.properties or use forward slashes, e.g. C:\\\\ndk or C:/ndk rather than C:\\ndk)",
null)
}
return ndkBuildFullPath
} task buildReactNdkLib(dependsOn: [prepareJSC, prepareBoost, prepareDoubleConversion, prepareFolly, prepareGlog], type: Exec) {
inputs.file('src/main/jni/react')
outputs.dir("$buildDir/react-ndk/all")
commandLine getNdkBuildFullPath(),
'NDK_PROJECT_PATH=null',
"NDK_APPLICATION_MK=$projectDir/src/main/jni/Application.mk",
'NDK_OUT=' + temporaryDir,
"NDK_LIBS_OUT=$buildDir/react-ndk/all",
"THIRD_PARTY_NDK_DIR=$buildDir/third-party-ndk",
'-C', file('src/main/jni/react/jni').absolutePath,
'--jobs', project.hasProperty("jobs") ? project.property("jobs") : Runtime.runtime.availableProcessors()
} task cleanReactNdkLib(type: Exec) {
commandLine getNdkBuildFullPath(),
'-C', file('src/main/jni/react/jni').absolutePath,
'clean'
} task packageReactNdkLibs(dependsOn: buildReactNdkLib, type: Copy) {
from "$buildDir/react-ndk/all"
exclude '**/libjsc.so'
into "$buildDir/react-ndk/exported"
} task packageReactNdkLibsForBuck(dependsOn: packageReactNdkLibs, type: Copy) {
from "$buildDir/react-ndk/exported"
into "src/main/jni/prebuilt/lib"
} android {
compileSdkVersion 23
buildToolsVersion "23.0.1" defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0" ndk {
moduleName "reactnativejni"
} buildConfigField 'boolean', 'IS_INTERNAL_BUILD', 'false'
testApplicationId "com.facebook.react.tests.gradle"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir "$buildDir/react-ndk/exported"
res.srcDirs = ['src/main/res/devsupport', 'src/main/res/shell', 'src/main/res/views/modal']
java {
srcDirs = ['src/main/java', 'src/main/libraries/soloader']
exclude 'com/facebook/react/processing'
}
} tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn packageReactNdkLibs
} clean.dependsOn cleanReactNdkLib lintOptions {
abortOnError false
}
} dependencies {
compile fileTree(dir: 'src/main/third-party/java/infer-annotations/', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.facebook.fresco:fresco:0.8.1'
compile 'com.facebook.fresco:imagepipeline-okhttp:0.8.1'
compile 'com.facebook.stetho:stetho:1.2.0'
compile 'com.facebook.stetho:stetho-okhttp:1.2.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.2.3'
compile 'com.google.code.findbugs:jsr305:3.0.0'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.squareup.okhttp:okhttp-ws:2.5.0'
compile 'com.squareup.okio:okio:1.6.0'
compile 'org.webkit:android-jsc:r174650' testCompile "junit:junit:${JUNIT_VERSION}"
testCompile "org.powermock:powermock-api-mockito:${POWERMOCK_VERSION}"
testCompile 'com.fasterxml.jackson.core:jackson-databind:2.2.3'
testCompile "org.powermock:powermock-module-junit4-rule:${POWERMOCK_VERSION}"
testCompile "org.powermock:powermock-classloading-xstream:${POWERMOCK_VERSION}"
testCompile "org.mockito:mockito-core:${MOCKITO_CORE_VERSION}"
testCompile "org.easytesting:fest-assert-core:${FEST_ASSERT_CORE_VERSION}"
testCompile "org.robolectric:robolectric:${ROBOLECTRIC_VERSION}" androidTestCompile "com.android.support.test:testing-support-lib:0.1"
} apply from: 'release.gradle'

去掉了那些下载,由于我们已经下载好,扔进去。至于那些怎么下载,大家就自己自行想办法吧,反正一个个下载。

然后能够编译了。

注意ndk版本号。在local.properties文件中面设定:

ndk.dir=/Users/zengjinlong/workplace/android-ndk-r10b
sdk.dir=/Users/zengjinlong/workplace/android-sdk-macosx

OK,跑起来。

然后,在项目的顶层。npm start 。

注意。我们并没有将ReactAndroid 装载到node_module里面。由于这样easy出问题,所以这也是跟官网差异的一个地方。就是,project依赖是通过源代码。可是npm start的,事实上是node_module里面的,也就是0.22.2

好,今天就到这里。有什么不懂的,能够来问我。

470910357@qq.com;

微信:micall123

React Native Android入门实战及深入源代码分析系列(2)——React Native源代码编译的更多相关文章

  1. Spark SQL 源代码分析系列

    从决定写Spark SQL文章的源代码分析,到现在一个月的时间,一个又一个几乎相同的结束很快,在这里也做了一个综合指数,方便阅读,下面是读取顺序 :) 第一章 Spark SQL源代码分析之核心流程 ...

  2. MyBatis架构设计及源代码分析系列(一):MyBatis架构

    如果不太熟悉MyBatis使用的请先参见MyBatis官方文档,这对理解其架构设计和源码分析有很大好处. 一.概述 MyBatis并不是一个完整的ORM框架,其官方首页是这么介绍自己 The MyBa ...

  3. OpenStack_Swift源代码分析——Ring的rebalance算法源代码具体分析

    1 Command类中的rebalnace方法 在上篇文章中解说了,创建Ring已经为Ring加入设备.在加入设备后须要对Ring进行平衡,平衡 swift-ring-builder object.b ...

  4. Cordova Android源代码分析系列一(项目总览和CordovaActivity分析)

    版权声明:本文为博主offbye西涛原创文章.未经博主同意不得转载. https://blog.csdn.net/offbye/article/details/31776833 PhoneGap/Co ...

  5. 《React+Redux前端开发实战》笔记1:不涉及React项目构建的Hello World案例

    本小节实现一个不涉及项目构建的Hello World. [React的第一个Hello World网页] 源码地址:https://jsfiddle.net/allan91/2h1sf0ky/8/ & ...

  6. lightning mdb 源代码分析系列(3)

    本系列前两章已经描述了系统架构以及系统构建的基础内存映射,本章将详细描述lmdb的核心,外存B+Tree的操作.本文将从基本原理.内存操作方式.外存操作方式以及LMDB中的相关函数等几方面描述LMDB ...

  7. Linux-0.11内核源代码分析系列:内存管理get_free_page()函数分析

    Linux-0.11内存管理模块是源码中比較难以理解的部分,如今把笔者个人的理解发表 先发Linux-0.11内核内存管理get_free_page()函数分析 有时间再写其它函数或者文件的:) /* ...

  8. WPF源代码分析系列一:剖析WPF模板机制的内部实现(一)

    众所周知,在WPF框架中,Visual类是可以提供渲染(render)支持的最顶层的类,所有可视化元素(包括UIElement.FrameworkElment.Control等)都直接或间接继承自Vi ...

  9. RTMPdump(libRTMP)源代码分析 4: 连接第一步——握手(Hand Shake)

    ===================================================== RTMPdump(libRTMP) 源代码分析系列文章: RTMPdump 源代码分析 1: ...

随机推荐

  1. 大话PHP设计模式

    设计模式 一书将设计模式引入软件社区,该书的作者是 Erich Gamma.Richard Helm.Ralph Johnson 和 John Vlissides Design(俗称 “四人帮”).所 ...

  2. AC日记——[Ahoi2013]作业 bzoj 3236

    3236 思路: 莫队+树状数组维护: 代码: #include <cmath> #include <cstdio> #include <cstring> #inc ...

  3. CF 1003C Intense Heat【前缀和/精度/双层暴力枚举】

    The heat during the last few days has been really intense. Scientists from all over the Berland stud ...

  4. 主席树【bzoj3524(p3567)】[POI2014]Couriers

    Description 给一个长度为n的序列a.1≤a[i]≤n. m组询问,每次询问一个区间[l,r],是否存在一个数在[l,r]中出现的次数大于(r-l+1)/2.如果存在,输出这个数,否则输出0 ...

  5. Eclipse Build all and build project not working - jar missing

    Eclipse Build all and build project not working - jar missing

  6. Compare, sort, and delete duplicate lines in Notepad ++

    Compare, sort, and delete duplicate lines in Notepad ++ Organize Lines: Since version 6.5.2 the app ...

  7. 微信小程序开发教程(五)开发框架:MINA

    微信团队为小程序提供的框架命名为MINA应用框架.MINA框架通过封装微信客户端提供的文件系统.网络通信.任务管理.数据安全等基础功能,对上层提供一整套JavaScript API,让开发者能够非常方 ...

  8. 【AC自动机+DP】USACO2012 JAN GOLD_Video Game Combos

    [题目大意] 给你个模式串(每个长度≤15,1≤N≤20),串中只含有三种字母.求一长度为K(1≤K≤1000)的字符串,使得匹配数最大(重复匹配计多次),输出最大值. [解题思路] W老师给的题,然 ...

  9. java static代码段

    1)java中还有个static代码块的形式,形式为 static {……}.static代码块是类定义的一部分,仅仅在类被初次加载的时候被调用一次,之后再调用不会再加载.那么类什么时候首次被加载呢? ...

  10. display:flex;多行多列布局学习

    从以前的table布局到现在的div布局,再到未来的flex布局,CSS重构方面对展示行和适应性的要求越来越高: 首先来比较一下布局方式的更新意义: table布局: 优点:1.兼容性好,ie6.ie ...