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.
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.
react-native or for more real time interactions, ask on Discord in the #react-native channel.Hi @alvinwoon, How did you ran the pro-guard, can you please share the steps.
@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.
@satya164 Thanks! That reduce it down to 5.2mb but crashes the app upon opening. Need to debug more and report back.
@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.
cc @mkonicek
Thanks @brentvatne, after re-generating key everything works fine, but getting crash reports would be very helpful.
@MuruganDurai You have 2 options for crash reports,
adb logcat, or the logs panel in Android studio to see logs (filter only errors to see crash reports).@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
@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
-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.*
-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 [email protected]
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/facebook/react-native/issues/5037#issuecomment-168831770.
@satya164 Thanks for the suggestions. How to remove "React Native JSCore binaries for x86" to reduce the size further.
@MuruganDurai Remove x86 from abiFilters.
Thanks @satya164
@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
@SuhairZain Thanks.
@SuhairZain This seems like a good addition to the docs or even a tutorial. Wink. Wink.
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.
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.
@wenq1 That is amazing.
Most helpful comment
@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:
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.