问题
I am developing a small dictionary app by using react native with expo.
As I am compiling to Apk file. The size goes up to 30mb and after having installed on a device, it goes to 80mb.
Is this normal?
Are there any ways to reduce the size of the app?
Thank you guys.
回答1:
expo is for testing the app you should migrate to react-native for production
make a new react app "
react-native init
"Copy the source files over from Expo project
- Install all dependencies of the Expo project except Expo specific libraries.
- Make necessary adjustments to
app.json
file Download the signing key of your Android app from Expo using exp
fetch:android:keystore and set it up
this reduce your app dramatically you can also enable proguard and specific build for cpu architecture
buildTypes {
release {
debuggable false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
for more info visit https://medium.com/@aswinmohanme/how-i-reduced-the-size-of-my-react-native-app-by-86-27be72bba640
using expo component
after you done and want publish with less size or just wan't to use a native library expo give you an option called ExpoKit this also can be use with already build with native code react projects
1-run command expo eject
to add ExpoKit (choose the "ExpoKit" option)
(no need to do this if you have copied files manually or using native project)
2 -start expo packager with expo start
.Leave this running and continue with the following steps.
3-
link library for android and ios , this command mostly do this react-native link
,sometime this will not work and you should do it manually for this means visit expokit
PS: i didn't test this so if this not work inform me
回答2:
Make following changes in build.gradle
file located at:
./android/app/build.gradle
Remove x86 from abi filters.
splits {
abi {
reset()
enable true
universalApk false
include "armeabi-v7a", "x86"
}
}
Generate different APK's for different architecture
def enableSeparateBuildPerCPUArchitecture = true
Enable ProGuard :
def enableProguardInReleaseBuilds = true
Also set minifyEnabled true and shrinkResources true
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
Also, you can have different build types for development and release builds(depends on your user base)
buildTypes {
debug {
ndk {
abiFilters "armeabi-v7a", "x86"
}
....
}
release {
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}
....
}
Also don't forget to remove the unused FONT Files
回答3:
For android APK bundle using expo, you can use the following command:
expo build:android -t app-bundle
The size will be much smaller once you upload it to the play store.
回答4:
There are basically two options for reducing size of apk file from 32mb(expo) to 7mb(react-native cli).
- Detach from expo
- create new react-native cli project and copy all source from expo to new react-native project.
回答5:
Upgrade expo version to 31.exporecently launched single-SDK builds for Android. These builds contain only the SDK version the app uses when built and are both faster and slimmer. it helps for smaller standalone app build size. release note
回答6:
Upgrade react-native to newer version, for different versions it is giving different size apk.
for 0.57
it was ≈12mb
for 0.59.3
it was ≈30mb
and for 0.59.9
it was ≈15mb
always try to use updated react-native version
回答7:
I used all above steps for reducing my app size. Now it's 6.94 MB. How to reduce it even more. Similar apps are less than 1 MB on Google Play.
来源:https://stackoverflow.com/questions/49993006/how-to-reduce-the-size-of-an-expo-react-native-app-on-android