Load .class file in android to use as a local class

250 views Asked by At

We have to dynamically load a .class file into Android. The .class file is generated serverside and depends on user input in another software.

Let me give you an example on what we're trying to achieve here. Let's say we want to load this class during runtime:

Person.class

public class Person{

    String name;

    public Person(String name){
        this.name = name;
    }

    public String getName(){
        return this.name;
    }

}

We want to include this class in a way that allows us to use its functions just like functions of any other class. For example:

Person person1 = new Person("mike");
System.out.println(person1.getName());

We found lots of examples, but all of them assume that you have a static class file which isn't going to change and can therefore convert it to a dex file during development.

1

There are 1 answers

0
Kartik On

The closest I can think of achieving this is through RMI. I found following answer that might be helpful for using RMI on Android:

Using JAVA RMI in Android application