I want to build an android instant app from my previous app.My main source code is less than 4 MB (Instant App Requirement). But I am using some external libraries those have a size of approx 39 MB. How I can shrink the code to 4 MB?
Is there any possible way to load the libraries dynamically from the internet? Or shrink my code to 4 MB?
You can reduce your APK size greatly by using App Bundles, which will build split APKs for you (or just do the splits yourself). In your case, only one architecture will be delivered.
On that same page, you can also read about dynamic feature modules. You can develop them now, but uploading to Google Play isn't available to all developers yet.
This may not work for extracting a library unless it's well encapsulated with the user facing feature and code that uses it in your app. So, if your app can't launch without the library, it will not help much.
Also relevant, Google announced a 10MB beta program to increase instant apps size limit: http://g.co/instantapps/10MB
Related
I was trying to a react native application which just take a phone number and have country codes.
This app is of size 60mb. Whereas large apks such as facebook and uber which are also build on react native are of around 100 mb.
How is this possible?
I have even tried this also.
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.
You have to optimise your app size. There are some approaches through which you can optimise the size of your app
- Remove unused libraries from `package.json`
- Remove unused `imports` from all the files in the app.
- Remove unused assets including Audio, Video and Images files
- Resize the images which are using in the app.
- Using Hermes, is an open-source JavaScript engine optimized for React Native.
For many apps, enabling Hermes will result in improved start-up time,
decreased memory usage, and smaller app size.
More details Hermes
beside all issues #Nooruddin-Lakhani mentioned above this can also help :
also keep in mind Generate release as Bundle will help you!
I'm developing an app similar to Instagram, and in my app I used the Ffmpeg library to compress and trim videos, but this library has greatly increased the size of my app. Is there any way to add this library to the project after installing the apk? or do you have any way to reduce the apk size to 10 MB?
current apk size: 35MB
minifyEnabled true
shrinkResources true
// ffmpeg
implementation 'com.arthenica:mobile-ffmpeg-min:4.4.LTS'
of course you cannot !
making Apk means you compile all of your codes whit 3party library together, so you cannot download library after installing Apk on your phone
here is some tips for reducing android Apk size: reduce apk size
How to Reduce APK Size in Android?
APK size is one of the most important factors while building any app for any organization or any business. No user would like to install a very large APK and consume his data on downloading that APK. The APK size will make an impact on your app performance about How fast it loads, How much memory it consumes, and How much memory it uses. It is very important to take a look at your APK size while developing. In this answer, I will take a look over the tips to reduce your APK size in Android Studio.
1. Remove unused sources
The size of APK depends on very small factors rather it may be code, images, and assets used in your app. To reduce the size of your APK remove unused sources which will help to reduce APK size up to a certain extent. Removing unused sources of APK such as unused pngs, jpegs, and many other assets. Small size images are also preferable for reducing APK size. It is advised to use vector drawables instead of other image formats like JPEG, PNG, and others. Vector drawables are small in size and the main advantage of vector drawables is they don’t lose their quality even after increasing or decreasing size.
2. Use of Vector Drawables
Avoid using jpegs and pngs images because they consume very high memory in comparison with normal vector drawables. Vector drawables are easily scalable and their quality does not degrade in the change of size.
3. Reuse your code
Reuse your code as much as possible instead of repeating the code. Object-Oriented Programming will help you a lot to solve this problem and this will also help to maintain your size of APK. Repetitive code will increase the size of that particular file and it will lead to an increase in APK size.
4. Compress PNG and JPEG files
In most cases, images are the main purpose to degrade the performance in-app as well as on websites. So it is preferable to use compressed images to reduce its size and increase app performance. The size of the image will also affect the APK size so it is preferable to use compressed images in your app. You can use so many online platforms to compress your images for free.
5. Use of Lint
Lint is one of the important tools which will help us to get the unused and repeated code inside your application. So this tool will help in removing repeated and unused code.
6. Use images in WebP file format
WebP is another one of the famous image formats which are developed by Google. This image format generally focuses on image quality and optimization. Rather than using images in PNG and JPEG format WebP image format is highly preferable because of its quality.
7. Use of proguard
Proguard also plays an important role in adjusting the size of the Android APK. The main functions of using Proguard are given below:
It makes the application difficult to reverse engineer.
It helps to reduce the size of the application by removing the unused classes and methods.
Proguard in Android App can be found in Gradle Scripts > build.gradle file.
proguardFiles getDefaultProguardFile(‘proguard-android-optimize.txt’), ‘proguard-rules.pro’
8. Use of ShrinkResources
shrinkResources true
will remove the resources which are not being used in the project. You have to enable it by specifying it to true. You can find this method in build.gradle file > buildTypes > release > shrinkResources. Enable it to true.
9. Use of R8 to reduce the size of APK
R8 works similar to that of proguard. R8 shrinking is the process in which we reduce the amount of code which helps to reduce APK size automatically. R8 works with proguard rules and shrinks code faster improvising the output size.
10. Limit the usage of external libraries
While adding many external features inside our app we prefer to use some external libraries. These external libraries will install the classes provided by them some of the classes are not required and of no use, they can consume storage and will lead to an increase in APK size. So it is preferable to limit the usage of external libraries to reduce APK size.
11. Use the Android Size Analyzer tool
In Android Studio there is a plugin called Android Size Analyzer this tool will help to find the amount of memory consumed by different files of our APK. Along with this Size, the Analyzer tool will also provide us some tips which will be helpful for reducing the size of our APK. To analyze your APK size you just have to click on the build > Analyze APK option and then select your APK. You will get to see the actual size of files with distribution along with downloadable size. With the help of this tool, you can also compare the size of your previous APK with the new one.
12. Generate App Bundles instead of APK
Android App Bundle is a publishing format which is provided by Google. It consists of your app’s code and resources which is different from APK generation and signing to Google Play. Google Play will handle your app’s bundle, it will generate optimized APK for a specific device according to device configuration. When you are using app bundles you don’t have to generate multiple APK files for different devices. To generate app bundles for your app you just have to click on Build>Build Bundle(s)/APK(s) and then click on Build Bundle(s). Your apps bundle will be generated.
13. Use of Multiple APK files
If you don’t want to create bundles for your application then you can opt for the option for creating multiple APK files. Multiple APK files can be used to support different device types and different CPU architectures.
14. Reduce library size
If you are using the libraries for adding some custom views inside your project, then you can add the official libraries which are provided by Google. Generally adding libraries makes it easier to add new functionality easily inside our app but at the same time, it also affects the size of our app. It is preferable to reduce the usage of libraries while building any application.
15. Use of Resconfigs
While building an Android application it is having some default resources present inside them. All of these support libraries which we are using in our device are having local folders for other languages which we actually don’t inside our app. These folders also take some memory location inside our app. We can remove these resources which are not required inside our APK using resConfigs and this will helps in reducing the app size by a certain amount. If you are building a specific app for targeting an only specific audience and this audience only uses a specific language like Hindi, then we will only keep resource for Hindi language and we will remove all other languages which are not required.
16. Remove libraries that are only required for debugging
Many developers used some specific libraries for debugging their APK files. These debugging libraries will also take some storage inside our APK file. We can use the method of debugImplementation() inside our app to use these debugging libraries only while debugging. So these libraries will be used only while debugging and will not be added inside your release APK files.
I have an application which is deployed to some pretty remote, data connection starved regions of the world, specifically to health workers.
These people have minimal data connections and the app requires regular updates to provide increased functionality and critical bugfixes.
The problem we have is that the APK for the app is 5.7mb and only going to get larger. Which means that every time the users need to update the app, they have to download the 5.7 meg apk to update. If we roll out more than one release in a week, it can eat through a significant portion of their data plan as well as time as they have to sit and wait for it to download and install.
Is there a better way to do this? Some way to patch the versus completely replacing the application on the host device so that we deploy smaller patches?
I've tried looking for examples of "host" applications, where the actual application is just a shell for a downloadable set of libraries, sort of like a plugin system, but couldn't find any examples.
Are there any resources or a standardised way to accomplish this?
Also worth noting this is a react-native app and we're already running proguard and splitting apks based on architecture to reduce the apk size.
Did you have chance to examine CodePush? It basically allows you to push updates only for javascript part (the bundle) of your app, on-the-fly, without making your users download a new version of the apk.
If you add new native code to your project, you will still need to build and release a new apk though.
How it works is that, when you update the javascript code in your app, you push a new release. When users run the application, CodePush checks if there is a new version available and if there is, update it immediately and restart the app if you mark the mentioned release as mandatory or use the newly downloaded bundle version on next run.
Edit: react-native library of CodePush is here on github.
I'm finishing my android first app and I'm wondering why does it take so much space. It just has few activities with WebView and TextView so it should take around 1MB (like the .apk does) but definitely not 12... I've looked around but haven't seen any good reason, compressing images doesn't help much either, please help.
I'm not sure this question is within the scope of Stack Overflow. I think your answer is over at Android Enthusiasts though!
https://android.stackexchange.com/a/107204
To paraphrase, the APK is compressed version of your app. So it may be 1MB, but once decompressed on the phone, it may take 12 MB of space. If you are worrying about your app's size because you want the download to be as small as possible, then it shouldn't be a problem. It downloads from the Play Store as 1 MB.
In Android Studio, go to File-Project Structure and verify the default Dependencies already included in your project. It seems you're not using support-appcompat-v7, for example. If you make your apk without this dependency you will get your apk compressed by hundreds of kbytes.
i'm actually adding a music player in my android app. It will contains 8 albums, 12songs in each one. So i'm thinking about the best way to do this. Should i store the mp3 songs in the app, which will make there lecture faster and won't need access to internet. Or maybe it's too much heavy and calling mp3 url would be a better idea?
Thank you
There are a few things to consider when evaluating your options.
If you ship the songs together with the app, you will greatly increase it's size. Most probably you will go over the 50 Mb limit, and you will have to implement APK expansion files, which are downloaded when the app is first started. Implementing this is not very hard, but it can take some time.
If you implement a custom download for the songs, you can optionally provide better control over what is downloaded, optimizing bandwidth usage, download times, etc. Still, it would be more difficult to implement then the standard APK expansions, and you will have to deal with a lot of additional download logic - pausing / resuming, dealing with insufficient storage space, etc.
My advice is to go with an APK expansion, which is downloaded when the app is first started and will manage all the download complexity out of the box. If you need a more fine grained download - go custom.
Good luck.