Skip to content

Commit

Permalink
Add workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrovgs committed Aug 5, 2021
1 parent 1f34784 commit 8b1f97b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
- name: Execute screenshot tests for shot-consumer-flavors blue flavor
run: ./gradlew blueCustomBuildTypeExecuteScreenshotTests
working-directory: shot-consumer-flavors
- name: Execute screenshot tests for shot-consumer-compose
run: ./gradlew executeScreenshotTests
working-directory: shot-consumer-library
- uses: actions/upload-artifact@v2
if: always()
with:
Expand Down
2 changes: 1 addition & 1 deletion shot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
implementation gradleApi()
implementation localGroovy()
implementation project(':core')
compileOnly 'com.android.tools.build:gradle:7.1.0-alpha05'
compileOnly 'com.android.tools.build:gradle:7.1.0-alpha06'
implementation 'org.scala-lang:scala-library:2.12.13'

testImplementation 'org.scalatest:scalatest_2.12:3.2.6'
Expand Down
5 changes: 3 additions & 2 deletions shot/src/main/scala/com/karumi/shot/ShotExtension.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class ShotExtension(
@BeanProperty var runInstrumentation: Boolean,
@BeanProperty var useComposer: Boolean,
@BeanProperty var tolerance: Double,
@BeanProperty var showOnlyFailingTestsInReports: Boolean
@BeanProperty var showOnlyFailingTestsInReports: Boolean,
@BeanProperty var applicationId: String
) {

def this() = this(true, false, Config.defaultTolerance, false)
def this() = this(true, false, Config.defaultTolerance, false, "")

}
19 changes: 16 additions & 3 deletions shot/src/main/scala/com/karumi/shot/ShotPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,27 @@ class ShotPlugin extends Plugin[Project] {
) = {
val flavor = variant.getMergedFlavor
checkIfApplicationIdIsConfigured(project, flavor)
val completeAppId = composeCompleteAppId(variant)
val completeAppId = composeCompleteAppId(project, variant)
val appTestId =
Option(flavor.getTestApplicationId).getOrElse(completeAppId)
addTasksFor(project, variant.getFlavorName, variant.getBuildType, appTestId, baseTask)
}

private def composeCompleteAppId(variant: BaseVariant) =
variant.getApplicationId + ".test"
private def composeCompleteAppId(project: Project, variant: BaseVariant): String = {
val appId = try {
variant.getApplicationId
} catch {
case _: Throwable =>
console.showWarning("Error found trying to get applicationId from library module. We will use the extension applicationId param as a workaround.")
console.showWarning("More information about this AGP7.0.1 bug can be found here: https://github.com/Karumi/Shot/issues/247")
val extension = project.getExtensions.getByType[ShotExtension](classOf[ShotExtension])
val extensionAppIdValue = extension.applicationId
console.showWarning(s"Extension applicationId value read = $extensionAppIdValue")
extensionAppIdValue
}
appId + ".test"
}


private def checkIfApplicationIdIsConfigured(project: Project, flavor: ProductFlavor) =
if (isAnAndroidLibrary(project) && flavor.getTestApplicationId == null) {
Expand Down

0 comments on commit 8b1f97b

Please sign in to comment.