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
1 2 | Lỗi thay đổi Dalvik định dạng: Không thể thực hiện dex: phương pháp ID không trong [0, 0xffff]: 65536 |
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:
1 | java -jar path_of_file_.jar path_of_file_apk |
For example :
1 | C: Java Program Files jdk1.8.0_45 bin> java -jar E: method.jar E: pic.apk |
Then on your cmd screen will show the statistics of method numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | codehaus: 6189 jackson: 6189 annotate: 62 format: 31 impl: 545 io: 128 map: 4025 annotate: 34 deser: 887 impl: 81 std: 423 exc: 5 ext: 102 introspect: 496 jsontype: 164 impl: 138 module: 49 ser: 749 impl: 97 std: 368 type: 303 util: 213 node: 498 schema: 9 sym: 96 type: 47 util: 329 joda: 37 time: 37 format: 6 json: 67 w3c: 4 dom: 4 bootstrap: 2 ls: 2 xml: 1 sax: 1 xmlpull: 13 v1: 13 techonology: 1429 nexts: 1429 media: 1429 adapter: 170 controller: 180 cache: 32 update: 38 fragments: 91 objects: 119 views: 377 dialog: 79 quickaction: 48 vn: 409 nexts: 409 backup: 84 constant: 9 help: 52 manager: 133 location: 35 model: 103 receiver: 5 se: 10 service: 13 Overall method count: 60301 |
- 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
1 | C: Java Program Files jdk1.8.0_45 bin> java -jar E: method.jar --max-depth = 1 --output-style = TREE E: mp3.apk |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Processing E: mp3.apk Read in 60301 method IDs. <root>: 60301 <default>: 1 android: 13568 bolts: 183 com: 36314 dalvik: 2 java: 1435 javax: 38 okio: 461 org: 6455 techonology: 1429 vn: 409 Overall method count: 60301 |
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.