Reputation: 579
i have built a react native project and i added some libraries and i build an apk to check if it works and i saw this. i have no activities right now, just a couple of libraries.
this is how my package.json looks like:
{
"name": "AppName",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"load-script": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@react-native-community/async-storage": "^1.9.0",
"@react-native-community/masked-view": "^0.1.9",
"@react-navigation/native": "^5.1.5",
"@react-navigation/stack": "^5.2.10",
"axios": "^0.19.2",
"i18next": "^19.4.2",
"moment-jalaali": "^0.9.2",
"native-base": "^2.13.12",
"react": "16.11.0",
"react-i18next": "^11.3.4",
"react-native": "0.62.2",
"react-native-gesture-handler": "^1.6.1",
"react-native-localize": "^1.4.0",
"react-native-reanimated": "^1.8.0",
"react-native-responsive-screen": "^1.4.1",
"react-native-restart": "^0.0.14",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.4.0",
"react-native-svg": "^12.1.0",
"react-redux": "^7.2.0",
"redux": "^4.0.5",
"redux-logger": "^3.0.6",
"redux-persist": "^6.0.0",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/runtime": "^7.9.2",
"@react-native-community/eslint-config": "^1.0.0",
"babel-jest": "^25.3.0",
"eslint": "^6.8.0",
"jest": "^25.3.0",
"metro-react-native-babel-preset": "^0.59.0",
"react-test-renderer": "16.11.0",
"reactotron-react-native": "^5.0.0"
},
"jest": {
"preset": "react-native"
}
}
how can i reduce the apk size and is there any way to know which library is taking too much size ?
Upvotes: 1
Views: 5177
Reputation: 143
In android/app/build.gradle
add line:
def enableSeparateBuildPerCPUArchitecture = true
Upvotes: 0
Reputation: 75788
release {
debuggable false
shrinkResources true
minifyEnabled true
useProguard true
setProguardFiles([getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'])
}
minifyEnabled
and useProguard
, you will
activate the minification and obfuscation of the code.shrinkResources
in your app's build.gradle file./** * Run Proguard to shrink the Java bytecode in release builds. */ def enableProguardInReleaseBuilds = true
Proguard is a tool that can slightly reduce the size of the APK. It does this by stripping parts of the React Native Java bytecode (and its dependencies) that your app is not using.
def enableProguardInReleaseBuilds = true
this would enable
Progaurd to compress the Java Bytecode. This reduces the app size.enableSeparateBuildPerCPUArchitecture = true
.Upvotes: 1