Is there a way to get count of number methods used in a jar file

前端 未结 12 2195
粉色の甜心
粉色の甜心 2020-11-28 03:20

Can i have the count of all methods used in a jar file . My APK uses certain external JARS and there are a number of classes around hundred to be precise.

I have use

12条回答
  •  渐次进展
    2020-11-28 03:53

    I just wrote a python script for this to get a rough estimate

    import re
    import subprocess
    import sys
    
    for jarfile in sys.argv[1:]:
        class_output = subprocess.check_output(['jar', 'tf', jarfile])
        classes = [c.replace('/', '.') for c in re.findall(r'(.*)\.class', class_output)]
        methods = []
        if classes:
            def_out = subprocess.check_output(['javap', '-classpath', jarfile] + classes)
            # This is pretty hacky: look for parentheses in the declaration line.
            num_methods = sum(1 for line in def_out if '(' in line)
        else:
            num_methods = 0
        print '{} {} {}'.format(num_methods, len(classes), jarfile)
    

    I had just run into the Android 64K method limit, and my dependencies weren't indexed by the methodcount.com service yet.

提交回复
热议问题