문제

I'm working on android app that's running up against the dex method count limit. Is there a simple way to show the method count grouped by package? I can get the total method count, but my app has multiple components and I'm trying to figure out which component is the biggest contributor to this.

도움이 되었습니까?

해결책 2

This will give you an idea of how much each package hierarchy contributes to the method count. The results include all classes in that directory/package and all subdirectories/packages.

baksmali blah.apk -o out
cd out
find * -type d -print -exec sh -c "smali {} -o {}/classes.dex && sh -c \"dexdump -f {}/classes.dex | grep method_ids_size\"" \;

This slightly modified version is similar, except that it is only for the classes in that particular directory/package, not including any subdirs/subpackages

baksmali blah.apk -o out
cd out
find * -type d -print0 | xargs -0 -I{} sh -c "echo {} && find {} -maxdepth 1 -name \"*.smali\" -print0 | xargs -r -0 smali -o {}/classes.dex"
find -name "*.dex" -print -exec sh -c "dexdump -f {} | grep method_ids_size" \;

다른 팁

I've written a dex-method-counts tool that outputs per-package method counts faster and more accurately than the smali-based tools referenced in JesusFreke's answer¹. It can be installed from https://github.com/mihaip/dex-method-counts.

[1] that script disassembles the .dex and re-assembles it by package, but this means that methods that are referenced by multiple packages are counted twice

I and a collegue published the last month a service that can help you with your purpose: http://www.methodscount.com/. It shows the methods count and other neat information

enter image description here

Under the hood we use gradlew to get the dependencies and the Android SDK tool dx to calculate the dex information. We apply the procedure recursively to the library and its dependencies. We also persist the results for the already computed libraries so to speed up the process on consequent requests.

If you use Android Studio or IntelliJ, you can just install the plugin to have all the information as an handy hint (the plugin uses the service as well).

Piling on to an old question, I've written a Gradle plugin that will report the number of methods in your APK on every build. It uses the same DEX parsing code that the AOSP project uses. You can find it at https://github.com/KeepSafe/dexcount-gradle-plugin.

I appreciated the work off all developers above and I am always happy to have such great community, but since Android studio 2.2 Google team has released APK Analyzer -> https://developer.android.com/studio/build/apk-analyzer.html

Now we all have build in tool to analyze out methods count, our resources size and even we can compare two .apk files agains each other. Finally we all have this tool build in. Android development is coming to be easier and easier.

BTW: To find how much methods you have, open your .apk file in Android Studio (support 2.2+ only) and click on the classes.dex file. After that you will be able to see the methods count in all libraries and in your project as well.

You can also try using https://github.com/KeepSafe/dexcount-gradle-plugin which allows you to see the method counts per package graphically through an html.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top