Skip to content

Commit 2a9cf33

Browse files
committed
Project Init
1 parent c6420dc commit 2a9cf33

File tree

14 files changed

+139
-16
lines changed

14 files changed

+139
-16
lines changed

README.md

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
# Dagger Multi-Module Android
2-
Learn to use dagger for dependency management in a multi-module app
1+
# Dagger Dynamic Feature Module Android
2+
Learn to use dagger for dependency management in a dynamic feature module app
33

44
[![MindOrks](https://img.shields.io/badge/mindorks-opensource-blue.svg)](https://mindorks.com/open-source-projects)
55
[![MindOrks Community](https://img.shields.io/badge/join-community-blue.svg)](https://mindorks.com/join-community)
66

77
<p align="center">
8-
<img src="https://raw.githubusercontent.com/MindorksOpenSource/Dagger-Multi-Module-Android/master/art/dagger-github.png">
8+
<img src="https://s3.ap-south-1.amazonaws.com/mindorks-server-uploads/dynamic-feature-module-banner-f27f94e8e526888d.png">
99
</p>
1010

1111
## About this Open Source Project
12-
This open-source project is for you(community). In this project you will learn about how to use dagger for dependency management in a multi-module app.
13-
### [You can find the blog to learn about Using Dagger in Multi-Module Architecture here](https://blog.mindorks.com/dagger-in-a-multi-module-project)
14-
## Project Structure
15-
<p align="start">
16-
<img src="https://raw.githubusercontent.com/MindorksOpenSource/Dagger-Multi-Module-Android/master/art/project-structure.png">
17-
<img src="https://s3.ap-south-1.amazonaws.com/mindorks-server-uploads/feature-dependenct-base-d29d996b697942a8.jpg">
18-
</p>
12+
This open-source project is for you(community). In this project you will learn about how to use dagger for dependency management in a multi-module app using dynamic feature module.
1913

2014
## Explore Android Online Tutorials and Courses To Learn More by MindOrks
2115
* [Android Tutorial](https://mindorks.com/android-tutorial) - All Free Android Tutorials by MindOrks

app/build.gradle

+6-4
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ android {
2424
}
2525
}
2626

27+
dynamicFeatures = [":featureThree"]
2728
}
2829

2930
dependencies {
3031
implementation fileTree(dir: 'libs', include: ['*.jar'])
3132
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
32-
implementation 'androidx.appcompat:appcompat:1.1.0'
33-
implementation 'androidx.core:core-ktx:1.2.0'
34-
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
33+
api 'androidx.appcompat:appcompat:1.1.0'
34+
api 'androidx.core:core-ktx:1.2.0'
35+
api 'androidx.constraintlayout:constraintlayout:1.1.3'
3536

36-
implementation "com.google.dagger:dagger:2.27"
37+
api "com.google.dagger:dagger:2.27"
3738
kapt "com.google.dagger:dagger-compiler:2.27"
3839

3940
implementation project(':base')
@@ -43,4 +44,5 @@ dependencies {
4344
testImplementation 'junit:junit:4.12'
4445
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
4546
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
47+
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4648
}

app/src/main/java/com/mindorks/dagger/multi/module/main/MainActivity.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ class MainActivity : AppCompatActivity() {
3030
.build()
3131
.inject(this)
3232
Log.d("DaggerSample_Main", databaseService.toString())
33-
startActivity(Intent(this,FeatureOneActivity::class.java))
33+
// startActivity(Intent(this,FeatureOneActivity::class.java))
3434

35+
val intent = Intent().setClassName(this, "com.mindorks.sample.feature.three.FeatureThreeActivity")
36+
startActivity(intent)
3537
}
38+
39+
3640
}

app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<resources>
22
<string name="app_name">Dagger-Multi-Module-Android-Example</string>
3+
<string name="title_feature_three">feature-three</string>
34
</resources>

feature-one/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ dependencies {
3232
implementation 'androidx.appcompat:appcompat:1.1.0'
3333
implementation 'androidx.core:core-ktx:1.2.0'
3434
implementation "com.google.dagger:dagger:2.27"
35-
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
3635
kapt "com.google.dagger:dagger-compiler:2.27"
36+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
3737
implementation project(':base')
3838
testImplementation 'junit:junit:4.12'
3939
androidTestImplementation 'androidx.test.ext:junit:1.1.1'

featureThree/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

featureThree/build.gradle

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apply plugin: 'com.android.dynamic-feature'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
4+
apply plugin: 'kotlin-kapt'
5+
6+
android {
7+
compileSdkVersion 29
8+
9+
10+
defaultConfig {
11+
minSdkVersion 21
12+
targetSdkVersion 29
13+
versionCode 1
14+
versionName "1.0"
15+
16+
}
17+
18+
19+
}
20+
21+
dependencies {
22+
implementation fileTree(dir: 'libs', include: ['*.jar'])
23+
implementation project(':app')
24+
implementation project(':base')
25+
implementation "com.google.dagger:dagger:2.27"
26+
kapt "com.google.dagger:dagger-compiler:2.27"
27+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:dist="http://schemas.android.com/apk/distribution"
4+
package="com.mindorks.sample.feature.three">
5+
6+
<dist:module
7+
dist:instant="false"
8+
dist:title="@string/title_feature_three">
9+
<dist:delivery>
10+
<dist:on-demand />
11+
</dist:delivery>
12+
13+
<dist:fusing dist:include="true" />
14+
</dist:module>
15+
16+
<application>
17+
<activity android:name=".FeatureThreeActivity" />
18+
</application>
19+
20+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.mindorks.sample.feature.three
2+
3+
import androidx.appcompat.app.AppCompatActivity
4+
import android.os.Bundle
5+
import android.util.Log
6+
import com.mindorks.dagger.multi.module.base.data.DatabaseService
7+
import com.mindorks.dagger.multi.module.base.data.NetworkService
8+
import com.mindorks.dagger.multi.module.base.utils.InjectUtils
9+
import com.mindorks.sample.feature.three.di.component.DaggerFeatureThreeComponent
10+
import javax.inject.Inject
11+
12+
class FeatureThreeActivity : AppCompatActivity() {
13+
14+
@Inject
15+
lateinit var databaseService: DatabaseService
16+
17+
@Inject
18+
lateinit var networkService: NetworkService
19+
20+
override fun onCreate(savedInstanceState: Bundle?) {
21+
super.onCreate(savedInstanceState)
22+
setContentView(R.layout.activity_feature_three)
23+
24+
DaggerFeatureThreeComponent
25+
.builder()
26+
.baseComponent(InjectUtils.provideBaseComponent(applicationContext))
27+
.build()
28+
.inject(this)
29+
30+
Log.d("DaggerSample_Feature3", databaseService.toString())
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.mindorks.sample.feature.three.di.component
2+
3+
import com.mindorks.dagger.multi.module.base.di.component.BaseComponent
4+
import com.mindorks.sample.feature.three.FeatureThreeActivity
5+
import com.mindorks.sample.feature.three.di.module.FeatureThreeModule
6+
import com.mindorks.sample.feature.three.di.scopes.FeatureThreeScope
7+
import dagger.Component
8+
9+
@FeatureThreeScope
10+
@Component(
11+
dependencies = [BaseComponent::class],
12+
modules = [FeatureThreeModule::class]
13+
)
14+
interface FeatureThreeComponent {
15+
16+
fun inject(activity: FeatureThreeActivity)
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.mindorks.sample.feature.three.di.module
2+
3+
import dagger.Module
4+
5+
@Module
6+
class FeatureThreeModule {
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.mindorks.sample.feature.three.di.scopes
2+
3+
import javax.inject.Scope
4+
5+
@Scope
6+
@Retention(AnnotationRetention.SOURCE)
7+
annotation class FeatureThreeScope
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context="com.mindorks.sample.feature.three.FeatureThreeActivity">
8+
9+
</androidx.constraintlayout.widget.ConstraintLayout>

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ include ':app'
33
include ':base'
44
include ':feature-one'
55
include ':feature-two'
6+
include ':featureThree'

0 commit comments

Comments
 (0)