blob: 8dbbba56c3ac6ca5cf22e7ae86f863924ebb0e54 [file] [log] [blame]
Richard Uhler24ed94f2017-11-16 11:54:29 +00001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Richard Uhler24ed94f2017-11-16 11:54:29 +000017import java.lang.reflect.Method;
18
19public class Main {
Richard Uhler24ed94f2017-11-16 11:54:29 +000020 private static long getDexFileSize(String filename) throws Exception {
21 ClassLoader loader = Main.class.getClassLoader();
22 Class<?> DexFile = loader.loadClass("dalvik.system.DexFile");
23 Method DexFile_loadDex = DexFile.getMethod("loadDex",
24 String.class,
25 String.class,
26 Integer.TYPE);
27 Method DexFile_getStaticSizeOfDexFile = DexFile.getMethod("getStaticSizeOfDexFile");
28 Object dexFile = DexFile_loadDex.invoke(null, filename, null, 0);
29 return (Long) DexFile_getStaticSizeOfDexFile.invoke(dexFile);
30 }
31
32 private static void test(String resource) throws Exception {
David Brazdil7d2ec612018-01-19 14:19:59 +000033 String filename = System.getenv("DEX_LOCATION") + "/res/" + resource;
Richard Uhler24ed94f2017-11-16 11:54:29 +000034 long size = getDexFileSize(filename);
35 System.out.println("Size for " + resource + ": " + size);
36 }
37
38 public static void main(String[] args) throws Exception {
39 test("test1.dex");
40 test("test2.dex");
41 test("test-jar.jar");
42 test("multi-jar.jar");
43 }
44}