Created
July 16, 2013 00:03
-
-
Save swankjesse/6004640 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.android.dex; | |
import java.io.File; | |
import java.io.IOException; | |
import java.util.Map; | |
import java.util.TreeMap; | |
import java.util.concurrent.atomic.AtomicInteger; | |
public class Summary { | |
public static void main(String[] args) throws IOException { | |
Dex dex = new Dex(new File(args[0])); | |
Map<String, AtomicInteger> packageToCount = new TreeMap<String, AtomicInteger>(); | |
for (MethodId methodId : dex.methodIds()) { | |
String typeName = dex.typeNames().get(methodId.getDeclaringClassIndex()); | |
String packageName = typeNameToPackageName(typeName); | |
AtomicInteger count = packageToCount.get(packageName); | |
if (count == null) { | |
count = new AtomicInteger(); | |
packageToCount.put(packageName, count); | |
} | |
count.incrementAndGet(); | |
} | |
for (Map.Entry<String, AtomicInteger> entry : packageToCount.entrySet()) { | |
System.out.printf("% 8d %s%n", entry.getValue().get(), entry.getKey()); | |
} | |
} | |
private static String typeNameToPackageName(String typeName) { | |
if (typeName.startsWith("[")) typeName = typeName.substring(1); // arrays | |
if (!typeName.contains("/")) return "<default>"; // default package | |
return typeName.substring(1, typeName.lastIndexOf('/')).replaceAll("/", "."); | |
} | |
} |
There is no Dex class in dx.jar.
I'm not seeing Dex in dx.jar either. My dx.jar is from $ANDROID_HOME/build-tools/18.0.1/lib/
@swankjesse you sure its in dx.jar?
Thanks for this code, works pretty well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You'll need dx.jar on your classpath.