How to load Java class with Class.forName() in Android app?

  Kiến thức lập trình

I hava an Android app and want to invoke a Java class, e.g.,
during runtime (intead of adding the Java class into my app project at compile time).

In the traditional Java development, I can do so by calling something like
in my own Java program, when running my program, I just provide the class path of com.example.ThatClass (or the .jar file if the class is packed into jar).

But I don’t know how this can be done in Android app: like how to tell the app the class path of com.example.ThatClass? Assuming I can place the jar file containing com.example.ThatClass into some system partition when I build the entire AOSP from ground up (so the .jar is a system lib like framework.jar), what is my options?


I tried Google “how to dynamically load java class in Android”, but the results show the solution of adding .jar to my app project in Android Studio, this is not what I wanted.