Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is ~8mb the smallest size RN android apk can get? #5037

Closed
alvinwoon opened this issue Dec 30, 2015 · 19 comments
Closed

is ~8mb the smallest size RN android apk can get? #5037

alvinwoon opened this issue Dec 30, 2015 · 19 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@alvinwoon
Copy link

I have a simple app. Ran proguard and it went down to 7.5mb. I just want to know whether there's other way to reduce the apk size that I am not aware of.

@facebook-github-bot
Copy link
Contributor

Hey alvinwoon, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

  • If you don't know how to do something or something is not working as you expect but not sure it's a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • If this is a feature request or a bug that you would like to be fixed, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • We welcome clear issues and PRs that are ready for in-depth discussion. Please provide screenshots where appropriate and always mention the version of React Native you're using. Thank you for your contributions!

@MuruganDurai
Copy link
Contributor

Hi @alvinwoon, How did you ran the pro-guard, can you please share the steps.

@satya164
Copy link
Contributor

@alvinwoon React Native app APKs include JSCore binaries for x86 and ARM. If you don't need x86 you could reduce the size even more.

@alvinwoon
Copy link
Author

@satya164 Thanks! That reduce it down to 5.2mb but crashes the app upon opening. Need to debug more and report back.

@MuruganDurai
Copy link
Contributor

@satya164 After proguard enabled I could not get the build finished, got unable to compute hash error at ":app:packageRelease". Also If I disabled the proguard minify, able to generate the apk but the app crashes always for first navigation with error "Unfortunattely <>...", after that first crash app works perfectly. Do you know how to get the crash reports for this error and fix for the previous error.

@brentvatne
Copy link
Collaborator

cc @mkonicek

@MuruganDurai
Copy link
Contributor

Thanks @brentvatne, after re-generating key everything works fine, but getting crash reports would be very helpful.

@satya164
Copy link
Contributor

satya164 commented Jan 1, 2016

@MuruganDurai You have 2 options for crash reports,

  1. Use adb logcat, or the logs panel in Android studio to see logs (filter only errors to see crash reports).
  2. Use something like crashlytics in your productions apps to track crashes

@hosainnet
Copy link
Contributor

@MuruganDurai How did you solve the 'got unable to compute hash error at ":app:packageRelease"' issue exactly? I tried regenerating the key but no luck

@MuruganDurai
Copy link
Contributor

@Hosain As I said before I copied all the contents suggested from stackoverflow for "proguard-rules.pro" and re-generated the key.

-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; }
-keepclassmembers class * { @com.facebook.react.uimanager.ReactProp ; }
-keepclassmembers class * { @com.facebook.react.uimanager.ReactPropGroup ; }

okhttp

-keepattributes Signature
-keepattributes Annotation
-keep class com.squareup.okhttp.* { ; }
-keep interface com.squareup.okhttp.
* { ; }
-dontwarn com.squareup.okhttp.

-dontwarn rx.Observale.**
-dontwarn rx.**
-dontwarn com.squareup.okhttp.internal.huc.**
-dontwarn com.google.appengine.api.urlfetch.**

okio

-keep class sun.misc.Unsafe { ; }
-dontwarn java.nio.file.

-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**

-dontwarn butterknife.**

-keep public class com.google.android.gms.**

-dontwarn android.support.v7.**
-keep class android.support.v7.** { ; }
-keep interface android.support.v7.
* { *; }

-dontwarn java.lang.invoke**

-dontwarn android.support.**
-dontwarn com.github.**
-dontwarn com.squareup.picasso.**


From: Hosain notifications@github.com
Sent: Tuesday, January 5, 2016 4:04 AM
To: facebook/react-native
Cc: MuruganDurai
Subject: Re: [react-native] is ~8mb the smallest size RN android apk can get? (#5037)

@MuruganDuraihttps://github.com/MuruganDurai How did you solve the 'got unable to compute hash error at ":app:packageRelease"' issue exactly? I tried regenerating the key but no luck

[https://avatars2.githubusercontent.com/u/6378771?v=3&s=400]https://github.com/MuruganDurai

MuruganDurai · GitHubhttps://github.com/MuruganDurai
github.com
MuruganDurai has 3 repositories written in JavaScript, Shell, and CSS. Follow their code on GitHub.

Reply to this email directly or view it on GitHubhttps://github.com//issues/5037#issuecomment-168831770.

@MuruganDurai
Copy link
Contributor

@satya164 Thanks for the suggestions. How to remove "React Native JSCore binaries for x86" to reduce the size further.

@satya164
Copy link
Contributor

satya164 commented Jan 5, 2016

@MuruganDurai Remove x86 from abiFilters.

@MuruganDurai
Copy link
Contributor

Thanks @satya164

@SuhairZain
Copy link
Contributor

@MuruganDurai
Hi, you could also try using the split feature to create separate apks for different CPU architectures. In case of RN, this creates 2 APKs (x86 and ARMv7a). Just change the following line in your android/app/build.gradle:

- def enableSeparateBuildPerCPUArchitecture = false
+ def enableSeparateBuildPerCPUArchitecture = true

Upload both these files to Google Play and the users will automatically get the appropriate APK file. If you want to upload to other markets such as APKFiles, which do not support multiple APKs for a single app, change the following line as well to create a big universal APK with binaries for both CPUs.

- universalApk false  // If true, also generate a universal APK
+ universalApk true  // If true, also generate a universal APK

@MuruganDurai
Copy link
Contributor

@SuhairZain Thanks.

@theodoregold
Copy link

@SuhairZain This seems like a good addition to the docs or even a tutorial. Wink. Wink.

@martsie
Copy link

martsie commented Oct 4, 2017

Using @SuhairZain 's suggestion we got our APK size down from 15.2MB for the universal to 8.4MB for the ARMv7a and 10.3MB for x86.

facebook-github-bot pushed a commit that referenced this issue Oct 4, 2017
Summary:
It leads to a reduction of 5-7MB for an app, which is a considerable saving when it comes to emerging markets. Also, I had written a [comment](#5037 (comment)) on an issue which seems to have helped at least 26 people.
Closes #16197

Differential Revision: D5978945

Pulled By: TheSavior

fbshipit-source-id: 391a992e2d8e62e59fb20e5d5f8e5f59c00b6295
@wenq1
Copy link

wenq1 commented Jan 15, 2018

I did some primary experiments on Alibaba's weex which is based on Chrome's v8, similar to ReactNative in architecture. Switching from v8 to duktape bindings significantly reduces the solib size (from 3MB to 300kB), without functional impacts. I suppose the same approach can be applied to ReactNative although its bindings seems more complex.

@alvinwoon
Copy link
Author

@wenq1 That is amazing.

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests