mihaip / dex-method-counts Goto Github PK
View Code? Open in Web Editor NEWCommand-line tool to count per-package methods in Android .dex files
License: Apache License 2.0
Command-line tool to count per-package methods in Android .dex files
License: Apache License 2.0
Why not make this a universal tool for counting all ?
static class HeaderItem {
public static final byte[] DEX_FILE_MAGIC = { 0x64, 0x65, 0x78, 0x0a, 0x30, 0x33 }; // , 0x??, 0x00 };
}
private static boolean verifyMagic(byte[] magic) {
return Arrays.equals(Arrays.copyOfRange(magic,0,HeaderItem.DEX_FILE_MAGIC.length), HeaderItem.DEX_FILE_MAGIC)
&& magic[HeaderItem.DEX_FILE_MAGIC.length] >= 0x30
&& magic[HeaderItem.DEX_FILE_MAGIC.length+1] == 0x00;
}
Is it possible to automate this process on every debug build by creating custom gradle task?
Would be great to have a switch that enables a mode which prints only the total method count. I've added this functionality in my fork but it constitutes some rather reaching changes to the code base that I'm not sure fit the pattern you're currently using.
It would be nice if it was possible to easily use the output of this tool for other scripts, that would for example compare binary versions to find regressions.
Yaml seems to be a good candidate as it is already quite similar to the current output. It could be essentially changing the output from
Read in 65490 method IDs.
<root>: 65490
<default>: 3
android: 6837
accessibilityservice: 6
bluetooth: 2
content: 248
pm: 22
res: 45
...
com: 53881
adjust: 283
sdk: 283
codebutler: 65
android_websockets: 65
...
Overall method count: 65490
To something like
---
<root>:
<default>: 65490
android:
<default>: 6837
accessibilityservice: 6
bluetooth: 2
content:
<default>: 248
pm: 22
res: 45
...
com:
<default>: 53881
adjust:
<default>: 283
sdk: 283
codebutler:
<default>: 65
android_websockets: 65
...
The totals aren't as prominent as in the current format so maybe just make it an option instead of the default format?
If you have download gradle file in AndroidStudio, then you can replace
"distributionUrl=https://services.gradle.org/distributions/gradle-2.4-bin.zip"
in gradle/wrapper/gradle-wrapper.properties by
"distributionUrl=https://services.gradle.org/distributions/gradle-2.4-all.zip"
then the gradle file would not need to download again.
This tip may be useful to the developers in counties which has limited access to gradle.org
Hello, is there any way to count total of classes on dex file,
its on dalvik.system.DexFile package, but must load inside android, if possible to count it outside of android itself
Hi i have a JAR which is a library that i have developed for Android devices. I convert the JAR into dex and then run the script. But in my JAR, why are the method counts for android and JAVA packages are involved? These methods are native android and JAVA methods and they don't ship into my JAR. So why are these included for the dex count?
android: 650
animation: 10
app: 47
content: 93
pm: 11
res: 4
database: 18
sqlite: 8
graphics: 58
drawable: 8
location: 20
media: 20
net: 20
wifi: 8
os: 38
provider: 3
support: 23
v4: 15
view: 15
v7: 8
widget: 8
telephony: 41
cdma: 3
gsm: 3
text: 1
util: 15
view: 101
accessibility: 2
animation: 10
webkit: 50
widget: 92
.........
.........
java: 381
io: 36
lang: 145
ref: 3
reflect: 8
math: 1
net: 25
nio: 4
security: 9
spec: 1
text: 5
util: 156
concurrent: 37
atomic: 8
zip: 1
javax: 17
crypto: 14
spec: 3
xml: 3
parsers: 3
org: 61
json: 50
w3c: 10
dom: 10
xml: 1
sax: 1
Overall method count: 6163
I wanted to count number of classes directly in a application java folder but the library didn't search in sub-folder and stop on the first folder with a java.io.FileNotFoundException (is a directoy)
which is true but I'm stuck with that :/
Will it be possible to teach tool to work with AAR packages?! This is actually ZIP with JAR inside... so its not exactly the DEX...
but gradle execute special step - preDexLibraries, that actually produce a DEX... so i think its possible to count methods inside AAR in two steps.
i can get method count,is there anyway to dump methods name?
btw,some classes's method-count are different to javap's.
Can you make it possible to count inside decompiled APK, so I can easly see if i have reached the limit or not when working with smali without having to recompile?
It doesn't appear that the script supports builds that result in multiple dex files, where classes are segmented into a primary dex file and additional dex files. The script reports only 22K methods, which I believe to be merely the methods from the primary dex (mostly our own application minus libraries.)
The Android tool chain will generate multiple DEX files when your minSdkLevel is Lollipop / 21 since that is how ART deals with library code (one dex per dependency), and also when you have the multidex switch enabled.
can you publish this to central?
Exception in thread "main" java.lang.UnsupportedClassVersionError: info/persistent/dex/Main : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: info.persistent.dex.Main. Program will exit.
Hi, my project has failed to build due to too many methods, can I use this tool to pinpoint the culprit? I'm not sure how to run it given I don't have an APK file, thanks!
Need to calculate the number of methods and variables in the smali file, not through dex. How?
$ dex-method-counts --max-depth=1 classes.dex
Processing classes.dex
Read in 64203 method IDs.
<root>: 64203
<default>: 1
android: 9104
anet: 380
anetwork: 450
com: 23416
dalvik: 13
java: 1621
javax: 45
mtopsdk: 706
org: 526
tv: 29
Overall method count: 64203
when I plus each package together, the result is 36290(9104 + 380 + ...+ 29), but the overall method count is 64203. why?
Google release Android Studio 2.0 to Stable Channel today, as well as its instant run features. I believe dex-method-counts
count the methods incorrectly for APK produced with instant run. If you try to extract the APK, you could see there is a new file instant-run.zip
which contains all dexes for each package. I believe this is the reason why dex-method-counts
won't work.
Any plan to support this? Thanks.
What about built .jar? You can create release and attach binary to release directly on the GitHub, mm? https://github.com/blog/1547-release-your-software
Hello, is it possible to add "export data to JSON/XML file" feature?
Windows doesn't support the runfile you provided. You can make a .bat file, or provide the different code for Windows:
java -jar [path-to-generated-jar (./build/jar/....)] [filename to inspect]
Version number of dex-method-counts is hardcoded as "1.0" in every versions.
https://github.com/mihaip/dex-method-counts/blob/master/src/info/persistent/dex/Main.java#L203
I'd like to use this useful tool in my daily job and I have to get permission from the security office to do that.
They told me they need managable version number of the object for tracking purpose, so hardcoded one is not acceptable.
Hi, I wonder if it is possible to measure the size of methods and classes (LOC bytes, etc)?
Thanks.
I created a symlink of dex-method-counts into a directory that was in my $PATH so that I could execute it easily.
However, I found that this does not work; if you execute dex-method-counts via a symlink, it can't find the jar.
I have a fix for this that I've tested on Ubuntu and OS X, and will file a PR shortly.
在 https://github.com/Tencent/matrix#matrix_cn 页面单独下载 matrix-apk-canary-0.4.10.jar 失败
浏览器提示:
载入页面时与 d29vzk4ow07wi7.cloudfront.net 的连接中断。
由于不能验证所收到的数据是否可信,无法显示您想要查看的页面。
建议向此网站的管理员反馈这个问题。
The output information is too long,How to write it to the log?
I git clone this repo to my computer. I enter dex-method-counts/ folder and execute ./dex-method-counts /path/to/my.apk in linux shell and get an error says "can't find dex-method-counts.jar".
What I did wrong? How to solve it and get right output?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.