Android multiple apps and modules in one project demo
1. Create a new project using the Android Studio create new project wizard. Name the project thanksgiving.
2. Create a new module and name it base, File -> New -> New Module -> Select Android Library. Create Greeting class to be used by the thanksgiving and christmas apps. Greeting
object Greeting { val thanksgivingGreeting = "Happy Thanksgiving, eat some turkey!" val christmasGreeting = "Merry Christmas, unwrap yourself a joyful Christmas!" }
3. Create a new app and name it christmas, File -> New -> New Module -> Select Phone and Tablet module.
4. Open the activity_main.xml in the thanksgiving and christmas app, update it to the following.
5. Open the app gradle files for the thanksgiving and christmas app, add this line in the dependencies to include the base module.
implementation project(':base')
6. Add this line in the onCreate function in the thanksgiving app, it uses the Greeting class from the base module to set the TextView string.
tv_greeting.text = Greeting.thanksgivingGreeting
7. Add this line in the onCreate function in the christmas app, it uses the Greeting class from the base module to set the TextView string.
tv_greeting.text = Greeting.christmasGreeting
With the above steps, we have created an Android project with one library module and two Android apps in one source directory. The thanksgiving and christmas apps are using the Greeting class from the base module to get greetings. Since this is only for demo purpose, so the base module here is super simple that it only gives greetings, but you can create a lot more functionalities in the base module and use them in other apps.
Search within Codexpedia
Search the entire web