Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Android environment has a limitation of maximum 65536 methods definition Here is a ruby script that helps to count the number of methods per each jar.
#!/usr/bin/env ruby
class CountAndroidMethods
def count(path)
full_folder_path = File.expand_path(path)
total_count = 0
# Traverse the folder
Dir.entries(full_folder_path).each {|file|
# Attempt to read only jars
if file.end_with?('jar')
# Count methods in dex
count = count_methods_in_jar(full_folder_path, file)
# Accumulate count
total_count = total_count + count
# Print out count
puts "File: [#{file}] Methods: [#{count}]"
# Print out total count
puts "Total of #{total_count} methods"
def count_methods_in_jar(full_folder_path, jar_file_name)
temp_dex_path = full_folder_path + '/temp.dex'
jar_path = full_folder_path + '/' + jar_file_name
# Create a temp dex file
`dx --dex --output=#{temp_dex_path} #{jar_path}`
# Count methods in dex
count = `cat #{temp_dex_path} | head -c 92 | tail -c 4 | hexdump -e '1/4 "%d"'`
# Delete temp dex file
# Return int
# Input check
if ARGV.empty? || ARGV.size > 1
puts 'usage: ./count_android_methods.rb [jar folder path]'
counter =
Copy link

lambed commented Aug 31, 2014

This is nice work however, the real question is if you have too many methods in a jar in a project especially in a library you don't control what can you do about it.

Copy link

yshinkarev commented Sep 7, 2014

Thanks for the code

Copy link

ilyasjan commented Sep 1, 2015

how to use this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment