Skip to content

Instantly share code, notes, and snippets.

@toms972
Created July 28, 2014 09:05
Show Gist options
  • Save toms972/c83504df2da1176a248a to your computer and use it in GitHub Desktop.
Save toms972/c83504df2da1176a248a to your computer and use it in GitHub Desktop.
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}]"
end
}
# Print out total count
puts "Total of #{total_count} methods"
end
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
File.delete(temp_dex_path)
# Return int
count.to_i
end
end
# Input check
if ARGV.empty? || ARGV.size > 1
puts 'usage: ./count_android_methods.rb [jar folder path]'
else
counter = CountAndroidMethods.new
counter.count(ARGV.first)
end
@ilyasjan
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