Home | History | Annotate | Download | only in src
      1 /*
      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 
     17 import java.lang.reflect.Method;
     18 
     19 public class Main {
     20     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 {
     33         String filename = System.getenv("DEX_LOCATION") + "/res/" + resource;
     34         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 }
     45