gpt4 book ai didi

android - React Native 将 apk 文件的大小增加了 6.5 MB

转载 作者:行者123 更新时间:2023-11-29 02:36:23 43 4
gpt4 key购买 nike

我开始测试在现有 android 项目中使用 react-native 对大小的影响。当创建一个简单的 android 项目(带抽屉导航的模板项目)并创建 .apk 文件时,它的大小在 Release模式下为 1.1 MB

然后我尝试按照文档中的步骤将 react-native 与其集成, https://facebook.github.io/react-native/docs/integration-with-existing-apps.html

完成此集成并使用此处定义的 progaurd 步骤更新我的 progaurd-rules.pro 文件后, https://github.com/luggit/react-native-config/blob/master/Example/android/app/proguard-rules.pro

Proguard-rules.pro 文件内容类似于,

# React Native

# Keep our interfaces so they can be used by other ProGuard rules.
# See http://sourceforge.net/p/proguard/bugs/466/
-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip

# Do not strip any method/class that is annotated with @DoNotStrip
-keep @com.facebook.proguard.annotations.DoNotStrip class *
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
@com.facebook.proguard.annotations.DoNotStrip *;
@com.facebook.common.internal.DoNotStrip *;
}

-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
void set*(***);
*** get*();
}

-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
-keepclassmembers,includedescriptorclasses class * { native <methods>; }
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp <fields>; }
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp <methods>; }
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup <methods>; }

-dontwarn com.facebook.react.**

# okhttp

-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

# okio

-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**

现在,我发布的 .apk 文件的大小已跃升至 7.9 MB。这太多了。我可以在 Play 商店中看到总大小为 9-12 MB 的各种电子商务应用程序。我的 Hybrid react-native 应用程序是最基本的应用程序,它只有两个几乎什么都不做的 Activity 。

为了验证我的发现,我按照这个文档创建了一个新的 react-native 应用程序, https://facebook.github.io/react-native/docs/getting-started.html

当我为这个纯 react-native 项目生成发布 .apk 文件时,基本的 Awesome App .apk 大小也是 6.8 MB

这是 Not Acceptable 。 React Native 给 apk 添加了太多的大小。我的 progaurd 文件 是否有进一步改进的可能?还有什么可以改进的吗?

如果有人可以分享 React native 对他/她的应用程序的大小影响,那将非常有帮助。

最佳答案

使用 react-native 创建的 apk 的大小总是大于 native-app apk。但是您可以在使用 react-native 时减小 apk 的大小。

可以看到herehere了解如何去做。

在文档本身中首选

React Native is great when you are starting a new mobile app from scratch. However, it also works well for adding a single view or user flow to existing native applications.

因此,我宁愿创建新的 react-native 应用程序,而不是与您现有的应用程序集成,因为您想使 react-native android 应用程序的 apk 大小尽可能小。

关于android - React Native 将 apk 文件的大小增加了 6.5 MB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46760670/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com