Skip to content

Commit 57a439b

Browse files
danysantiagoDagger Team
authored andcommitted
Add hilt-android to the Gradle projects
Also consolodiate and move proguard files to resources directories. RELNOTES=N/A PiperOrigin-RevId: 794732656
1 parent 59ac2f9 commit 57a439b

File tree

15 files changed

+684
-20
lines changed

15 files changed

+684
-20
lines changed

gradle/libs.versions.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ androidMinSdk = "21"
55
autoFactory = "1.0"
66
autoService = "1.0"
77
autoValue = "1.9"
8+
lifecycle = "2.5.1"
89
lint = "30.3.1"
910
guava = "33.0.0-jre"
1011
gradleIncap = "0.2"
@@ -24,6 +25,9 @@ androidx-annotations = { module = "androidx.annotation:annotation", version = "1
2425
androidx-activity = { module = "androidx.activity:activity", version = "1.5.1" }
2526
androidx-appcompat = { module = "androidx.appcompat:appcompat", version = "1.3.1" }
2627
androidx-fragment = { module = "androidx.fragment:fragment", version = "1.5.1" }
28+
androidx-lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel", version.ref = "lifecycle" }
29+
androidx-lifecycle-viewmodel-savedstate = { module = "androidx.lifecycle:lifecycle-viewmodel-savedstate", version.ref = "lifecycle" }
30+
androidx-savedstate = { module = "androidx.savedstate:savedstate", version = "1.2.0" }
2731
androidx-lint = { module = "androidx.lint:lint-gradle", version = "1.0.0-alpha04" }
2832
androidx-test-ext-junit = { module = "androidx.test.ext:junit", version = "1.2.1" }
2933
auto-common = { module = "com.google.auto:auto-common", version = "1.2.1" }

hilt-android/BUILD

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ gen_maven_artifact(
139139
manifest = "AndroidManifest.xml",
140140
packaging = "aar",
141141
proguard_and_r8_specs = [
142-
"//hilt-core/main/java/dagger/hilt:proguard-rules.pro",
143-
"//hilt-android/main/java/dagger/hilt/android:proguard-rules.pro",
144-
"//hilt-android/main/java/dagger/hilt/internal:proguard-rules.pro",
142+
"//hilt-core/main/resources:proguard",
143+
"//hilt-android/main/resources:proguard",
145144
],
146145
)

hilt-android/api/hilt-android.api

Lines changed: 562 additions & 0 deletions
Large diffs are not rendered by default.

hilt-android/build.gradle.kts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import dagger.gradle.build.SoftwareType
2+
import dagger.gradle.build.findXProcessingJar
3+
4+
plugins {
5+
alias(libs.plugins.daggerBuild)
6+
id(libs.plugins.android.library.get().pluginId)
7+
id(libs.plugins.kotlinAndroid.get().pluginId)
8+
id(libs.plugins.binaryCompatibilityValidator.get().pluginId)
9+
}
10+
11+
dependencies {
12+
api(project(":dagger"))
13+
implementation(project(":dagger-lint-aar"))
14+
api(project(":hilt-core"))
15+
16+
api(libs.androidx.activity)
17+
api(libs.androidx.annotations)
18+
api(libs.androidx.fragment)
19+
api(libs.androidx.lifecycle.viewmodel)
20+
api(libs.androidx.lifecycle.viewmodel.savedstate)
21+
api(libs.androidx.savedstate)
22+
implementation(libs.findBugs)
23+
implementation(libs.kotlin.stdlib)
24+
25+
annotationProcessor(project(":dagger-compiler", "unshaded"))
26+
annotationProcessor(project(":hilt-compiler", "unshaded"))
27+
annotationProcessor(libs.auto.common)
28+
annotationProcessor(files(project.findXProcessingJar()))
29+
}
30+
31+
android {
32+
buildTypes {
33+
defaultConfig {
34+
proguardFiles("$projectDir/main/resources/META-INF/com.android.tools/r8/dagger-android.pro")
35+
}
36+
}
37+
}
38+
39+
daggerBuild {
40+
type = SoftwareType.ANDROID_LIBRARY
41+
isPublished = true
42+
}
43+
44+
android { namespace = "dagger.android" }
45+
46+
kotlin { explicitApi() }

hilt-android/main/java/dagger/hilt/android/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ android_library(
124124
"//hilt-compiler/main/java/dagger/hilt/processor/internal/aggregateddeps:plugin",
125125
"//hilt-compiler/main/java/dagger/hilt/processor/internal/earlyentrypoint:processor",
126126
],
127-
proguard_specs = ["proguard-rules.pro"],
127+
proguard_specs = ["//hilt-android/main/resources:proguard"],
128128
exports = [
129129
"//hilt-android/main/java/dagger/hilt/android/internal/earlyentrypoint",
130130
],

hilt-android/main/java/dagger/hilt/android/EntryPointAccessors.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,65 +24,65 @@ import dagger.hilt.EntryPoints
2424
import dagger.hilt.android.internal.Contexts
2525

2626
/** Utility functions for dealing with entry points for standard Android components. */
27-
object EntryPointAccessors {
27+
public object EntryPointAccessors {
2828
/**
2929
* Returns the entry point interface from an application. The context can be any context derived
3030
* from the application context. May only be used with entry point interfaces installed in the
3131
* SingletonComponent.
3232
*/
3333
@JvmStatic
34-
fun <T> fromApplication(context: Context, entryPoint: Class<T>): T =
34+
public fun <T> fromApplication(context: Context, entryPoint: Class<T>): T =
3535
EntryPoints.get(Contexts.getApplication(context.applicationContext), entryPoint)
3636

3737
/**
3838
* Returns the entry point interface from an application. The context can be any context derived
3939
* from the application context. May only be used with entry point interfaces installed in the
4040
* SingletonComponent.
4141
*/
42-
inline fun <reified T> fromApplication(context: Context): T =
42+
public inline fun <reified T> fromApplication(context: Context): T =
4343
fromApplication(context, T::class.java)
4444

4545
/**
4646
* Returns the entry point interface from an activity. May only be used with entry point
4747
* interfaces installed in the ActivityComponent.
4848
*/
4949
@JvmStatic
50-
fun <T> fromActivity(activity: Activity, entryPoint: Class<T>): T =
50+
public fun <T> fromActivity(activity: Activity, entryPoint: Class<T>): T =
5151
EntryPoints.get(activity, entryPoint)
5252

5353
/**
5454
* Returns the entry point interface from an activity. May only be used with entry point
5555
* interfaces installed in the ActivityComponent.
5656
*/
57-
inline fun <reified T> fromActivity(activity: Activity): T =
57+
public inline fun <reified T> fromActivity(activity: Activity): T =
5858
fromActivity(activity, T::class.java)
5959

6060
/**
6161
* Returns the entry point interface from a fragment. May only be used with entry point interfaces
6262
* installed in the FragmentComponent.
6363
*/
6464
@JvmStatic
65-
fun <T> fromFragment(fragment: Fragment, entryPoint: Class<T>): T =
65+
public fun <T> fromFragment(fragment: Fragment, entryPoint: Class<T>): T =
6666
EntryPoints.get(fragment, entryPoint)
6767

6868
/**
6969
* Returns the entry point interface from a fragment. May only be used with entry point interfaces
7070
* installed in the FragmentComponent.
7171
*/
72-
inline fun <reified T> fromFragment(fragment: Fragment): T =
72+
public inline fun <reified T> fromFragment(fragment: Fragment): T =
7373
fromFragment(fragment, T::class.java)
7474

7575
/**
7676
* Returns the entry point interface from a view. May only be used with entry point interfaces
7777
* installed in the ViewComponent or ViewNoFragmentComponent.
7878
*/
7979
@JvmStatic
80-
fun <T> fromView(view: View, entryPoint: Class<T>): T = EntryPoints.get(view, entryPoint)
80+
public fun <T> fromView(view: View, entryPoint: Class<T>): T = EntryPoints.get(view, entryPoint)
8181

8282
/**
8383
* Returns the entry point interface from a view. May only be used with entry point interfaces
8484
* installed in the ViewComponent or ViewNoFragmentComponent.
8585
*/
86-
inline fun <reified T> fromView(view: View): T =
86+
public inline fun <reified T> fromView(view: View): T =
8787
fromView(view, T::class.java)
8888
}

hilt-android/main/java/dagger/hilt/android/lifecycle/HiltViewModelExtensions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import dagger.hilt.android.internal.lifecycle.HiltViewModelFactory
3131
* @param callback A creation callback that takes an assisted factory and returns a {@code
3232
* ViewModel}.
3333
*/
34-
fun <VMF> CreationExtras.withCreationCallback(callback: (VMF) -> ViewModel): CreationExtras =
34+
public fun <VMF> CreationExtras.withCreationCallback(callback: (VMF) -> ViewModel): CreationExtras =
3535
MutableCreationExtras(this).addCreationCallback(callback)
3636

3737
/**
@@ -42,7 +42,7 @@ fun <VMF> CreationExtras.withCreationCallback(callback: (VMF) -> ViewModel): Cre
4242
* ViewModel}.
4343
*/
4444
@Suppress("UNCHECKED_CAST")
45-
fun <VMF> MutableCreationExtras.addCreationCallback(callback: (VMF) -> ViewModel): CreationExtras =
45+
public fun <VMF> MutableCreationExtras.addCreationCallback(callback: (VMF) -> ViewModel): CreationExtras =
4646
this.apply {
4747
this[HiltViewModelFactory.CREATION_CALLBACK_KEY] = { factory -> callback(factory as VMF) }
4848
}

hilt-android/main/java/dagger/hilt/internal/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ java_library(
2828
java_library(
2929
name = "component_entry_point",
3030
srcs = ["ComponentEntryPoint.java"],
31-
proguard_specs = ["proguard-rules.pro"],
31+
proguard_specs = ["//hilt-android/main/resources:proguard"],
3232
deps = ["//hilt-core/main/java/dagger/hilt:generates_root_input"],
3333
)
3434

3535
java_library(
3636
name = "generated_entry_point",
3737
srcs = ["GeneratedEntryPoint.java"],
38-
proguard_specs = ["proguard-rules.pro"],
38+
proguard_specs = ["//hilt-android/main/resources:proguard"],
3939
deps = ["//hilt-core/main/java/dagger/hilt:generates_root_input"],
4040
)
4141

hilt-android/main/resources/BUILD

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (C) 2025 The Dagger Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
package(default_visibility = ["//:src"])
16+
17+
filegroup(
18+
name = "proguard",
19+
srcs = ["META-INF/com.android.tools/proguard/hilt-android.pro"],
20+
)
21+
22+
filegroup(
23+
name = "r8",
24+
srcs = ["META-INF/com.android.tools/r8/hilt-android.pro"],
25+
)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Keep for the reflective cast done in EntryPoints.
22
# See b/183070411#comment4 for more info.
33
-keep,allowobfuscation,allowshrinking @dagger.hilt.internal.ComponentEntryPoint class *
4-
-keep,allowobfuscation,allowshrinking @dagger.hilt.internal.GeneratedEntryPoint class *
4+
-keep,allowobfuscation,allowshrinking @dagger.hilt.internal.GeneratedEntryPoint class *
5+
-keep,allowobfuscation,allowshrinking @dagger.hilt.android.EarlyEntryPoint class *

0 commit comments

Comments
 (0)