Open doin opened 6 years ago
this.props.navigation.setParams({name:"可以的"})
warning encountered 1 time. remote debugger is in a background tab which may cause apps to perform slowly. fix this by foregrounding the tab (or opening it in a separate window)
翻译: 远程调试器处于后台选项卡,可能会导致应用程序执行缓慢。 通过前面的选项卡(或在单独的窗口中打开它)来解决这个问题
打开"RCTWebSocketExecutor.m "文件,将“localhost”改为你的电脑的ip,然后在Developer Menu下单击"Debug JS Remotely" 启动JS远程调试功能。
方式一: 在Android5.0以上设备上,将手机通过usb连接到你的电脑,然后通过adb命令行工具运行如下命令来设置端口转发。 adb reverse tcp:8081 tcp:8081
方式二: 你也可以通过在“Developer Menu”下的“Dev Settings”中设置你的电脑ip来进行调试。
心得:在使用真机调试时,你需要确保你的手机和电脑处在同一个网段内,即它们实在同一个路由器下。
devtool: shouldUseSourceMap ? false : false
vendor: [require.resolve('./polyfills'), "react", "react-dom", "react-router"]
通过嵌套来实现背景图片
开发者们常面对的一种需求就是类似web中的背景图(background-image)。要实现这一用例,只需简单地创建一个<Image>组件,然后把需要背景图的子组件嵌入其中即可。
return (
<Image source={...}>
<Text>Inside</Text>
</Image>
);
react-native bundle --entry-file index.ios.js --platform ios --dev false --bundle-output ios/ios.jsbundle
//jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"ios" withExtension:@"jsbundle"];
info.plist => Bundle name 修改
Installing APK 'app-debug.apk' on 'm2 note - 5.1' for app:debug
09:03:40 E/341473558: Error while uploading app-debug.apk : Unknown failure ([CDS]close[0])
Unable to install /Users/doin/Desktop/coding/DoctorRN/android/app/build/outputs/apk/app-debug.apk
com.android.ddmlib.InstallException: Failed to install all
at com.android.ddmlib.SplitApkInstaller.install(SplitApkInstaller.java:89)
at com.android.ddmlib.Device.installPackages(Device.java:904)
at com.android.builder.testing.ConnectedDevice.installPackages(ConnectedDevice.java:137)
at com.android.build.gradle.internal.tasks.InstallVariantTask.install(InstallVariantTask.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
解决
安装错误: Gradle 的编译版本过高, 不兼容部分5.0+手机, 需要降低版本为 1.3.
Installing APK 'app-debug.apk' on 'HUAWEI GRA-TL00 - 5.0.1' for app:debug
Error while uploading app-debug.apk : Unknown failure ([CDS]close[0])
使用AndroidStudio安装的时候,IDE提供了app运行时需要的权限,所以直接使用Debug就可以安装。而使用react-native run-android有这样的问题是因为没有获得权限,所以没法往真机上装应用。
有两种解决办法,一是降低gradle的build版本,改为1.2.3;另一种是升级你的React-Native至最新版本。
打开 React Native 的项目, 修改最外层工程的 build.gradle 配置, 降低 gradle 的 build 为1.2.3版本.
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3' // 修改1.2.3
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
}
}
这个时候还是会报错,需要重新设置 Gradle 的 Wrapper , 修改为2.2版本.
Gradle version 2.2 is required. Current version is 2.11
修改Gradle的Wrapper版本,需要修改android/griddle/wrapper/grade-wrapper.properties文件:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip
报错: 安卓真机上启动后白屏
报错: 真机红屏(同网段不需要)
摇一摇DEBUG窗不显示:
5.0和5.0以下真机调试的不同方式
react-native bundle --entry-file index.android.js --bundle-output ./android/app/src/main/assets/index.android.jsbundle --platform android --assets-dest ./android/app/src/main/res/ --dev false
// 生成key,把文件拉到APP文件夹DoctorRN-release-key.keystore
$ keytool -genkey -v -keystore DoctorRN-release-key.keystore -alias DoctorRN-key-alias -keyalg RSA -keysize 2048 -validity 10000
// 配置build.gradle
signingConfigs {
release {
storeFile file("./DoctorRN-release-key.keystore")
storePassword "starfish"
keyAlias "DoctorRN-key-alias"
keyPassword "starfish"
}
}
cd android && ./gradlew assembleRelease
// 修改react-native-root-siblings/lib/AppRegistryInjection.js文件
import EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter';
//import EventEmitter from 'react-native/Libraries/EventEmitter/EventEmitter';
http://blog.csdn.net/fsf_snail/article/details/71080827
onNavigationStateChange = (navState) => {
console.log("navState", navState);
Actions.refresh({title:navState.title});
this.setState({
backButtonEnabled: navState.canGoBack,
forwardButtonEnabled: navState.canGoForward,
url: navState.url,
status: navState.title,
loading: navState.loading,
scalesPageToFit: true
});
};
I was able to solve this error by:
Opening the project in XCode
Navigate to Build Phases > Bundle React Native code and images
Change export NODE_BINARY=node
../node_modules/react-native/packager/react-native-xcode.sh to export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh
Notice how packager is now scripts, which is where that file actually lives in latest version of RN
What is the meaning of 'No bundle URL present' in react-native?
https://github.com/facebook/react-native/issues/12754
https://blog.csdn.net/shalyf/article/details/71629617 apple mach-o linker error 报错解决 https://blog.csdn.net/mushaofeng1990/article/details/53159147 只要在电脑上找到这个文件夹,删除下面所有的缓存文件,然后clean一下项目,再编译运行,就没有问题了。
上图中的 /Users/apple/Library/Developer/Xcode/DerivedData 中的apple 是我本机的用户名,替换成自己的用户名就可以了。
found 'config.h'
安装环境
react-native init MyApp --version 0.44.3
测试环境
HELLO WORLD
学习参考