diff --git a/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/HiltGradlePlugin.kt b/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/HiltGradlePlugin.kt index 98fa696fba8..916664ee3d8 100644 --- a/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/HiltGradlePlugin.kt +++ b/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/HiltGradlePlugin.kt @@ -353,7 +353,8 @@ class HiltGradlePlugin @Inject constructor( @Suppress("DEPRECATION") // Older variant API is deprecated it.testEnvironment.set( variant is com.android.build.gradle.api.TestVariant || - variant is com.android.build.gradle.api.UnitTestVariant + variant is com.android.build.gradle.api.UnitTestVariant || + androidExtension is com.android.build.gradle.TestExtension ) it.crossCompilationRootValidationDisabled.set( hiltExtension.disableCrossCompilationRootValidation diff --git a/javatests/artifacts/hilt-android/simple/settings.gradle b/javatests/artifacts/hilt-android/simple/settings.gradle index 9dc59db7ebd..15f0cc4ca33 100644 --- a/javatests/artifacts/hilt-android/simple/settings.gradle +++ b/javatests/artifacts/hilt-android/simple/settings.gradle @@ -5,4 +5,5 @@ include ':feature' include ':lib' include ':deep-android-lib' include ':deep-lib' -include ':earlyentrypoint' \ No newline at end of file +include ':earlyentrypoint' +include ':uitest' \ No newline at end of file diff --git a/javatests/artifacts/hilt-android/simple/uitest/build.gradle b/javatests/artifacts/hilt-android/simple/uitest/build.gradle new file mode 100644 index 00000000000..f16a376c95c --- /dev/null +++ b/javatests/artifacts/hilt-android/simple/uitest/build.gradle @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2022 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.test' +apply plugin: 'com.google.dagger.hilt.android' + +android { + compileSdkVersion 32 + buildToolsVersion "32.0.0" + + defaultConfig { + minSdkVersion 15 + targetSdkVersion 32 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "dagger.hilt.android.simple.uitest.TestRunner" + } + targetProjectPath ':app' + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } + flavorDimensions "tier" + productFlavors { + free { + dimension "tier" + } + pro { + dimension "tier" + matchingFallbacks = ["free"] + } + } +} + +hilt { + enableAggregatingTask = true +} + +dependencies { + implementation project(':app') + + implementation 'junit:junit:4.13' + implementation 'androidx.test.ext:junit:1.1.3' + implementation 'androidx.test:runner:1.4.0' + + implementation "com.google.dagger:hilt-android:$dagger_version" + implementation "com.google.dagger:hilt-android-testing:$dagger_version" + annotationProcessor "com.google.dagger:hilt-compiler:$dagger_version" +} diff --git a/javatests/artifacts/hilt-android/simple/uitest/src/main/AndroidManifest.xml b/javatests/artifacts/hilt-android/simple/uitest/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..59c530e852f --- /dev/null +++ b/javatests/artifacts/hilt-android/simple/uitest/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + diff --git a/javatests/artifacts/hilt-android/simple/uitest/src/main/java/dagger/hilt/android/simple/uitest/TestRunner.java b/javatests/artifacts/hilt-android/simple/uitest/src/main/java/dagger/hilt/android/simple/uitest/TestRunner.java new file mode 100644 index 00000000000..7c28d6641a3 --- /dev/null +++ b/javatests/artifacts/hilt-android/simple/uitest/src/main/java/dagger/hilt/android/simple/uitest/TestRunner.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2022 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.uitest; + +import android.app.Application; +import android.content.Context; +import androidx.test.runner.AndroidJUnitRunner; +import dagger.hilt.android.testing.HiltTestApplication; + +public final class TestRunner extends AndroidJUnitRunner { + @Override + public Application newApplication(ClassLoader cl, String className, Context context) + throws ClassNotFoundException, IllegalAccessException, InstantiationException { + return super.newApplication(cl, HiltTestApplication.class.getName(), context); + } +} diff --git a/javatests/artifacts/hilt-android/simple/uitest/src/main/java/dagger/hilt/android/simple/uitest/UITestOne.java b/javatests/artifacts/hilt-android/simple/uitest/src/main/java/dagger/hilt/android/simple/uitest/UITestOne.java new file mode 100644 index 00000000000..bea3ec1d367 --- /dev/null +++ b/javatests/artifacts/hilt-android/simple/uitest/src/main/java/dagger/hilt/android/simple/uitest/UITestOne.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2022 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.uitest; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import dagger.hilt.android.testing.HiltAndroidTest; +import org.junit.runner.RunWith; + +// An empty test file that validates multiple test roots in an com.android.test Gradle module. +@HiltAndroidTest +@RunWith(AndroidJUnit4.class) +public final class UITestOne { + +} \ No newline at end of file diff --git a/javatests/artifacts/hilt-android/simple/uitest/src/main/java/dagger/hilt/android/simple/uitest/UITestTwo.java b/javatests/artifacts/hilt-android/simple/uitest/src/main/java/dagger/hilt/android/simple/uitest/UITestTwo.java new file mode 100644 index 00000000000..210a7ddf773 --- /dev/null +++ b/javatests/artifacts/hilt-android/simple/uitest/src/main/java/dagger/hilt/android/simple/uitest/UITestTwo.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2022 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.uitest; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import dagger.hilt.android.testing.HiltAndroidTest; +import org.junit.runner.RunWith; + +// An empty test file that validates multiple test roots in an com.android.test Gradle module. +@HiltAndroidTest +@RunWith(AndroidJUnit4.class) +public final class UITestTwo { + +} \ No newline at end of file