由于React Native
在0.45版本上增加了boost
、Folly
、Glog
、DoubleConversion
四个库,并且所依赖的版本在github
上均无法找到,只能自己制作,所以在制作成私库中相对比较麻烦。
本篇文章记录的是基于0.49.5
的React Native
版本制作私库过程。
一、npm install
我们需要准备一个package.json
文件,用于下载相关库,内容如下:
{
"name": "react-install",
"version": "1.0.0",
"private": true,
"scripts": {
},
"dependencies": {
"react": "16.0.0",
"react-native": "0.49.5"
}
}
二、下载依赖的第三方库
打开node_modules/react-native/scripts
文件夹,执行安装第三方库的脚本:
$ ./ios-install-third-party.sh
执行以后发现报错:
Unpacking /Users/wsh/.rncache/glog-0.3.4.tar.gz...
./ios-install-third-party.sh: line 28: ./ios-configure-glog.sh: No such file or directory
需要修改下脚本,打开ios-install-third-party.sh
:
修改
fetch_and_unpack glog-0.3.4.tar.gz https://github.com/google/glog/archive/v0.3.4.tar.gz "\"$SCRIPTDIR/ios-configure-glog.sh\""
为
fetch_and_unpack glog-0.3.4.tar.gz https://github.com/google/glog/archive/v0.3.4.tar.gz "\"ios-configure-glog.sh\""
然后再执行上面的脚本:
$ ./ios-install-third-party.sh
Unpacking /Users/test/.rncache/double-conversion-1.1.5.tar.gz...
Unpacking /Users/test/.rncache/boost_1_63_0.tar.gz...
Unpacking /Users/test/.rncache/folly-2016.09.26.00.tar.gz...
这里脚本是先将相应的文件下载到/Users/test/.rncache
中进行缓存,然后再进行解压缩的操作。其中boost
下载比较难,需要连接VPN,boost下载地址, 可以自行去下载,然后放到本地的.rncache
文件夹中。
三、制作第三方库的依赖
这里我们开始制作Yoga
、boost
、Folly
、Glog
、DoubleConversion
五个库的私库依赖。如果使用npm install & npm run eject
安装后的项目工程,可以发现,Folly
、Glog
、DoubleConversion
三个库是被直接添加到React
子工程中的,如下截图:
Yoga(原名为小写yoga)私库制作
yoga为React Native
一直使用的布局库,类似于flexbox
。这个一直存在于React Native
中的各个版本,这里首先从制作此私库开始。
将node_modules/react-native/ReactCommon/yoga/yoga.podspec
,修改为Yoga.podspec
文件,其中内容修改为:
version = '0.49.5'
source = { :git => 'http://yourhost/yoga.git' }
if version == '1000.0.0'
# This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in.
source[:commit] = `git rev-parse HEAD`.strip
else
source[:tag] = "v#{version}"
end
Pod::Spec.new do |spec|
spec.name = 'Yoga'
spec.version = "#{version}.React"
spec.license = { :type => 'BSD' }
spec.homepage = 'https://facebook.github.io/yoga/'
spec.documentation_url = 'https://facebook.github.io/yoga/docs/api/c/'
spec.summary = 'Yoga is a cross-platform layout engine which implements Flexbox.'
spec.description = 'Yoga is a cross-platform layout engine enabling maximum collaboration within your team by implementing an API many designers are familiar with, and opening it up to developers across different platforms.'
spec.authors = 'Facebook'
spec.source = source
spec.module_name = 'yoga'
spec.requires_arc = false
spec.compiler_flags = [
'-fno-omit-frame-pointer',
'-fexceptions',
'-Wall',
'-Werror',
'-std=c11',
'-fPIC'
]
# Pinning to the same version as React.podspec.
spec.platforms = { :ios => "8.0", :tvos => "9.2" }
# Set this environment variable when not using the `:path` option to install the pod.
# E.g. when publishing this spec to a spec repo.
source_files = 'yoga/**/*.{c,h}'
source_files = File.join('ReactCommon/yoga', source_files) if ENV['INSTALL_YOGA_WITHOUT_PATH_OPTION']
spec.source_files = source_files
end
其中修改的内容如下:
package = JSON.parse(File.read(File.expand_path('../../package.json', __dir__)))
version = package['version']
source = { :git => ENV['INSTALL_YOGA_FROM_LOCATION'] || 'https://github.com/facebook/react-native.git' }
以上三行修改为如下两行:
version = '0.49.5'
source = { :git => 'http://stash.weimob.com/scm/fas/yoga.git' }
#私库名称修改
spec.name = 'Yoga'
提交git,打上tag v0.49.5
,同时将Yoga.podspec
提交到你的Specs
私库中。
Boost(原名为小写boost)私库制作
首先去boost Spec上去下载boost
对应的podspec文件。我们发现只有1.51.0
的版本,但是React Native
使用的是1.63.0
版本,因此我们要将下载下来的podspec文件进行相应的修改。修改后的文件如下:
Pod::Spec.new do |s|
s.name = "Boost"
s.version = "1.63.0"
s.summary = "Boost provides free peer-reviewed portable C++ source libraries."
s.homepage = "http://www.boost.org"
s.license = { :type => "Boost Software License",
:file => "LICENSE_1_0.txt" }
s.author = "Rene Rivera"
s.source = { :http => "http://yourhost/Spec/boost_1_63_0.tar.gz" }
s.ios.deployment_target = "4.0"
s.osx.deployment_target = "10.6"
# s.source_files = 'boost/*.hpp', 'boost/{config,smart_ptr}/**/*.hpp'
s.subspec 'string_algorithms-includes' do |string_algorithms|
string_algorithms.preserve_paths = 'boost/algorithm/string.hpp',
'boost/algorithm/string/**/*.hpp',
'boost/config.hpp',
'boost/config/**/*.hpp',
'boost/range/**/*.hpp',
'boost/static_assert.hpp',
'boost/assert.hpp',
'boost/current_function.hpp',
'boost/integer.hpp',
'boost/integer_fwd.hpp',
'boost/cstdint.hpp',
'boost/integer_traits.hpp',
'boost/ref.hpp',
'boost/checked_delete.hpp',
'boost/next_prior.hpp',
'boost/noncopyable.hpp',
'boost/mem_fn.hpp',
'boost/bind/**/*.hpp',
'boost/get_pointer.hpp',
'boost/limits.hpp',
'boost/throw_exception.hpp',
'boost/detail/**/*.hpp',
'boost/exception/**/*.hpp',
'boost/function.hpp',
'boost/function_equal.hpp',
'boost/function/**/*.hpp',
'boost/concept_check.hpp',
'boost/concept/**/*hpp',
'boost/utility.hpp',
'boost/utility/**/*.hpp',
'boost/type_traits/**/*.hpp',
'boost/mpl/**/*.hpp',
'boost/preprocessor/**/*.hpp',
'boost/iterator.hpp',
'boost/iterator/**/*.hpp'
end
s.subspec 'shared_ptr-includes' do |shared_ptr|
shared_ptr.preserve_paths = 'boost/shared_ptr.hpp',
'boost/config.hpp',
'boost/config/**/*.hpp',
'boost/version.hpp',
'boost/assert.hpp',
'boost/current_function.hpp',
'boost/checked_delete.hpp',
'boost/throw_exception.hpp',
'boost/exception/detail/attribute_noreturn.hpp',
'boost/exception/exception.hpp',
'boost/memory_order.hpp',
'boost/detail/workaround.hpp',
'boost/smart_ptr/shared_ptr.hpp',
'boost/smart_ptr/detail/spinlock*.hpp',
'boost/smart_ptr/detail/yield_k.hpp',
'boost/smart_ptr/detail/shared_count.hpp',
'boost/smart_ptr/bad_weak_ptr.hpp',
'boost/smart_ptr/detail/sp_counted_base.hpp',
'boost/smart_ptr/detail/sp_counted_base_spin.hpp',
'boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp',
'boost/detail/sp_typeinfo.hpp',
'boost/smart_ptr/detail/sp_has_sync.hpp',
'boost/smart_ptr/detail/sp_counted_impl.hpp',
'boost/smart_ptr/detail/sp_convertible.hpp',
'boost/smart_ptr/detail/operator_bool.hpp'
end
s.subspec 'pointer_cast-includes' do |pointer_cast|
pointer_cast.preserve_paths = 'boost/pointer_cast.hpp'
end
s.subspec 'numeric-includes' do |numeric|
numeric.preserve_paths = 'boost/numeric/**/*.hpp'
end
s.subspec 'preprocessor-includes' do |preprocessor|
preprocessor.preserve_paths = 'boost/preprocessor/**/*.hpp'
end
s.subspec 'math-includes' do |math|
math.preserve_paths = 'boost/math/**/*.hpp',
'boost/limits.hpp',
'boost/static_assert.hpp',
'boost/cstdint.hpp',
'boost/config.hpp',
'boost/config/**/*.hpp',
'boost/version.hpp',
'boost/detail/endian.hpp',
'boost/detail/limits.hpp',
'boost/mpl/**/*.hpp',
'boost/type_traits.hpp',
'boost/type_traits/**/*.hpp'
end
s.subspec 'graph-includes' do |graph|
graph.preserve_paths =
'boost/*.hpp',
'boost/{accumulators,algorithm,align,archive,asio,assign,atomic,bimap,bind,chrono,circular_buffer,compatibility,compute,
concept,concept_check,config,container,context,convert,core,coroutine,coroutine2,date_time,detail,dll,dynamic_bitset,endian,exception,fiber,filesystem,
flyweight,format,function,function_types,functional,fusion,geometry,gil,graph,hana,heap,icl,integer,interprocess,intrusive,io,iostreams,iterator,lambda,lexical_cast,
local_function,locale,lockfree,log,logic,math,metaparse,move,mpi,mpl,msm,multi_array,multi_index,multiprecision,numeric,optional,parameter,pending,phoenix,polygon,
pool,predef,preprocessor,program_options,property_map,property_tree,proto,ptr_container,python,qvm,random,range,ratio,regex,serialization,signals,signals2,smart_ptr,
sort,spirit,statechart,system,test,thread,timer,tr1,tti,tuple,type_erasure,type_index,type_traits,typeof,units,unordered,utility,uuid,variant,vmd,wave,xpressive}/**/*.hpp',
'boost/xpressive/**/*.ipp'
end
s.xcconfig = { 'HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/Boost"' }
end
主要对graph-includes
字库进行了调整。在下载下来的boost
文件夹内可执行以下脚本:
#! /bin/bash
function read_dir(){
for file in `ls $1` #注意此处这是两个反引号,表示运行系统命令
do
if [ -d $1"/"$file ] #注意此处之间一定要加上空格,否则会报错
then
# echo $file
echo $file',' #在此处处理文件即可
# read_dir $1"/"$file
fi
done
}
#读取第一个参数
read_dir $1
该脚本是获取boost
下的一级文件夹名称,然后将其填入boost.podspec
中graph-includes
字库中对应的目录。
此外,还修改了:
#为了区分,私库使用大写的`B`
s.name = "Boost"
#更新版本号
s.version = "1.63.0"
#为了方便下载,这里可以把之前下载的压缩包放到自己的服务器上面,然后填上对应的地址
s.source = { :http => "http://yourhost/Spec/boost_1_63_0.tar.gz" }
#更新配置搜索库
s.xcconfig = { 'HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/Boost"' }
以上准备工作完成后,即可将对应的Boost.podspec
文件放到你的私库里面,并提交到git,然后pod update
你就能找到对应的Boost
库了。
Folly私库制作
打开node_modules/react-native/third-party-podspecs
文件夹下的Folly.podspec
,修改为如下:
Pod::Spec.new do |spec|
spec.name = 'Folly'
spec.version = '2016.09.26.00'
spec.license = { :type => 'Apache License, Version 2.0' }
spec.homepage = 'https://github.com/facebook/folly'
spec.summary = 'An open-source C++ library developed and used at Facebook.'
spec.authors = 'Facebook'
spec.source = { :git => 'http://yourhost/folly.git',
:tag => "v#{spec.version}" }
spec.module_name = 'folly'
spec.dependency 'DoubleConversion'
spec.dependency 'Glog'
spec.dependency 'Boost', '1.63.0'
spec.compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1'
spec.source_files = 'folly/Bits.cpp',
'folly/Conv.cpp',
'folly/Demangle.cpp',
'folly/StringBase.cpp',
'folly/Unicode.cpp',
'folly/dynamic.cpp',
'folly/json.cpp',
'folly/portability/BitsFunctexcept.cpp',
'folly/detail/MallocImpl.cpp',
# workaround for https://github.com/facebook/react-native/issues/14326
spec.preserve_paths = 'folly/*.h',
'folly/detail/*.h',
'folly/portability/*.h',
spec.libraries = "stdc++"
spec.pod_target_xcconfig = { "USE_HEADERMAP" => "NO",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/Boost\" \"$(PODS_ROOT)/DoubleConversion\""
}
# Pinning to the same version as React.podspec.
spec.platforms = { :ios => "8.0", :tvos => "9.2" }
end
其中修改过的内容如下:
spec.source = { :git => 'http://yourhost/folly.git',
:tag => "v#{spec.version}" }
#GLog 改为 Glog
spec.dependency 'Glog'
#'boost' 改为 'Boost', '1.63.0'
spec.dependency 'Boost', '1.63.0'
#boost 改为 Boost
spec.pod_target_xcconfig = { "USE_HEADERMAP" => "NO",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/Boost\" \"$(PODS_ROOT)/DoubleConversion\""
}
修改完成后,上传到对应的私库Folly
,使用tagv2016.09.26.00
Glog私库制作
打开node_modules/react-native/third-party-podspecs
文件夹下的GLog.podspec
,修改为Glog.podspec
,内容修改为如下:
Pod::Spec.new do |spec|
spec.name = 'Glog'
spec.version = '0.3.4'
spec.license = { :type => 'Google', :file => 'COPYING' }
spec.homepage = 'https://github.com/google/glog'
spec.summary = 'Google logging module'
spec.authors = 'Google'
spec.prepare_command = File.read("scripts/ios-configure-glog.sh")
spec.source = { :git => 'http://stash.weimob.com/scm/fas/glog.git',
:tag => "v#{spec.version}" }
spec.module_name = 'glog'
spec.source_files = 'src/glog/*.h',
'src/demangle.cc',
'src/logging.cc',
'src/raw_logging.cc',
'src/signalhandler.cc',
'src/symbolize.cc',
'src/utilities.cc',
'src/vlog_is_on.cc'
# workaround for https://github.com/facebook/react-native/issues/14326
spec.preserve_paths = 'src/*.h',
'src/base/*.h'
spec.exclude_files = "src/windows/**/*"
spec.libraries = "stdc++"
spec.pod_target_xcconfig = { "USE_HEADERMAP" => "NO",
"HEADER_SEARCH_PATHS" => "$(PODS_TARGET_SRCROOT)/src" }
# Pinning to the same version as React.podspec.
spec.platforms = { :ios => "8.0", :tvos => "9.2" }
end
其中修改过的内容如下:
spec.name = 'Glog'
#原内容为spec.prepare_command = File.read("../scripts/ios-configure-glog.sh")
spec.prepare_command = File.read("scripts/ios-configure-glog.sh")
spec.source = { :git => 'http://stash.weimob.com/scm/fas/glog.git',
:tag => "v#{spec.version}" }
修改完成后,上传到对应的私库Glog
,使用tagv0.3.4
,其中,注意需要把node_modules/react-native/scripts
文件夹也放到你对应的Spec
中,如下图所示:
DoubleConversion私库制作
打开node_modules/react-native/third-party-podspecs
文件夹下的DoubleConversion.podspec
,内容修改为如下:
Pod::Spec.new do |spec|
spec.name = 'DoubleConversion'
spec.version = '1.1.5'
spec.license = { :type => 'BSD' }
spec.homepage = 'https://github.com/google/double-conversion'
spec.summary = 'Efficient binary-decimal and decimal-binary conversion routines for IEEE doubles'
spec.authors = 'Google'
spec.prepare_command = 'mv src double-conversion'
spec.source = { :git => 'http://yourhost/doubleconversion.git',
:tag => "v#{spec.version}" }
spec.module_name = 'DoubleConversion'
spec.source_files = 'double-conversion/*.{h,cc}'
# Pinning to the same version as React.podspec.
spec.platforms = { :ios => "8.0", :tvos => "9.2" }
end
其中修改过的内容如下:
spec.source = { :git => 'http://yourhost/doubleconversion.git',
:tag => "v#{spec.version}" }
修改完成后,上传到对应的私库DoubleConversion
,使用tagv1.1.5
,
四、制作React Native私库
经过以上几步,我们的准备工作完成,可以开始制作React Native
私库。
我们找到node_modules/react-native/React.podspec
文件,修改后的内容如下:
require "json"
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1'
Pod::Spec.new do |s|
s.name = "React"
s.version = "0.49.5"
s.summary = package["description"]
s.description = <<-DESC
React Native apps are built using the React JS
framework, and render directly to native UIKit
elements using a fully asynchronous architecture.
There is no browser and no HTML. We have picked what
we think is the best set of features from these and
other technologies to build what we hope to become
the best product development framework available,
with an emphasis on iteration speed, developer
delight, continuity of technology, and absolutely
beautiful and fast products with no compromises in
quality or capability.
DESC
s.homepage = "http://facebook.github.io/react-native/"
s.license = package["license"]
s.author = "Facebook"
s.source = { :git => "http://yourhost/react.git", :tag => "v#{s.version}" }
s.default_subspec = "Core"
s.requires_arc = true
s.platforms = { :ios => "8.0", :tvos => "9.2" }
s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++14" }
s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs", "PATENTS"
s.cocoapods_version = ">= 1.2.0"
s.subspec "Core" do |ss|
ss.dependency "Yoga", "#{package["version"]}.React"
ss.source_files = "React/**/*.{c,h,m,mm,S}"
ss.exclude_files = "**/__tests__/*",
"IntegrationTests/*",
"React/DevSupport/*",
"React/Inspector/*",
"ReactCommon/yoga/*",
"React/Cxx*/*",
"React/Base/RCTBatchedBridge.mm",
"React/Executors/*"
ss.ios.exclude_files = "React/**/RCTTVView.*"
ss.tvos.exclude_files = "React/Modules/RCTClipboard*",
"React/Views/RCTDatePicker*",
"React/Views/RCTPicker*",
"React/Views/RCTRefreshControl*",
"React/Views/RCTSlider*",
"React/Views/RCTSwitch*",
"React/Views/RCTWebView*"
ss.header_dir = "React"
ss.framework = "JavaScriptCore"
ss.libraries = "stdc++"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\"" }
end
s.subspec "BatchedBridge" do |ss|
ss.dependency "React/Core"
ss.dependency "React/cxxreact_legacy"
ss.source_files = "React/Base/RCTBatchedBridge.mm", "React/Executors/*"
end
s.subspec "CxxBridge" do |ss|
ss.dependency "Folly", "2016.09.26.00"
ss.dependency "React/Core"
ss.dependency "React/cxxreact"
ss.compiler_flags = folly_compiler_flags
ss.private_header_files = "React/Cxx*/*.h"
ss.source_files = "React/Cxx*/*.{h,m,mm}"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Boost\" \"$(PODS_ROOT)/Folly\"" }
end
s.subspec "DevSupport" do |ss|
ss.dependency "React/Core"
ss.dependency "React/RCTWebSocket"
ss.source_files = "React/DevSupport/*",
"React/Inspector/*"
end
s.subspec "jschelpers_legacy" do |ss|
ss.source_files = "ReactCommon/jschelpers/{JavaScriptCore,JSCWrapper,InspectorInterfaces}.{cpp,h}", "ReactCommon/jschelpers/systemJSCWrapper.cpp"
ss.private_header_files = "ReactCommon/jschelpers/{JavaScriptCore,JSCWrapper,InspectorInterfaces}.h"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\"" }
ss.framework = "JavaScriptCore"
end
s.subspec "cxxreact_legacy" do |ss|
ss.dependency "React/jschelpers_legacy"
ss.source_files = "ReactCommon/cxxreact/{JSBundleType,oss-compat-util}.{cpp,h}"
ss.private_header_files = "ReactCommon/cxxreact/{JSBundleType,oss-compat-util}.h"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\"" }
end
s.subspec "jschelpers" do |ss|
ss.dependency "Folly", "2016.09.26.00"
ss.compiler_flags = folly_compiler_flags
ss.source_files = "ReactCommon/jschelpers/*.{cpp,h}"
ss.private_header_files = "ReactCommon/jschelpers/*.h"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/Boost\" \"$(PODS_ROOT)/Folly\"" }
ss.framework = "JavaScriptCore"
end
s.subspec "cxxreact" do |ss|
ss.dependency "React/jschelpers"
ss.dependency "Boost", "1.63.0"
ss.dependency "Folly", "2016.09.26.00"
ss.compiler_flags = folly_compiler_flags
ss.source_files = "ReactCommon/cxxreact/*.{cpp,h}"
ss.exclude_files = "ReactCommon/cxxreact/SampleCxxModule.*"
ss.private_header_files = "ReactCommon/cxxreact/*.h"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/Boost\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Folly\"" }
end
s.subspec "ART" do |ss|
ss.dependency "React/Core"
ss.source_files = "Libraries/ART/**/*.{h,m}"
end
s.subspec "RCTActionSheet" do |ss|
ss.dependency "React/Core"
ss.source_files = "Libraries/ActionSheetIOS/*.{h,m}"
end
s.subspec "RCTAdSupport" do |ss|
ss.dependency "React/Core"
ss.source_files = "Libraries/AdSupport/*.{h,m}"
end
s.subspec "RCTAnimation" do |ss|
ss.dependency "React/Core"
ss.source_files = "Libraries/NativeAnimation/{Drivers/*,Nodes/*,*}.{h,m}"
ss.header_dir = "RCTAnimation"
end
s.subspec "RCTBlob" do |ss|
ss.dependency "React/Core"
ss.source_files = "Libraries/Blob/*.{h,m}"
ss.preserve_paths = "Libraries/Blob/*.js"
end
s.subspec "RCTCameraRoll" do |ss|
ss.dependency "React/Core"
ss.dependency 'React/RCTImage'
ss.source_files = "Libraries/CameraRoll/*.{h,m}"
end
s.subspec "RCTGeolocation" do |ss|
ss.dependency "React/Core"
ss.source_files = "Libraries/Geolocation/*.{h,m}"
end
s.subspec "RCTImage" do |ss|
ss.dependency "React/Core"
ss.dependency "React/RCTNetwork"
ss.source_files = "Libraries/Image/*.{h,m}"
end
s.subspec "RCTNetwork" do |ss|
ss.dependency "React/Core"
ss.source_files = "Libraries/Network/*.{h,m,mm}"
end
s.subspec "RCTPushNotification" do |ss|
ss.dependency "React/Core"
ss.source_files = "Libraries/PushNotificationIOS/*.{h,m}"
end
s.subspec "RCTSettings" do |ss|
ss.dependency "React/Core"
ss.source_files = "Libraries/Settings/*.{h,m}"
end
s.subspec "RCTText" do |ss|
ss.dependency "React/Core"
ss.source_files = "Libraries/Text/*.{h,m}"
end
s.subspec "RCTVibration" do |ss|
ss.dependency "React/Core"
ss.source_files = "Libraries/Vibration/*.{h,m}"
end
s.subspec "RCTWebSocket" do |ss|
ss.dependency "React/Core"
ss.dependency "React/RCTBlob"
ss.dependency "React/fishhook"
ss.source_files = "Libraries/WebSocket/*.{h,m}"
end
s.subspec "fishhook" do |ss|
ss.header_dir = "fishhook"
ss.source_files = "Libraries/fishhook/*.{h,c}"
end
s.subspec "RCTLinkingIOS" do |ss|
ss.dependency "React/Core"
ss.source_files = "Libraries/LinkingIOS/*.{h,m}"
end
s.subspec "RCTTest" do |ss|
ss.dependency "React/Core"
ss.source_files = "Libraries/RCTTest/**/*.{h,m}"
ss.frameworks = "XCTest"
end
s.subspec "_ignore_me_subspec_for_linting_" do |ss|
ss.dependency "React/Core"
ss.dependency "React/CxxBridge"
end
end
主要修改内容如下:
#删除了如下内容
version = package['version']
source = { :git => 'https://github.com/facebook/react-native.git' }
if version == '1000.0.0'
# This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in.
source[:commit] = `git rev-parse HEAD`.strip
else
source[:tag] = "v#{version}"
end
#修改的内容如下
s.version = "0.49.5"
s.source = { :git => "http://yourhost/react.git", :tag => "v#{s.version}" }
#yoga 改为Yoga
ss.dependency "Yoga", "#{package["version"]}.React"
#CxxBridge 子库修改如下配置
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Boost\" \"$(PODS_ROOT)/Folly\"" }
#jschelpers 子库修改如下配置
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/Boost\" \"$(PODS_ROOT)/Folly\"" }
#cxxreact 子库修改如下配置
ss.dependency "Boost", "1.63.0"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/Boost\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Folly\"" }
#删除tvOS子库,如使用可不删
s.subspec "tvOS" do |ss|
ss.dependency "React/Core"
ss.source_files = "React/**/RCTTVView.{h, m}"
end
私库的内容如下:
直接拷贝了
node_modules/react-native
中的文件到你的私库中,然后修改其中的podspec文件(如上所示)。
此外,因为引用的关系,需要修改两个文件的引用:
YourSpec/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h文件中
修改
#import
为
#import
YourSpec/Libraries/WebSocket/RCTReconnectingWebSocket.m文件中
修改
#import
为
#import
上传到对应的私库React ,使用tagv0.49.5
,其中,注意需要把YourSpec/package.json文件也放到你对应的Spec中,如下图所示:
然后在你项目中,pod React
就可以了,记得加入
source 'https://github.com/CocoaPods/Specs.git' #官方仓库地址
source 'http://yourhost/wfspecs.git'
然而,可能也许你会遇到跟我一样的问题,
#import "unistd.h" 'unistd.h' not found
FMDB
中有两处这样的导入,使用"
导入的话,会优先导入本项目的文件,因为Folly
中存在此文件,会优先使用该文件,但是很明显FMDB
希望使用的是系统库中的文件。基于FMDB
比较稳定了,暂时只能制作了一份其私库,并修改了对应文件的头部引用。待有更好的方法好再修正。
以上是本次制作的过程,与主要文件。欢迎提问~
附各私库文件目录:
Yoga
Boost
不需要建立单独的git项目,只需将Boost.podpsec
上传到Specs
中