如何使用React Native Android 实现本地组件的安装
展开全部
使用RN-android 时有时会发现,运行某个组件时,报js组件找不到的问题,参考下面的步骤:
demo 参考:
https://github.com/larsvinter/react-native-awesome-button
在js中 require失败的问题,大多数是require的那个东西(实际就是一个js文件),并没有部署在当前的node服务器里,所以解决办法就是把那个js文件手动copy一份到启动react-js的node服务器目录下
npm install -g 中-g是globel的意思
require 寻找顺序是依次寻找上级目录
可以通过react-native android在当前目录下创建一个包括rn骨架的工程
默认引用index.android.js
直接自定义使用也是不行的
Command
`run-myReactAndroid` unrecognized Usage:
react-native
Commands:
start: starts the webserver install: installs npm react components
bundle: builds the javascript bundle for offline use new-library:
generates a native library bridge android: generates an Android
project for your app
packager的启动可以执行 react-native start
可能遇到一些error【graldew wrapper 出错】,使用 gradlew installDebug/installRelease 直接执行
$ ./gradlew assemble -为所有构建类型创建apk
$ ./gradlew check 运行所有的检查,比如说Android Lint,如果发现问题可终止任务 $ ./gradlew build 运行以上两个任务
$ ./gradlew clean -清除生成的apk ++++
$ ./gradlew connectedCheck - 在设备上运行测试
$ ./gradlew deviceCheck - 远程设备运行测试
$ ./gradlew installDebug/installRelease - 在设备商安装指定版本
$ ./gradlew uninstall - 卸载
所有gradlew命令:
luoyuandeMacBook-Pro% gradlew tasks
:tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Android tasks
-------------
androidDependencies - Displays the Android dependencies of the project.
signingReport - Displays the signing info for each variant.
sourceSets - Prints out all the source sets defined in this project.
Build tasks
-----------
assemble - Assembles all variants of all applications and secondary packages.
assembleAndroidTest - Assembles all the Test applications.
assembleDebug - Assembles all Debug builds.
assembleRelease - Assembles all Release builds.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
clean - Deletes the build directory.
compileDebugAndroidTestSources
compileDebugSources
compileDebugUnitTestSources
compileReleaseSources
compileReleaseUnitTestSources
mockableAndroidJar - Creates a version of android.jar that's suitable for unit tests.
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
components - Displays the components produced by root project 'AliReactAndroid'. [incubating]
dependencies - Displays all dependencies declared in root project 'AliReactAndroid'.
dependencyInsight - Displays the insight into a specific dependency in root project 'AliReactAndroid'.
help - Displays a help message.
projects - Displays the sub-projects of root project 'AliReactAndroid'.
properties - Displays the properties of root project 'AliReactAndroid'.
tasks - Displays the tasks runnable from root project 'AliReactAndroid' (some of the displayed tasks may belong to subprojects).
Install tasks
-------------
installDebug - Installs the Debug build.
installDebugAndroidTest - Installs the android (on device) tests for the Debug build.
uninstallAll - Uninstall all applications.
uninstallDebug - Uninstalls the Debug build.
uninstallDebugAndroidTest - Uninstalls the android (on device) tests for the Debug build.
uninstallRelease - Uninstalls the Release build.
Verification tasks
------------------
check - Runs all checks.
connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
connectedCheck - Runs all device checks on currently connected devices.
connectedDebugAndroidTest - Installs and runs the tests for debug on connected devices.
deviceAndroidTest - Installs and runs instrumentation tests using all Device Providers.
deviceCheck - Runs all device checks using Device Providers and Test Servers.
lint - Runs lint on all variants.
lintDebug - Runs lint on the Debug build.
lintRelease - Runs lint on the Release build.
test - Run unit tests for all variants.
testDebugUnitTest - Run unit tests for the debug build.
testReleaseUnitTest - Run unit tests for the release build.
Other tasks
-----------
jarDebugClasses
jarReleaseClasses
To see all tasks and more detail, run with --all.
Adding Android to an existing React Native project
If you already have a (iOS-only) React Native project and want to add Android support, you need to execute the following commands in your existing project directory:
Update the
react-native
dependency in your
package.json
file to
the latest version
$ npm install
$ react-native android
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询