【问题标题】:React Native android builds very slow ( > 3min)React Native android 构建速度非常慢(> 3 分钟)
【发布时间】:2017-02-21 15:34:03
【问题描述】:

在我的 React Native 应用程序中,我在 android 上遇到了非常缓慢的构建时间和非常差的调试性能,而在构建之前大约 30 秒,并且在启用远程调试的情况下运行该应用程序在某种程度上是易于管理的。我不确定是什么导致了这种情况,但以下是我在运行 react-native run-android 时看到的一些症状:

1) 所有依赖项都作为单独的 APK 安装在我的设备上

对于我的应用程序中的每个依赖项,我都会在构建日志中看到以下内容:

...
Installing APK 'react-native-toast-debug-androidTest.apk' on 'Google Nexus 5X - 6.0.0 - API 23 - 1080x1920 - 6.0' for react-native-toast:debugAndroidTest
Installed on 1 device.
...
Installing APK 'react-native-vector-icons-debug-androidTest.apk' on 'Google Nexus 5X - 6.0.0 - API 23 - 1080x1920 - 6.0' for react-native-vector-icons:debugAndroidTest
Installed on 1 device.
...

2) 使用了错误的构建工具版本

这个警告可能是由每个依赖项目中指定的构建工具版本引起的,但是:

Running dex in-process requires build tools 23.0.2.
For faster builds update this project to use the latest build tools.

在我的 build.gradle 中,我将构建工具版本定义为 23.2.3

android {
    compileSdkVersion 23
    buildToolsVersion "23.2.3"

3) Adb 调用失败

在构建结束时,会显示此消息,并且应用程序不会在我的设备上自动启动:

adb invocation failed. Do you have adb in your PATH?

即使我的 PATH (.bashrc) 中有 adb

export PATH="/Users/Juuso/Library/Android/sdk/platform-tools":$PATH

...我可以在我的项目目录中运行 adb 命令

【问题讨论】:

    标签: android build react-native react-native-android


    【解决方案1】:

    如果你像我一样在 android/app/build.gradle 中添加 buildTypes 或 productFlavors。

    不要运行react-native run-android

    改用react-native run-anroid --variant [flavorBuildType]

    flavorBuildType 可以是以下任何一种。

    1. 调试
    2. 发布
    3. flavor1Debug
    4. flavor2Release

    【讨论】:

    • 请注意一点拼写错误 - react-native run-android --variant [flavorBuildType]
    猜你喜欢
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-17
    • 2014-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多