1.
Application NaticeHybrid has not been registered.This is either due to a require() error during initialization or failure to call AppRegistry.registerComponent.
AppRegistry.registerComponent('RnTestProject', () => HelloWorld);
Activity里getMainComponentName的return返回值要和RN注冊值"RnTestProject"保持一致
2.
Caused by: java.lang.UnsatisfiedLinkError: could find DSO to load: libreactnativejni.so
Android不能同時加載32和64位本機庫稚伍。 如果您至少有一個依賴庫使用ARM64支持編譯的擴展,而另外一些依賴庫僅支持ARM32,就會出現(xiàn)問題嫩絮。 系統(tǒng)將檢測ARM64依賴關系悴品,加載它语盈,然后拒絕加載僅ARM32的so庫沙合,就可能導致應用程序崩潰积糯。
需要修改app的build.gradle绊茧,將ndk铝宵,packagingOptions配置一下
defaultConfig {
applicationId "com.ghp.rn.rntestproject"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk{
abiFilters "armeabi-v7a","x86"
}
packagingOptions {
exclude "lib/arm64-v8a/libimagepipeline.so"
}
}
3.
在原生應用調轉到RN頁面的時候,會出現(xiàn)大概1s的白屏現(xiàn)象.
解決方法:把創(chuàng)建ReactRootView以及獲取jsbundle的操作放入到Native代碼中华畏,比如放置到啟動頁或者跳轉到RN界面的前一個頁面等等.總之保證打開的時候已經(jīng)緩存OK
待測試鹏秋!
4.
Brownfield | Stetho | “:com.facebook.stetho:stetho-okhttp:1.2.0' depends on one or more Android Libraries but is a jar”
Add to dependencies:
compile ("com.facebook.react:react-native:+") {
exclude group:'com.facebook.stetho', module:'stetho'
}
5.
can’t find \node_modules\react-native\local-cli\cli.js
重新npm install,把缺少的東西安裝上
6.
Could not find property’JIMU_RELEASE_STORE_FILE’* on SigningConfig_Decorated{name=release, storeFile=null, storePassword=null, keyAlias=null, keyPassword=null, storeType=null}.
刪除掉android/app/build.gradle 里的:
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
7.
“npm notice created a lockfile as package-lock.json. You should commit this file.” How to commit it?
git add --all亡笑, git commit -m "commit" 忽略過
8.
Exception in native call from JS
java.lang.RuntimeException: ReferenceError: Can’t find variable: __fbBatchedBridge
這個糾結了很久
在package.json里配置
"bundle-android":
"react-native bundle --platform android --dev false --entry-file index.android.js
--bundle-output android/RnTestProject/app/src/main/assets/index.android.bundle
--sourcemap-output
android/RnTestProject/app/src/main/assets/index.android.map
--assets-dest
android/RnTestProject/app/src/main/res/"
需要注意:
- 路徑需要和自己項目的路徑一致侣夷。
- 有的是 index.android.js,看看自己創(chuàng)建的是不是這個名字仑乌,還是 index.js百拓。
- 沒有assets文件夾琴锭,需要手動創(chuàng)建一下,搜索有說index.android.bundle也需要手動先創(chuàng)建耐版。
- activity里創(chuàng)建的
ReactRootView?.startReactApplication(mReactInstanceManager, "RnTestProject", null)
第二個參數(shù)moduleName需要合RN注冊的值"RnTestProject"保持一致祠够。
- 在項目的 build.gradle 文件中為 React Native 添加一個 maven 依賴的入口,必須寫在 "allprojects" 代碼塊中:
allprojects {
repositories {
...
maven {
// All of React Native (JS, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
...
}
確保依賴路徑的正確粪牲!以免在 Android Studio 運行Gradle同步構建時拋出 “Failed to resolve: com.facebook.react:react-native:0.x.x" 異常古瓤。
node_modules已經(jīng)在根目錄的話,需要去除../
當項目和node_modules不在一起的時候可以使用絕對路徑 腺阳。
執(zhí)行完之后落君,查看手機或者模擬器是否和你的RN服務端在同一個局域網(wǎng)內
在執(zhí)行 npm run bundle-android 時,可能會報IP問題亭引,按著提示 kill -9 ip值绎速,然后 npm start,studio build
發(fā)現(xiàn)執(zhí)行完焙蚓,index.android.bundle里沒有內容纹冤,APP運行起來打開依然奔潰,依然提示該錯誤
curl "http://localhost:8081/index.android.bundle?platform=android"
-o "android/RnTestProject/app/src/main/assets/index.android.bundle"
執(zhí)行這句index.android.bundle依然沒有內容的話购公,直接打開http://localhost:8081/index.android.bundle?platform=android萌京,
將獲取到的內容復制到index.android.bundle里
然后繼續(xù)重新運行
9.
修改js文件,reload之后沒效果:
要解決辦法宏浩,修改MAX WAIT_TIME變量知残,項目路徑
/node_modules/react-native/packager/react-packager/src/node-haste/FileWatcher/index.js
中的MAX WAIT_TIME值改得更大一些;
const MAX_WAIT_TIME = 120000;
const MAX_WAIT_TIME = 360000; //改大一些以便node服務可以將js的修改打包到bundle文件中比庄。
找到如下代碼
key: '_createWatcher',
value: function _createWatcher(rootConfig) {
var watcher = new WatcherClass(rootConfig.dir, {
glob: rootConfig.globs,
dot: false
});
return new Promise(function (resolve, reject) {
var rejectTimeout = setTimeout(function () {
return reject(new Error(timeoutMessage(WatcherClass)));
}, MAX_WAIT_TIME);
watcher.once('ready', function () {
clearTimeout(rejectTimeout);
resolve(watcher);
});
});
}
//修改為
key: '_createWatcher',
value: function _createWatcher(rootConfig) {
var watcher = new WatcherClass(rootConfig.dir, {
glob: rootConfig.globs,
dot: false
});
return new Promise(function (resolve, reject) {
const rejectTimeout = setTimeout(function() {
reject(new Error([
'Watcher took too long to load',
'Try running `watchman version` from your terminal',
'https://facebook.github.io/watchman/docs/troubleshooting.html',
].join('\n')));
}, MAX_WAIT_TIME);
watcher.once('ready', function () {
clearTimeout(rejectTimeout);
resolve(watcher);
});
});
}
修改和之后要重啟React Packager求妹。
最新的RN已經(jīng)沒有這個這個問題了,只要你啟動hot loading佳窑,修改js后就會自動加載制恍。
10.
The development server returned response error code: 500 in react-native
tries to require 'react-native',
but there are several files providing this module.
You can delete or fix them: ……
找到多余的files,刪除后報這個:
Unable to resolve module `react/lib/ReactComponentWithPureRenderMixin` from `/Users/song/Desktop/ReactNativeRouterFlux/node_module s/react-native-experimental-navigation/node_modules/react-addons-pure-render-mixin/index.js`: Module does not exist in the module map or in these directories:
類似這種錯誤神凑,就是缺少模塊吧趣,通過
npm i react-addons-pure-render-mixin -S
命令即可,標記部分是你缺少的模塊名耙厚。
如果還不行的話强挫,就把node_modules刪除,再重新建立
11.
undefined is not an object(evaluating 'HotUpdate.downloadRootDir')
需要在getPackages方法中添加new UpdatePackage()薛躬;
rn0.29后在Mainapplication中俯渤,rn0.29前在MainActivity中:
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new UpdatePackage()
);
}
記得導包:
import cn.reactnative.modules.update.UpdatePackage;
12.
Error: Cannot find module 'metro-bundler/src/babelRegisterOnly'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/ghp/c_work/RN/AwesomeProject/node_modules/react-native-update/local-cli/lib/bundle.js:439:9)
at next (native)
at step (/Users/ghp/c_work/RN/AwesomeProject/node_modules/react-native-update/local-cli/lib/bundle.js:310:191)
at /Users/ghp/c_work/RN/AwesomeProject/node_modules/react-native-update/local-cli/lib/bundle.js:310:361
將node_modules\react-native-update\local-cli\lib\bundle.js的439行種的metro-bundler改成metro可成功運行;
13.
unable to load script from assets ‘index.android bundle’ ,make sure your bundle is packaged correctly or youu’re runing a packager server
In project directory,
* `mkdir android/app/src/main/assets`
* `react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res`
* `react-native run-android`
14.
uncaughtException:couldn't find DSO to load: libreactnativejni.so
修改app的build.gradle:
defaultConfig {
...
minSdkVersion 16
...
ndk{
abiFilters "armeabi-v7a","x86"
}
packagingOptions {
exclude "lib/arm64-v8a/libimagepipeline.so"
}
}
15.
uncaughtException:Unable to load script from assets 'index.android.bundle'.
Make sure your bundle is packaged correctly or you're running a packager server.
reload之后型宝,變?yōu)?/p>
Could not connect to development server
看是否啟動 npm start八匠,adb是否連接絮爷,WiFi是否連接同一個IP,
我是Dev Setting設置IP重啟OK的梨树,如圖:
16. Can't find variable: CodePush
原先demo添加了熱更新的邏輯坑夯,現(xiàn)在將項目遷移至Android目錄夾,實現(xiàn)Android原生頁面跳轉RN頁面抡四,index.js在registerComponent時設置了CodePush,去掉后頁面正常打開柜蜈,熱更新如何修改待定
17.
按照官網(wǎng)文檔集成到現(xiàn)有原生應用,需要自建ReactRootView指巡,其實ReactActivity已經(jīng)幫我們做了這些淑履,新建activity直接繼承ReactActivity就可以。
ReactInstanceManager.builder()
.setApplication(application)
.setBundleAssetName("index.android.bundle")
.setJSMainModulePath("index")
...
在自建ReactRootView時藻雪,查看RN源碼會發(fā)現(xiàn)assets取的路徑在assets文件夾秘噪,需要在main目錄下創(chuàng)建assets文件夾,生成index.android.bundle文件勉耀,index.android.map是標識文件指煎,可以不用
在assets文件夾生成index.android.bundle文件,將bundles里的該文件復制過來也可以:
react-native bundle --entry-file index.js --bundle-output
./android/app/src/main/assets/index.android.bundle --platform android
--assets-dest ./android/app/src/main/res/ --dev false
18
console.error:"React Native version mismatch.
JavaScript version:0.54.4
Native version:0.55.3
..."
這個問題需要指定下版本便斥,有2種修改方式:
(參考https://github.com/facebook/react-native/issues/19259)
第一種將app/build.gradle修改
//compile "com.facebook.react:react-native:+" // From node_modules
compile ("com.facebook.react:react-native:0.55.3") { force = true }// From node_modules
第二種在根目錄的build.gradle修改
allprojects {
repositories {
...
}
// 版本 指定
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.facebook.react' && details.requested.name == 'react-native') {
details.useVersion "0.55.3" //你當前react native 版本
}
}
}
}
}