forked from square/dagger
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RELNOTES=N/A PiperOrigin-RevId: 417294644
- Loading branch information
Showing
5 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
javatests/artifacts/hilt-android/simple/app-java-only/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (C) 2021 The Dagger Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
apply plugin: 'com.android.application' | ||
apply plugin: 'dagger.hilt.android.plugin' | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.2" | ||
|
||
defaultConfig { | ||
applicationId "dagger.hilt.android.simple" | ||
minSdkVersion 15 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
compileOptions { | ||
sourceCompatibility 1.8 | ||
targetCompatibility 1.8 | ||
} | ||
testOptions { | ||
unitTests.includeAndroidResources = true | ||
} | ||
lintOptions { | ||
checkReleaseBuilds = false | ||
} | ||
} | ||
|
||
hilt { | ||
enableTransformForLocalTests = true | ||
enableAggregatingTask = true | ||
} | ||
|
||
configurations.all { | ||
resolutionStrategy.eachDependency { DependencyResolveDetails details -> | ||
if ("$dagger_version" == 'LOCAL-SNAPSHOT' | ||
&& details.requested.group == 'com.google.dagger') { | ||
details.useVersion 'LOCAL-SNAPSHOT' | ||
details.because 'LOCAL-SNAPSHOT should act as latest version.' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation "com.google.dagger:hilt-android:$dagger_version" | ||
annotationProcessor "com.google.dagger:hilt-compiler:$dagger_version" | ||
|
||
androidTestImplementation 'com.google.truth:truth:1.0.1' | ||
androidTestImplementation 'junit:junit:4.13' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
androidTestImplementation 'androidx.test:runner:1.3.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
androidTestImplementation "com.google.dagger:hilt-android-testing:$dagger_version" | ||
androidTestAnnotationProcessor "com.google.dagger:hilt-compiler:$dagger_version" | ||
} |
39 changes: 39 additions & 0 deletions
39
...droid/simple/app-java-only/src/androidTest/java/dagger/hilt/android/simple/BuildTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2021 The Dagger Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dagger.hilt.android.simple; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import androidx.test.core.app.ApplicationProvider; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Regression test for https://github.com/google/dagger/issues/3119 | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class BuildTest { | ||
@Test | ||
public void useAppContext() { | ||
assertThat((Object) ApplicationProvider.getApplicationContext()) | ||
.isInstanceOf(SimpleApplication.class); | ||
SimpleApplication app = (SimpleApplication) ApplicationProvider.getApplicationContext(); | ||
assertThat(app.str).isNotNull(); | ||
assertThat(app.str).isEqualTo(app.entryPointStr); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
javatests/artifacts/hilt-android/simple/app-java-only/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!-- | ||
~ Copyright (C) 2020 The Dagger Authors. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="dagger.hilt.android.simple"> | ||
|
||
<application android:name=".SimpleApplication" android:label="Java-only Hilt Android"> | ||
</application> | ||
</manifest> |
58 changes: 58 additions & 0 deletions
58
...roid/simple/app-java-only/src/main/java/dagger/hilt/android/simple/SimpleApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) 2020 The Dagger Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dagger.hilt.android.simple; | ||
|
||
import android.app.Application; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
import dagger.hilt.EntryPoint; | ||
import dagger.hilt.InstallIn; | ||
import dagger.hilt.android.EntryPointAccessors; | ||
import dagger.hilt.android.HiltAndroidApp; | ||
import dagger.hilt.components.SingletonComponent; | ||
import javax.inject.Inject; | ||
|
||
/** | ||
* A simple, skeletal application that demonstrates a dependency-injected application using the | ||
* utilities in {@code Hilt} in Android. | ||
*/ | ||
@HiltAndroidApp | ||
public class SimpleApplication extends Application { | ||
@EntryPoint | ||
@InstallIn(SingletonComponent.class) | ||
interface MyEntryPoint { | ||
String getString(); | ||
} | ||
|
||
@Module | ||
@InstallIn(SingletonComponent.class) | ||
interface MyModule { | ||
@Provides | ||
static String provideString() { | ||
return "blah"; | ||
} | ||
} | ||
|
||
@Inject String str; | ||
String entryPointStr; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
entryPointStr = EntryPointAccessors.fromApplication(this, MyEntryPoint.class).getString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters