Code inside a module is separate and can be called from other modules.
Android Kotlin
module1/src/main/java/com/example/module1/Utils.kt
fun greet() = "Hello from Module 1"
Sample App
This example shows two modules: app and greeting. The greeting module has a function that returns a message. The app module uses this function to show the message on screen.
Hint: Use implementation project(":moduleName") to add module dependency [OK]
Common Mistakes:
Using import or include keywords incorrectly
Forgetting to wrap module name in project()
Using add dependency which is not Gradle syntax
3. Given two modules: app and utils. If app depends on utils, what happens when you call a function defined in utils from app?
medium
A. The function runs correctly if dependency is set
B. The app crashes at runtime
C. The function is ignored during build
D. The app fails to compile
Solution
Step 1: Understand module dependency effect
If app depends on utils, app can use utils code.
Step 2: Predict behavior when calling function
Calling a function from utils works if dependency is correctly set, so function runs fine.
Final Answer:
The function runs correctly if dependency is set -> Option A
Quick Check:
Dependency set = function runs [OK]
Hint: Module dependency allows code sharing and function calls [OK]
Common Mistakes:
Assuming app crashes without error
Thinking function is ignored during build
Believing app fails to compile without error
4. You added a module dependency in app on library, but the app fails to compile with "Unresolved reference" errors for library classes. What is the most likely cause?
medium
A. The project was not synced after adding dependency
B. The library module has no Kotlin files
C. The app module is missing AndroidManifest.xml
D. The dependency was added in the wrong build.gradle file
Solution
Step 1: Identify cause of unresolved references
Unresolved references after adding dependency usually mean changes haven't taken effect in the IDE.
Step 2: Check sync status
The project must be synced after modifying build.gradle for dependencies to resolve.
Final Answer:
The project was not synced after adding dependency -> Option A
Quick Check:
No sync = unresolved references [OK]
Hint: Sync project after adding dependencies [OK]
Common Mistakes:
Adding dependency in wrong build.gradle file
Library module has no Kotlin files
App module missing AndroidManifest.xml
5. You want to create a modularized Android app with three modules: app, network, and database. The app module should use both network and database, but network should not depend on database. How should you set dependencies?
hard
A. network depends on database; app depends on network
B. app depends on network and database; network has no dependencies
C. database depends on network; app depends on database
D. app depends only on network; network depends on database
Solution
Step 1: Analyze dependency requirements
App needs both network and database modules. Network must not depend on database.
Step 2: Set dependencies accordingly
App depends on both network and database. Network has no dependencies to database.
Final Answer:
app depends on network and database; network has no dependencies -> Option B
Quick Check:
App uses both; network independent [OK]
Hint: Only app depends on both; network stays independent [OK]
Common Mistakes:
Making network depend on database incorrectly
Setting app to depend only on network
Confusing dependency directions
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.