Statistics of the amount of methods used in the .apk file

This is my first post on viblo, in this first series I want to share with everyone how I use the library in android as well as optimizing each library to use. Using libraries written by other programmers is completely normal and convenient, but using too many libraries often makes a lot of difficulties in managing code, optimizing code, and maintaining fixbug later. This is why it is necessary to optimize libraries right from the beginning to make the best use. With my experience in the series of lib, I will share some articles as follows:

  • Dex method count: mothod statistics tool, code structure
  • Optimize google play service library.
  • Image processing library.
  • Download library ….

The first article I will introduce about the tool is very nice to use the dex mothod count.

General introduction :

Dex method count is a fairly simple tool that statistics the number of methods used in an apk file after it is finished. Perhaps many of you wonder: "why do I have to count the number of methods to do?", Or "what method should I use, what do statistics do?", Currently Android has a majority dev on Android studio studio. pretty good suport for build -multi-dex but error

It's a bug that haunts me (and probably lots of android devs using eclip). The above bug handling is quite complicated because it has to be optimized for the source code, reducing the amount of method load so that eclip can build okie, so this tool method count supports dev a lot in statistics, as well as the system of source code of me

Instructions for installing and using

(You can get source code as well as detailed instructions on github at https://github.com/mihaip/dex-method-counts ).

  • B1: download the code on githup: https://github.com/mihaip/dex-method-counts
  • B2: You create a java project on eclip.
  • B3: Copy the entire source code in the folder / / src of the folder you just downloaded into the / src folder of the project you just created.
  • B4: export project to runable file (.jar)
  • B5: Open cmd in the bin directory of java / jdk. then execute the command to show the number of methods:

For example :

Then on your cmd screen will show the statistics of method numbers

  • Also you have options:
    • –Count-fields: Change the method count to switch to counting fields
    • –Include-classes: Treat classes as packages and provide per-method counts. Một tùy chọn một sử dụng là cho bộ đệm giao thức nào có thể tạo mã số trong một gói đầu vào trong một lớp đơn.
    • –Package-filter = …: only count packages that start with ..
    • –Max-depth = …: method tree depth limit
    • –Filter = [all | defined_only referenced_only]: Whether to count một phương pháp (mặc định), chỉ các xác định trong tập tin input, hoặc chỉ có tham số trong nó. Ghi nhớ, tham chiếu các số đếm phương pháp cho sự chế độ 64K chế độ limit quá.
    • –Output-style = [flat | tree]: displays the result of a directory tree or alignment.

For example

Also you can change some logic in main.java file, output.java so that you can output the result to file or change the method tree structure as you want. (This custom problem I think you discover yourself would be much more fun and interesting :). )

Conclude

There is this tool in hand now you try to create a small android project with only 1 simple view, in which import 2 sets of libraries: android suport.v7, and google play service. (Try using this tool to see how many methods your library has on your library, compared to the 65k method max that eclip can build for you, there will be a big surprise: D.) How unexpected, and how to solve it I will answer more carefully in the following article: Optimize google play service library . We hope you support: D.

ITZone via Viblo

Share the news now