Does APK library size increase library size?

I have several libraries in my project, for example

dependencies { compile files('libs/universalloaderlibrary.jar') compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.1' compile 'com.android.support:design:22.2.1' compile 'com.android.support:recyclerview-v7:22.2.1' compile 'com.android.support:cardview-v7:22.2.1' compile 'de.hdodenhof:circleimageview:1.3.0' compile 'com.jakewharton:butterknife:7.0.1' //noinspection GradleCompatible compile 'com.google.android.gms:play-services-gcm:7.3.0' compile 'com.github.castorflex.smoothprogressbar:library:1.1.0' compile 'com.google.code.gson:gson:2.2.4' compile 'com.loopj.android:android-async-http:1.4.8' compile 'com.android.support:multidex:1.0.1' } 

and other libraries. They increase the size of the application too much. In my project I have more than 25 libraries. Now the size of the APK is 11 MB, and I have to add more functionality to it. What could be the reason?

I have some questions regarding this.

What takes up more memory?

  • The module is added to the project.
  • The file is added as a JAR file.
  • Gradle A dependency that we add in the same way as compile 'com.android.support:appcompat-v7:22.2.1' .

I read that by enabling Proguard , setting minifyEnabled true can reduce the size of the application.

 buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } 

How do they work behind the picture?

Should you avoid using multiple libraries in a project?

In my opinion, I have a lot of questions to reduce the size of the APK. Any suggestion and help will be noticeable. Thanks at Advance.

+5
source share
2 answers

All three of these methods will increase the size of your APK. The difference between the two is where the source code is located:

  • A module dependency is the source code on your local machine. It is compiled into bytecode when creating the application.
  • A JAR file is a precompiled bytecode. It is also located on your local machine, but in fact it is not the source code. The bytecode is simply added to your own when created.
  • The Gradle dependency is basically the same as when using a JAR file, except that Gradle will load the pre-compiled artifact, rather than adding it as a file to the local machine.

Regardless of the above, the dependency contributes its classes to the assembly, and they will be present in the final release (APK).

Proguard does a few things that can reduce the size of your APK. It can statically analyze all bytecode and remove classes and methods that are never used. It can also rename classes, fields, and methods to smaller identifiers, such as "abc," which can slightly reduce the size of the bytecode.

+6
source

Yes, dependencies and compilation output of the project source code are sent to dex to convert the bytecode and include it in the final APK.

With proguard, classes that are not used can be systematically deleted.

+2
source

Source: https://habr.com/ru/post/1238463/


All Articles