1 /*
2  * Copyright (C) 2018 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 String TEST_NAME = "172-app-image-twice";
21 
main(String args[])22     public static void main(String args[]) throws Exception {
23         System.loadLibrary(args[0]);
24 
25         Class<?> tc1 = Class.forName("TestClass");
26 
27         String dexPath = System.getenv("DEX_LOCATION") + "/" + TEST_NAME + ".jar";
28         Class<?> bdcl = Class.forName("dalvik.system.BaseDexClassLoader");
29         Method addDexPathMethod = bdcl.getDeclaredMethod("addDexPath", String.class);
30         addDexPathMethod.invoke(Main.class.getClassLoader(), dexPath);
31 
32         Class<?> tc2 = Class.forName("TestClass");
33 
34         // Add extra logging to simulate libcore logging, this logging should not be compared
35         // against.
36         System.out.println("Extra logging");
37 
38         if (tc1 != tc2) {
39             System.out.println("Class mismatch!");
40             debugPrintClass(tc1);
41             debugPrintClass(tc2);
42         } else {
43             System.out.println("passed");
44         }
45     }
46 
debugPrintClass(Class<?> cls)47     public static native void debugPrintClass(Class<?> cls);
48 }
49