RN真是個(gè)巨坑,只有本文章的最后一個(gè)坑,我沒(méi)踏過(guò),其他都入坑了
或是
解決:更改APP下的gradle
defaultConfig {
applicationId "com.example.laer.rn_demo"
minSdkVersion 18
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
packagingOptions {
exclude "lib/arm64-v8a/librealm-jni.so"
}
金典bug:這個(gè)bug况凉,基本是剛開(kāi)始將RN集成到原生安卓項(xiàng)目必現(xiàn)的bug
原因:多半是因?yàn)闆](méi)有生產(chǎn)打包所需要的bundle文件(也就是沒(méi)有圖中的文件)
出現(xiàn)這種情況的可能性還比較多,可以看這里:
ReferenceError:Can't find variable: _fbBatchedBridge · Issue #6425 · facebook/react-native · GitHub
解決:我們先在main下面創(chuàng)建asserts文件夾各拷,然后進(jìn)入工程根目錄打開(kāi)cmd輸入
react-native bundle --platform android --entry-file index.android.js --bundle-output app/src/main/assets/index.android.bundle --dev false
(注意-output后面的參數(shù)根據(jù)自己的項(xiàng)目目錄結(jié)構(gòu)來(lái)寫(xiě))
成功后的項(xiàng)目
如果搖晃手機(jī)重新加載js報(bào)錯(cuò)Unable to download JS bundle
兩種產(chǎn)生此問(wèn)題的可能(我遇到的):
①第一種可能:沒(méi)設(shè)置第三步的ip刁绒,按照如下方法設(shè)置就行了
②第二種可能:在瀏覽器輸入http://localhost:8081/index.android.bundle?platform=android,結(jié)果如下:
如果出現(xiàn)上面的界面烤黍,有可能就是你的server沒(méi)打開(kāi)膛锭,命令 react-native start
這個(gè)時(shí)候重新輸入以上的url,瀏覽器顯示下圖:
java.lang.IllegalAccessError: Method ‘void android.support.v4.net.ConnectivityManagerCompat.<init>()’
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
解決辦法:把support相關(guān)包改成23.0.1
compile 'com.android.support:appcompat-v7:23.0.1'
出現(xiàn)Got JS Exception: TypeError: undefined is not a function (evaluating ‘(bridgeConfig.remoteModuleConfig || []).forEach’) 的錯(cuò)誤蚊荣,原因是被官方文檔坑了初狰,官方文檔是這樣描述的:
allprojects {
repositories {
...
maven {
// All of React Native (JS, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
...
}
然而正確應(yīng)該是(這里還是要根據(jù)自己的項(xiàng)目結(jié)構(gòu)來(lái)配置路徑,但是不出意外都是下面的):
allprojects {
repositories {
jcenter()
maven {
// All of React Native (JS, Android binaries) is installed from npm
url "$rootDir/node_modules/react-native/android"
}
}
}
Error:Conflict with dependency 'com.google.code.findbugs:jsr305'
——這個(gè)stackoverflow有解答
解決方式是在app的build.gradle中添加 androidTestCompile 'com.google.code.findbugs:jsr305:3.0.0'互例。