Why does my app take so much space? - java

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.

Related

can i download android library after installing apk?

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.

(Java - Android) How do I smoothly unpack songs and play them on my Android app?

I am completely new to Android studio, but I would really like to create a music player that plays downloaded songs on android. My problem is that if I have a lot of songs they use up a lot of space and my question is if there is a way to compress the files in a way that they use up less space, but still get unpacked fast enough to not cause big lags between one song and the other.
The idea behind this is that when a song is selected it gets unpacked, then gets played and when it finishes it gets packed again. I don't know if that's the best way to do it, and if you have a better idea please let me know.
This is not possible. MP3 files (mentioned in tag) are already effectively compressed. The only way to make it significantly smaller is to re-encode it with lower bitrate which would be lossy compression. It would seem that external storage/hosting and loading the necessary files on the go is the only way to save device storage. To have no lag, keep "one song in advance from the playlist".

android playlist, storing mp3 file in the app or calling url

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.

Android - Server could not process your apk - Size limit?

I spent all day trying to figure out what is wrong with my apk. Tried ALL solutions from web, aapt revealed nothing, tried different signatures, packages, versions, browsers, OS. Manifest underwent all possible changes, yet I was getting same problem.
So I though OK, lets start from scratch, maybe google servers are down for some reason (wouldn't be the first time).
created new android application project, new package, just one activity
built, signed, uploaded, voila, OK, fine, removed apk from console
did this few times, it succeeded every time
the size of apk was few hundreds KB
as my original apk was around 25MB, I thought, hey, lets try increasing size of this testing one
so copied ~25MB worth of photos to drawable-hdpi
built, signed, uploaded and familiar message popped out again - 'Server could not process your apk'
tried several times, still same outcome
deleted photos, built, signed, uploaded, ok
added photos, no luck
So obviously problem is not in manifest or anything else, for some reason size matters (in this case anyway :)).
And yeah, when I deleted just 50% of photos, so apk was ~ 13MB, it sometimes worked, sometimes didn't.
Any explanation for this? Can you replicate? Have tried different browsers, operating systems, same everywhere ... I know there is a limit for apk size, but that's 50MB
Go figure ...
UPDATE: if you ever encounter same problem and you're sure your apk is fine, keep trying to upload. It worked after couple of consequent failed uploads, suddenly server COULD process, without ANY change to apk.
I don't know what's going on with your app and Google Play. Our largest APK file is just under 11MB and we've never had a problem.
Perhaps you can side-step the problem by packaging up the resources in an APK expansion file, as described here. The size limit for APK expansion files is 2GB, so there shouldn't be any size issues at all. According to this thread it can be set up to work pretty smoothly (transparently for the user).

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