1

There is a interface IA class in APK file. I create a jar containing IA's implementation MA. The jar has a Global class and B class. The jar is loaded dynamically with Dexclassloader from data directory.

interface IA {
  test();
}

class Global {
   IA instance;  //refer to  MA instance.
}

class B {
  ....
  instance.test() ; // throw NoSuchMethodError
....
} 

But it's OK to call instance's test method through reflection.

Why? Surely I am not familiar with some principals of Classloader or DexClassloader. Could someone give explanation for me? Thanks

Victor Choy
  • 4,006
  • 28
  • 35

1 Answers1

0

I too got a NoSuchMethod error, after doing some testing I found out that the problem was that the DEX file inside the JAR wasn't named classes.dex as it's supposed to be. The fact that the app was able to create a new instance of your class doesn't necessarily mean that the DEX was loaded properly, I tested it with an empty JAR (i. e. removed all internal files via 7-ZIP) and was still able to instantiate my class (although I guess it would work only with a default constructor that gets zero parameters).

Ezra Steinmetz
  • 1,267
  • 1
  • 17
  • 18