1

I have a java class called MyFunctions.java that I use in two Projects (A, B). This make two files of the same. It's posible to create a folder called "SharedCode" and put the MyFunctions.java inside, and link this file in both projects?

3 Answers3

0

Create a project for MyFunctions.java (say util ) and it in both the project A and B. In Eclipse add it in the path by : right click on project (A or B) -> Properties -> Java Build Path -> Projects -> Add

Rohit Gulati
  • 542
  • 3
  • 15
  • I'm using Android Studio –  Dec 30 '16 at 07:24
  • @richard1994x you should be able to do that in android studio as well. Create a jar and add that in the library. These links [link](http://stackoverflow.com/questions/16608135/android-studio-add-jar-as-library?rq=1) and [link2](http://stackoverflow.com/questions/17479076/android-studio-add-external-project-to-build-gradle) may be useful. – Rohit Gulati Dec 30 '16 at 07:30
0

I gonna show my solution:

  1. First, I make a .JAR of my library
  2. Import the .JAR to your Project in libs folder and make this as library
  3. Add compile files('../../YourJar.jar') in your dependencies of module build.gradle

Now, I can acccess mys functions in one patch only for all projects.

0

Just create a Gradle Java module in a new Gradle project and link that module in your settings.gradle. After that you can declare the module as a dependency in your app/library module. Essentially what's described in this answer.

Community
  • 1
  • 1
ubuntudroid
  • 3,680
  • 6
  • 36
  • 60