How to use the same file java class in two different projects in Android Studio

764 views Asked by At

I need use the class SharedClass.java in two projects: ProjectA and ProjectB, and if I change the code of SharedClass, it needs to change in the other project too.

1

There are 1 answers

0
Floern On

One option would be creating a library project or module, where you can provide all shared code, and include that in both projects.

Another option is adding an external source folder containing the shared classes to your projects, by adding it to the srcDirs in your build.gradle files:

android {
    ...
    sourceSets {
        main.java.srcDirs += '../../path/to/shared/code'
    }
}