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?
Asked
Active
Viewed 65 times
1
-
How are you using it? Include? If so , you can load it from any location. – Yeikel Dec 30 '16 at 06:36
-
I try put **include '../SharedCode/MyFunctions.java';** in **settings.gradle** but don't work – Dec 30 '16 at 07:13
-
Yes, that is possible. So what is the actual problem? – moffeltje Dec 30 '16 at 12:19
3 Answers
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
-
-
@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:
- First, I make a .JAR of my library
- Import the .JAR to your Project in libs folder and make this as library
- 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