Skip to content

How I can build a .jar file first and then my andoid app?

In my project: https://github.com/pc-magas/sercommH300sVoipCredentialsRecovery source is seperated into 2 parts:

  1. The core library where no android dependencies are placed.
  2. The android app iself.

Core Logic is in app/src/main/java/pc_magas/vodafone_fu_h300s/logic/ and the tests for the core logic is in: app/src/test/java/pc_magas/vodafone_fu_h300s/logic/

Therefore, I want to split my build process into these phases:

  1. Build a .jar out of the app/src/main/java/pc_magas/vodafone_fu_h300s/logic/
  2. place it into ./app/libs
  3. Build the app itself using the generated .jar

Therefore how I can configure the gradle.build to build my library first?

Answer

Well based upon this answer you’ll need you create a new Java/Kotlin library in order to do this you’ll need to follow these steps:

  1. In android studio select File -> New -> New Module
  2. Then select Java or Kotlin Library.
  3. Use the default settings.

This step creates a new folder with its own build.gradle. I’ll assume that the folder’s name is settings_fetcher. The folder name is the one you choose in this window:

Android Studio window that decides the folder library name as well

Also, this name mentioned above is the name you’ll need to place into the application’s dependency as well. So in the window shown above used settings_fetcher as Library Name then you’ll need to place the following dependency into your build.gradle located into

Once you created the module place into app/build.gradle the correct dependency as stated in this answer.

Then move the files located in app/src/main/java/pc_magas/vodafone_fu_h300s/logic/ into the settings_fetcher/src/main/java/pc_magas/vodafone_fu_h300s/logic/ also move any tests, related to the library, located in app/src/tests into settings_fetcher/src/tests (Assuming the new library is named settings_fetcher)

Then try to run the tests and build the application as well in order to ensure the correctness of the application’s functionality as well.