快速上手React Native

React Native 是facebook 开源的一套用于开发移动端跨平台App的技术框架,下面为大家讲解一下React Native安装和使用。

环境

  1. 安装homebrew
  2. 安装nodejs
  3. 安装watchman、flow
  4. 安装react-native

新建项目

react-native init JustNoCode

执行之后,一直卡在Installing react-native package from npm…,但是, 我等了两天,终于成功了:

@feng   github  react-native init JustNoCodeprompt: Directory JustNoCode already exist. Continue?:  (no) yThis will walk you through creating a new React Native project in /Users/fengjian/Code/github/JustNoCodeInstalling react-native package from npm...Setting up new React Native app in /Users/fengjian/Code/github/JustNoCodecreate .gitignorecreate .watchmanconfigcreate index.ios.jscreate index.Android.jscreate ios/main.jsbundlecreate ios/JustNoCode/AppDelegate.hcreate ios/JustNoCode/AppDelegate.mcreate ios/JustNoCode/Base.lproj/LaunchScreen.xibcreate ios/JustNoCode/Images.xcassets/AppIcon.appiconset/Contents.jsoncreate ios/JustNoCode/Info.plistcreate ios/JustNoCode/main.mcreate ios/JustNoCodeTests/JustNoCodeTests.mcreate ios/JustNoCodeTests/Info.plistcreate ios/JustNoCode.xcodeproj/project.pbxprojcreate ios/JustNoCode.xcodeproj/xcshareddata/xcschemes/JustNoCode.xcschemecreate android/app/build.gradlecreate android/app/proguard-rules.procreate android/app/src/main/AndroidManifest.xmlcreate android/app/src/main/res/values/strings.xmlcreate android/app/src/main/res/values/styles.xmlcreate android/build.gradlecreate android/gradle.propertiescreate android/settings.gradlecreate android/app/src/main/res/mipmap-hdpi/ic_launcher.pngcreate android/app/src/main/res/mipmap-mdpi/ic_launcher.pngcreate android/app/src/main/res/mipmap-xhdpi/ic_launcher.pngcreate android/app/src/main/res/mipmap-xxhdpi/ic_launcher.pngcreate android/gradle/wrapper/gradle-wrapper.jarcreate android/gradle/wrapper/gradle-wrapper.propertiescreate android/gradlewcreate android/gradlew.batcreate android/app/src/main/Java/com/justnocode/MainActivity.javaTo run your app on iOS:Open /Users/fengjian/Code/github/JustNoCode/ios/JustNoCode.xcodeproj in XcodeHit Run buttonTo run your app on Android:Have an Android emulator running, or a device connectedcd /Users/fengjian/Code/github/JustNoCodereact-native run-android

显示详细信息

运行Android

react-native run-android

结果报错,如下:

@feng   JustNoCode (master)  react-native run-androidStarting JS server...Building and installing the app on the device (cd android && ./gradlew installDebug)...Download https://jcenter.bintray.com/com/android/tools/build/gradle/1.3.1/gradle-1.3.1.pomDownload https://jcenter.bintray.com/com/android/tools/build/gradle-core/1.3.1/gradle-core-1.3.1.pom... ...Download https://jcenter.bintray.com/com/android/tools/lint/lint-api/24.3.1/lint-api-24.3.1.jarFailed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.java.lang.RuntimeException: SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.    at com.android.build.gradle.internal.SdkHandler.getAndCheckSdkFolder(SdkHandler.java:102)    ... ...    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMainin.java:61)FAILURE: Build failed with an exception.* Where:Build file '/Users/fengjian/Code/github/JustNoCode/android/app/build.gradle' line: 20* What went wrong:A problem occurred evaluating project ':app'.> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.* Try:Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.BUILD FAILEDTotal time: 52.605 secsCould not install the app on the device, see the error above.

显示详细信息

在.zshrc中配置一下ANDROID_HOME:

export ANDROID_HOME=~/Tools/android-sdk

再运行一次,

@feng   JustNoCode (master)  react-native run-androidJS server already running.Building and installing the app on the device (cd android && ./gradlew installDebug)...:app:preBuild UP-TO-DATE... ...:app:installDebugInstalling APK 'app-debug.apk' on 'Google Nexus S - 4.1.1 - API 16 - 480x800 - 4.1.1'Installed on 1 device.BUILD SUCCESSFULTotal time: 10.294 secsThis build could be faster, please consider using the Gradle Daemon: http://gradle.org/docs/2.4/userguide/gradle_daemon.htmlStarting the app (/Users/fengjian/Tools/android-sdk/platform-tools/adb shell am start -n com.justnocode/.MainActivity)...Starting: Intent { cmp=com.justnocode/.MainActivity }

显示详细信息

成功了,显示了MainActivity,一个简单的说明页面,

文章来源网络,作者:管理,如若转载,请注明出处:https://shuyeidc.com/wp/220122.html<

(0)
管理的头像管理
上一篇2025-04-14 10:27
下一篇 2025-04-14 10:28

相关推荐

  • 服务器磁盘IO过高如何优化?,磁盘IO过高的原因有哪些?

    服务器磁盘IO过高,核心优化路径是“先定位、再分流、后升级”,你需要通过系统工具精确判断究竟是应用程序、日志策略还是硬件瓶颈导致,然后针对性地从代码、缓存、存储架构和硬件选型四个层面下手,其中选择持有持牌自营机房和增值电信业务经营许可证的服务商,能从根本上保障底层IO稳定性,定位IO瓶颈:动手优化的第一步盲目优……

    2026-07-27
    0
  • 跨境网站访问延迟高怎么解决,网站访问慢的原因是什么?

    跨境网站访问延迟高的核心解决思路在于多维度优化网络路径,包括使用全球CDN加速、选择靠近目标区域的优质IDC机房、调整传输协议以及精简应用层资源,其中服务商的基础设施质量直接决定优化上限,为什么跨境访问延迟高?三大核心因素物理距离与光速限制数据包在海底光缆中的传输速度受限于介质,从中国到美国西海岸的物理往返时间……

    2026-07-27
    0
  • 站群服务器到底是什么意思,怎么选择比较好

    站群服务器就是一台拥有多个独立IP地址、专门用于托管和管理多个网站的高性能服务器,其核心价值在于通过独立IP降低网站间的关联风险,并提升搜索引擎优化效果,站群服务器的工作原理与适用场景站群服务器本质上是将一台物理服务器通过虚拟化或直接配置的方式,分配给多个独立IP地址,每个IP对应一个独立的网站,这些网站共享服……

    2026-07-27
    0
  • 高防服务器误封正常流量如何调整,怎么解决?

    高防服务器误封正常流量,核心调整思路是从“一刀切”转向“精细化”——通过分析业务特征,调整防护阈值、配置白名单和启用智能学习模式,让防护系统学会区分真假流量,为什么会误封正常流量误封主要源于防护策略的通用化,高防服务器通常默认启用严格防护规则,当流量特征与攻击特征库部分匹配时,就会被拦截,据行业安全白皮书指出……

    2026-07-27
    0
  • 高防服务器的防御原理是什么,如何选择高防服务器?

    高防服务器的防御原理,简单说就是通过流量清洗、防火墙规则和黑洞路由等机制,在攻击流量到达业务服务器之前将其过滤或阻断,从而保障正常访问,流量清洗机制是核心防线高防服务器对抗DDoS攻击,靠的不是单一技术,而是一套组合动作,最常见的攻击类型是流量型攻击,比如UDP洪水、SYN洪水、ICMP放大等,核心思路是耗尽带……

    2026-07-26
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注