react-native 安卓项目gradle优化

profile报告命令

./gradlew clean app:assembleDebug --profile
1.png

1、debug环境禁止crashLytics上报
2、避免Legacy Multidex

image.png
2.png

记录

2018-11-06 11:05 clean
gradlew clean app:assembleDebug --profile

1、修改参数,加快build
org.gradle.jvmargs=-Xmx4608M -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
安卓:非发布版禁用fabric上报,修改jvmargs参数,使开发环境build时间降至2min以内
http://www.easemob.com/news/852
https://medium.com/exploring-code/how-to-decrease-your-gradle-build-time-by-65-310b572b0c43

debug环境禁用fabric
非发布版本关闭Fabirc

android {
    buildTypes {
        debug {
          // Disable fabric build ID generation for debug builds
          ext.enableCrashlytics = false
          ...

参考:https://www.cnblogs.com/zhou-guobao/p/disable-crashlytics-for-debug-builds.html

2、配置不同的图标
https://blog.csdn.net/MAIMIHO/article/details/76106700?utm_source=blogxgwz4

配置不同app名称
遇到一个错误:


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@label value=(@string/app_name_debug) from AndroidManifest.xml:86:9-37
    is also present at [:react-native-fetch-blob] AndroidManifest.xml:11:18-50 value=(@string/app_name).
    Suggestion: add 'tools:replace="android:label"' to  element at AndroidManifest.xml:80:5-324:19 to override.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

按照提示解决,解释:https://www.2cto.com/kf/201712/702939.html

3、配置不同applicationId
fileprovider 修改,https://www.jianshu.com/p/1afa7d4c0afd 提醒
FileHelp.java中使用父项目的BuildConf.applicationId

4、打jsbundle后生成的这个垃圾文件
D:\Git\pingtai\Portal\android\app\src\main\res\drawable-mdpi\js_commonview_echarts_tpl.html

5、android studio 中distributionUrl使用本地文件
D:\Git\pingtai\Portal\android\gradle\wrapper\gradle-wrapper.properties


distributionUrl.png

6、修改combile

7、开发环境使用比android studio 自带的【apply changes】更牛逼的【JRebel for Android】

  • 1、安装Jrebel插件:https://zeroturnaround.com/software/jrebel-for-android/quick-start/#!/installation
  • 2、激活帮助:http://blog.lanyus.com/archives/299.html

生成GUID:https://www.qvdv.com/tools/guid.html
我生成的:http://idea.lanyus.com/E086630D-638A-07A7-58D2-68ED4762D053

activate.png

activated.png
  • 3、配置参考博客地址:http://www.czhzero.com/2016/08/10/jrebel-for-android-guide/

8、减小APP的体积

你可能感兴趣的:(react-native 安卓项目gradle优化)