Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a project in another project as a module?

I'm hoping to modularize an Android project so it will be easy to maintain in future use. I want to know whether its possible or not, to make an Android project used as a module within another Android project?

For example, let's say in my main android project I have three buttons for login, signup, forget password. and I have three separate projects for login, signup and forget password with their own views, activities and libraries. How can I use these separate android projects in the main Android project so when I click any of the three options in the main activity view so it will load the relevant view from those three module projects? (click the login button in the main view and load login view from the separate login project activities). I have tried to fiddle with build files and library module importing but couldn't do it. help me with saying if this approach is possible or not? if possible how to achieve it?

like image 866
Pixxu Waku Avatar asked Oct 18 '18 06:10

Pixxu Waku


2 Answers

settings.gradle in root project include each project.

include ':loginApp'
include ':signupApp'
include ':resetpasswordApp'

project(':loginApp').projectDir = file('path/to/LoginApp')
project(':signupApp').projectDir = file('path/to/SignupApp')
project(':resetpasswordApp').projectDir = file('path/to/ResetpasswordApp')

build.gradle Of main module

implementation project(':loginApp')
implementation project(':signupApp')
implementation project(':resetpasswordApp')
like image 173
Khaled Lela Avatar answered Sep 19 '22 11:09

Khaled Lela


Yes, it's possible. Your current project is basically a module too. See the app folder.

An easy way is to create a new module (android library) with a different name from the current one which by default is app. Let's call it bigapp. This module will have all properties just like your app and you can select to run it from the debug configuration too.

Go to settings.gradle and ensure the file reads include ':app', ':bigapp'

To use the bigapp and call its functions, import it in your dependency. This will be the build.gradle file of the app module.

dependencies {
    implementation project(":bigapp")
}

Lets now start the MainActivity from our app module

startActivity(new Intent(this, com.lucemanb.bigapp.MainActivity.class));

You can also import it at the top and simply call the MainActivity

import com.lucemanb.bigapp.MainActivity;

---

private void startActivity(){
    startActivity(new Intent(this, MainActivity.class));
}
like image 34
Lucem Avatar answered Sep 20 '22 11:09

Lucem