Skip to content

Commit

Permalink
Set Hilt's aggregating task test environment flag when configuring th…
Browse files Browse the repository at this point in the history
…e task for a com.android.test Gradle module.

Fixes: #3478
RELNOTES=Fix an issue in Hilt's Gradle Plugin not configuring the aggregating task correctly on a com.android.test Gradle module.
PiperOrigin-RevId: 463330712
  • Loading branch information
danysantiago authored and Dagger Team committed Jul 26, 2022
1 parent 90300d9 commit bbaa178
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 2 deletions.
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion javatests/artifacts/hilt-android/simple/settings.gradle
Expand Up @@ -5,4 +5,5 @@ include ':feature'
include ':lib'
include ':deep-android-lib'
include ':deep-lib'
include ':earlyentrypoint'
include ':earlyentrypoint'
include ':uitest'
58 changes: 58 additions & 0 deletions javatests/artifacts/hilt-android/simple/uitest/build.gradle
@@ -0,0 +1,58 @@
/*
* 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 "com.google.dagger:hilt-android:$dagger_version"
implementation "com.google.dagger:hilt-android-testing:$dagger_version"
annotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"
}
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dagger.hilt.android.simple.uitest">
</manifest>
@@ -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);
}
}
@@ -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 {

}
@@ -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 {

}

0 comments on commit bbaa178

Please sign in to comment.