Trying to make a smaller APK, currently the size is 21 MB. Hoping to reduce it to 10MB.
I do this inside android/app/build.gradle, but it doesn't reduce, I just want ARM support for now:
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "arm64-v8a"
}
}
Try this, I hope this will helps you.
Open up android/app/build.gradle
Set def enableProguardInReleaseBuilds = true this would enable Progaurd to compress the Java Bytecode. This reduces the app size by a tad bit
Set def enableSeparateBuildPerCPUArchitecture = true . Android devices support two major device artitectures armebi and x86. By default RN builds the native librariers for both these artitectures into the same apk.
more information to https://medium.com/#aswinmohanme/how-i-reduced-the-size-of-my-react-native-app-by-86-27be72bba640
Related
In my app , I implemented APPRTC. Before implement the APPRTC my app size is 6MB. After implemented APPRTC My app size went 16 MB. i am using one to one Voice chat only. Can we have any other options to reduce the APP size or webrtc library size? Please suggest.. Thanks..
Note : "libjingle_peerconnection_so.so" liberary size is 10 MB.
You can Split APK using Gradle. Like,
// APK splitting
splits {
abi {
// Enable APK splitting wrt architecture
enable true
// Reset the architectures for which you need to build the APKs for
reset()
// Include the architectures for which Gradle is building APKs
include 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
// Set this to false if you don't want an APK that has native code for all architectures
universalApk false
}
}
// Assign codes to each architecture
project.ext.versionCodes = ['x86': 0, 'x86_64': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3]
// Add the architecture-specific codes above to base version code, i.e. the version code specified in the defaultConfig{} block
// Example: 2000 is the base version code -> 2000 (x86), 2001 (x86_64), 2002 (armeabi-v7a) & 2003 (arm64-v8a) would be the version codes for the generated APK files
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
output.versionCodeOverride = project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1 + android.defaultConfig.versionCode
}
}
}
Can someone please specify me the procedures for compressing the app size built on react native.
I referred to many pages on google, hackernoon, and medium but they were too good for me to understand.
Please if someone knows basic and fewer glitch ideas on how to compress react native apps for both Android and iOS with procedures and where to keep the screen files and assets folder.
I tried by following the steps on medium, detached the iOS and android folders but it was an unsuccessful attempt.
Please if someone can help me in compressing the app size.
Yes you can easily reduce app size . Just go to app/build.gradle and pasted these lines or check these lines
def enableSeparateBuildPerCPUArchitecture = true
def enableProguardInReleaseBuilds = true
enjoy
you can reduce your react-native app size by this steps:
1- shrink your app icons and images size as possible as you can
2- go to android/app/build.gradle and make this changes:
project.ext.react = [
entryFile: "index.js",
enableHermes: true, // change false to true
]
...
def enableHermes = project.ext.react.get("enableHermes", true);
its for using hermes engine in bundling js server.
3-
def enableSeparateBuildPerCPUArchitecture = false // change false to true
the above line causes building seprate apks instead of universal apk. however you can have both seprates and universal by doing following changes :
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk true // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" // seprate apks
}
}
i have a arm 64bit binary that only work on armeabi-v8a. when i upload to google play other abi users get errors. i do not use ndk
i use this and works perfectly on armeabi-v8a. other people gave me bad reviews because google play showed my app to armeabi-v7a and other abi phones.
Process dd = Runtime.getRuntime().exec(s);
i want to know how to filter and give my app only to armeabi-v8a users. so i used abi splits it did not work always showed my app to other abi users. my gradle code is
splits {
abi {
enable true
reset()
include "armeabi-v8a"
universalApk false
}
}
The name of the ABI should be "arm64-v8a", not "armeabi-v8a".
Im facing this problem which seems im not able to solve. Here is scenario:
Im building apk which uses gradle dependency and this dependency is architecture specific so for apk for x86 i need different dependency and for arm different as well.
I solved it with product flavors:
productFlavors {
dev { ... }
develx86 { ... }
production { ... }
productionx86 { ... }
}
So then i defined dependency like this:
develCompile 'dependency_for_arm'
develx86Compile 'dependency_for_x86'
This works good. But recently i had to add to my application an usage of renderscript. I did it in this way:
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
And after this when i uploaded apk on Google Play it says it's apk is suitable with arm, x86. I don't know how this is possible. As you can think it will crash on device with different CPU (if i generated apk for arm and user will execute it on x86 app will crash).
So i decited to use ABI splits:
splits {
abi {
enable true
reset()
include 'armeabi', 'x86'
universalApk false
}
}
//Ensures architecture specific APKs have a higher version code
//(otherwise an x86 build would end up using the arm build, which x86 devices can run)
ext.versionCodes = [armeabi:0, x86:1]
import com.android.build.OutputFile
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
int abiVersionCode = project.ext.versionCodes.get(output.getFilter(OutputFile.ABI)) ?: 0
output.versionCodeOverride = android.defaultConfig.versionCode + abiVersionCode
}
But now when i see generated apk files, my dependency which is flavor-specific is not included into apk and apk will crash when i open section which uses API from this dependency.
Do someone know how to solve this issue? Or someone know why Google Play says that apk is for both architectures when i included renderscript? (Without it it works properly but i need renderscript).
Thank you for your time. I will appreciate any help.
If you look inside your APK, under lib folder, you should see that renderscript support mode added libs for other architectures than the one you're supporting.
You can keep your earlier configuration with ABI-specific flavors.
But in order to ensure that no libs for other architectures are included, try adding abiFilters to your flavors:
productFlavors {
dev { ... ndk.abiFilters 'armeabi-v7a' }
develx86 { ... ndk.abiFilters 'x86' }
production { ... ndk.abiFilters 'armeabi-v7a' }
productionx86 { ... ndk.abiFilters 'x86' }
}
Sorry I cannot comment inline yet.
What's in the apk, especially in res/raw/ and lib/?
Also, are you using gradle-plugin 2.1.0? (since you are using renderscriptTargetApi 22), have you tried Build-Tools 23.0.3?
I want to make APK split based on CPU ABI according to http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits, however I want to split the APK only for a certain product flavor.
So my build.gradle file has the following product flavors plain and market. Actually I want the APK split to be performed when building market flavor.
android {
productFlavors {
plain {
}
market {
splits {
abi {
enable true
reset()
include 'armeabi', 'armeabi-v7a', 'x86', 'mips'
universalApk true
}
}
}
}
}
However, when I invoke gradle assemblePlainDebug and assembleMarketDebug, both of them produces the multiple APK. Is there something wrong with the configuration above?
I'm using com.android.tools.build:gradle:1.2.3.
I've been looking for a way to do this for a while and haven't found a solid solution. Something to do with the splits having to be run before resolving the buildTypes and productFlavors.
The Android Gradle - is use splits only for release possible? question had answer that I thought useful. It basically relies on a project property, passed in when building via the command line or continuous integration invironment, to set weather the split apk's option is enabled or not.
I used it like this:
splits {
abi {
enable project.hasProperty('splitApk')
reset()
include 'x86', 'armeabi-v7a', 'mips', 'armeabi'
universalApk true
}
}
and then depending on what falvour or build type you are building you can include:
./gradlew --project-prop splitApk assembleMarketDebug
This should then only enable the apk split when explicitly told too and should stay disabled for everything else.