solve class loader isolation problem when load same classes in different jar
Switch branches/tags
Nothing to show
Clone or download
Latest commit 1cfc516 Jul 9, 2015
Failed to load latest commit information.
java-dynamic-loader-common init Jun 10, 2014
java-dynamic-loader-host Update Jul 9, 2015
java-dynamic-loader-jar1 init Jun 10, 2014
java-dynamic-loader-jar2 init Jun 10, 2014
.gitignore init Jun 10, 2014
LICENSE Initial commit Jun 10, 2014 Update Jun 23, 2014

Java Dynamic Load Jar

Solve class loader isolation problem when load same classes in different jar, but not work for android because of dalvik pre-verification failed, cry...

Class Diagram
中文文档介绍:[Java 加载不同依赖 Jar 中的公共类]( ‎)




  1. extend
  2. contains CommonClass field


  1. extend
  2. contains CommonClass field


  1. to load jar1 and jar2, load from current ClassLoader first if class is CommonClass .
  2. have 3 tests
    TestA: CommonClass loaded from jar1 and jar2 are equals
    TestB: ChildCommonClass1 or ChildCommonClass2 can be reflected to CommonClass in host normaly
    TestC: or those contains CommonClass field can be reflected and running normal.

###Run Loading projects to eclipse, run java-dynamic-loader-host as a Java Application

###Android It's simple in java, but not work for TestB and TestC on android, because dalvik pre-verification failed. This may solved it, but I have not try.

17:28:36.095: E/PluginDexClassLoader(1464): support class is, current loader:1110431216, commmon lib loader:1108712248, clazz:1110549272
17:28:36.095: W/dalvikvm(1464): Class resolved by unexpected DEX: Lcn/trinea/java/dynamic/load/jar1/ChildCommonClass1;(0x422fd5f0):0x6838f000 ref [Lcn/trinea/java/dynamic/load/common/CommonClass;] Lcn/trinea/java/dynamic/load/common/CommonClass;(0x42159b38):0x65ae6000
17:28:36.095: W/dalvikvm(1464): (Lcn/trinea/java/dynamic/load/jar1/ChildCommonClass1; had used a different Lcn/trinea/java/dynamic/load/common/CommonClass; during pre-verification)
17:28:36.095: W/dalvikvm(1464): Unable to resolve superclass of Lcn/trinea/java/dynamic/load/jar1/ChildCommonClass1; (993)
17:28:36.095: W/dalvikvm(1464): Link of class 'Lcn/trinea/java/dynamic/load/jar1/ChildCommonClass1;' failed
17:28:36.095: W/dalvikvm(1464): threadid=1: thread exiting with uncaught exception (group=0x416fb498)
17:28:36.095: E/AndroidRuntime(1464): FATAL EXCEPTION: main
17:28:36.095: E/AndroidRuntime(1464): java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
17:28:36.095: E/AndroidRuntime(1464): 	at dalvik.system.DexFile.defineClass(Native Method)
17:28:36.095: E/AndroidRuntime(1464): 	at dalvik.system.DexFile.loadClassBinaryName(
17:28:36.095: E/AndroidRuntime(1464): 	at dalvik.system.DexPathList.findClass(
17:28:36.095: E/AndroidRuntime(1464): 	at dalvik.system.BaseDexClassLoader.findClass(
17:28:36.095: E/AndroidRuntime(1464): 	at java.lang.ClassLoader.loadClass(


Copyright 2014

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.