How to add Java file to Build Path Android Studio

Viewed 409

I have some .java files that I'd like to include in my build path to utilize some of the classes and such inside them. I've added them to the /lib folder but it doesn't allow me to call data types and methods and such from the .java files in my app project (in the .MainActivity). How can I accomplish this?

1 Answers

The simplest thing is just to add the Java source code to your existing project, alongside your existing Java code.

In your case, the Java files do not have a package declaration. That's... not good. But, you can add one, then put the files in the appropriate directory for that package in your project. For example, you could use the package used by some of your existing classes, then put the files in the same directory as those classes.

If the Java files already had a package, you could create a directory tree off of your java/ directory based on that package, then put the Java files in that directory.

Related