How to import java class from another app’s src folder?

Asked

Viewed 37 times

-1

For example, I have several apps. They all have in the src folder the same java class (example: Calculator.java which is the same for everyone). Only when I modify this class, I have to copy it to all src folders of all apps.

Can I import this class from the src folder of a particular app to everyone else? Or have a common folder (with certain common java classes) for all other apps?

  • Do not put greetings or thanks in questions or answers. Ref: https://answall.com/help/behavior

1 answer

0


From what I understand you are wanting to create a library - a standalone module to be reused by various applications.

In this case you will need to create a separate project and reference the compiled project in a certain folder.

To create a new library module in the project, do the following:

  1. Click File > New > New Module.
  2. In the Create New Module window that appears, click Android Library and Next.
  3. Name the library, select a minimum SDK version for the code in the library, and click Finish.

See the guidelines in the links below:

https://developer.android.com/studio/projects/android-library

https://qastack.com.br/programming/16608135/android-studio-add-jar-as-library

https://medium.com/android-dev-br/como-crea-suas-pr%C3%B3prias-libraries-b86e4ad77b92

  • Gabriel, I had even used this before (to create a jar and include it as a library), but I had forgotten. It’s really an option. Although I still use the eclipse...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.