can i download android library after installing apk? - java

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.

Related

facebook or Uber react native app size is so small

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!

Reduce size of .apk file when use native libraries in android without using pro-guard

I am developing a PDF related application in android (java). For PDF editing and converting others file type to PDF file, I add some native libraries and that work fine for me. But after developing an application, the released .apk file size is above 29 MB. If I apply pro-guard, the .apk size is definitely reduced as 22 MB. But I do not want to apply pro-guard because some functionalities do not work with pro-guard. So how can I reduce the size of my .apk file?
You should use SVG images
A VectorDrawable is a vector graphic defined in an XML file as a set
of points, lines, and curves along with its associated color
information. The major advantage of using a vector drawable is image
scalability. It can be scaled without loss of display quality, which
means the same file is resized for different screen densities without
loss of image quality.
Vector objects are much smaller than raster image format. If we have full size image to update, the vector file might only take few kilobytes of space on your system, where the same image in medium resolution bitmap format might not place on CD ROM.
FYI
Use app bundle instead of apk.
Google Play’s new app serving model, called Dynamic Delivery, then
uses your app bundle to generate and serve optimized APKs for each
user’s device configuration, so they download only the code and
resources they need to run your app. You no longer have to build,
sign, and manage multiple APKs to support different devices, and users
get smaller, more optimized downloads.
one thing you can try is from
Refactor>Remove Unused Resaurces it will remove unused classes,images,xml,etc so it will decrease some of your apk size.
And one more thing you can do is shrinkResources by adding shrinkResources true
as below in build.gradel
android {
// Other settings
buildTypes {
release {
minifyEnabled true
shrinkResources true
}
}
}
There are multiple ways to reduce apk size. You can start using App Bundles which splits your app into base, configuration and dynamic feature apks based on architecture(native libs), density & language. When installing, it merges various configuration bundles and create a singular apk for that device using its specs.
This reduces download(install) and update size but final bundle(.aar) file is same as that of universal apk created without bundle.
Another option is to create Multiple APKs. This way you create and manage apks yourself by specifying densities, architecture and language you wanna support or ignore. This will be a little bit hectic but this certainly reduces final apk size as you are only using required resources and libs.
Both of these work in similar way but in case of bundles, you don't have to manage multiple apks yourself. You just handle creation of bundle, and play store will create apks itself depending on device requesting the update or install. But in case of multipole apk, you create all the apks yourself. E.g. If you support 3 languages (en, es, fr), 2 architectures (x86, x86_64) and
4 densities (mdpi, hdpi, xhdpi, xxhdpi), you will have to create 3x2x4 apks.

Instant Apps: How to add external libraries?

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

Why does my app take so much space?

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.

Installation of big .apk take longe time on Android Emulator

I am writing application for Android. Application size is more then 200 MB. And it take very long time to install on the Android Emulator. I want to know
How can I speed up installation of huge file on Android Emulator.
How I can speed up Android Emulator ( for example to give more RAM for it or to give more Internal Memory for it ).
My operating system is Windows 7 64bit.
Why would you have a 200mb APK? I can imagine you'd have some sort of data (it's surely not 200mb of pure code, right?) ?
You could/should remove this and put it on the (virtual) SD card of your emulator. APK size will be lot smaller, no need to keep loading that datafile.
In the end you'd want to do this for release anyway: 200mb is way too big. Release a small(er) APK and make the data available as download.
And if it is all code.. well, then you're out of luck.
How can I speed up installation of huge file on Android Emulator.
I don't think there's anything you can do to speed up the installation. 200mb is a ridiculously huge APK.
How I can speed up Android Emulator ( for example to give more RAM for
it or to give more Internal Memory for it ).
When you create the AVD (or choose to edit it later), you can specify the amount of memory it has.
See reference here: Managing Virtual Devices

Categories

Resources