Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 8215107

Browse files
authored
Merge pull request #112 from google/custom-standard-multidex
added custom dex checking for mulitdex
2 parents 830c052 + 97c787d commit 8215107

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

ClassySharkWS/src/com/google/classyshark/Shark.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ public List<String> getAllStrings() {
8282
public boolean isMultiDex() {
8383
return SilverGhostFacade.isMultiDex(archiveFile);
8484
}
85-
85+
86+
public boolean isCustomMultiDex() {
87+
return SilverGhostFacade.isCustomMultiDex(archiveFile);
88+
}
89+
8690
public static void main(String[] args) {
8791

8892
File apk =

ClassySharkWS/src/com/google/classyshark/silverghost/SilverGhostFacade.java

+38-7
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@
2828
import com.google.classyshark.silverghost.translator.apk.ApkTranslator;
2929
import com.google.classyshark.silverghost.translator.dex.DexMethodsDumper;
3030
import com.google.classyshark.silverghost.translator.dex.DexStringsDumper;
31-
3231
import java.io.File;
3332
import java.io.PrintWriter;
3433
import java.util.LinkedList;
3534
import java.util.List;
3635

3736
/**
38-
* Basic API class with small independent scenarios
37+
* Basic API class with small independent scenarios
3938
*/
4039
public class SilverGhostFacade {
4140
private SilverGhostFacade() {
@@ -127,7 +126,7 @@ public static void inspectPackages(List<String> args) {
127126
MethodCountExporter methodCountExporter =
128127
new TreeMethodCountExporter(new PrintWriter(System.out));
129128
if (args.size() > 2) {
130-
for (int i = 2; i < args.size(); i++ ) {
129+
for (int i = 2; i < args.size(); i++) {
131130
if (args.get(i).equals("-flat")) {
132131
methodCountExporter = new FlatMethodCountExporter(new PrintWriter(System.out));
133132
}
@@ -155,7 +154,8 @@ public static void exportArchive(List<String> args) {
155154
}
156155
}
157156

158-
/** returns true if the apk is multidex
157+
/**
158+
* returns true if the apk is multidex
159159
*
160160
* @param archiveFile
161161
* @return
@@ -167,16 +167,47 @@ public static boolean isMultiDex(File archiveFile) {
167167
List<String> allClassNames = contentReader.getAllClassNames();
168168
int numDexes = 0;
169169

170-
for(String classEntry : allClassNames) {
171-
if(classEntry.endsWith(".dex")) {
170+
for (String classEntry : allClassNames) {
171+
if (classEntry.endsWith(".dex")) {
172172
numDexes++;
173173
// 2 dexes or more + optimization
174-
if(numDexes == 2) {
174+
if (numDexes == 2) {
175175
return true;
176176
}
177177
}
178178
}
179179

180180
return false;
181181
}
182+
183+
/**
184+
* returns true if the apk is custom dex loading multidex
185+
*
186+
* @param archiveFile
187+
* @return
188+
*/
189+
public static boolean isCustomMultiDex(File archiveFile) {
190+
if (!isMultiDex(archiveFile)) {
191+
return false;
192+
}
193+
194+
ContentReader contentReader = new ContentReader(archiveFile);
195+
contentReader.load();
196+
197+
List<String> allClassNames = contentReader.getAllClassNames();
198+
List<String> allDexNames = new LinkedList<>();
199+
200+
for (String classEntry : allClassNames) {
201+
if (classEntry.endsWith(".dex")) {
202+
allDexNames.add(classEntry);
203+
}
204+
}
205+
206+
for (String classEntry : allDexNames) {
207+
if (!classEntry.startsWith("classes")) {
208+
return true;
209+
}
210+
}
211+
return false;
212+
}
182213
}

0 commit comments

Comments
 (0)