Reputation: 1711
We are building an Android application with a server backend which is a simple Java project. These two projects should now share some classes.
We are developing the Android app with Android Studio and the server backend with Intellij IDEA.
We have been unable to properly import the backend project or use it as a dependency properly. How do you do this?
Upvotes: 0
Views: 173
Reputation: 1704
Usually when I have situation like this, I create new module/project called "Commons" and put there all classes shared between Client and Backend. Then I add it as a dependency for both Client and Backend.
As long as you don't use sophisticated Java tricks that are not supported by Android (like lambdas introduced in Java 8), everything will work fine.
It's much better than creating jar
library on your own, since you don't have to update it manually everytime you change something in it.
Please write a comment if you have any further questions :)
Upvotes: 1
Reputation: 13535
Usually android app connects with backend via network connection, so you need not to import the whole backend as a dependency. To share some classes, form that classes as a library and use it as a dependency in both android and backend projects.
Upvotes: 0
Reputation: 80
I suppose that you connect the android app with service via REST or similar.
For example, you could have a User class in the server and User class in the app. This class might be the same and I supose that you want import service classes in the app because of this. That isn't the correct because you might have properties in the service that you don't want share with the app.
In real developement you can build an app that use a external Service and you never going to have the classes that the service developers are using.
In conclusion, the correct way is that you have your classes for the service and new others for app.
Upvotes: 0