-
Notifications
You must be signed in to change notification settings - Fork 6
Support Android Gradle Plugin 9.0 #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2004d9c
a7bd17b
d513825
0fc7ee0
ab69de3
a80fe07
90a3770
d055b0f
c6229a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,13 +25,15 @@ | |
|
|
||
| package dev.testify.internal | ||
|
|
||
| import com.android.build.gradle.AppExtension | ||
| import com.android.build.gradle.TestedExtension | ||
| import com.android.build.api.dsl.ApplicationExtension | ||
| import com.android.build.api.dsl.CommonExtension | ||
| import com.android.build.api.dsl.LibraryExtension | ||
| import org.gradle.api.GradleException | ||
| import org.gradle.api.Project | ||
|
|
||
| val Project.android: TestedExtension | ||
| get() = this.properties["android"] as? TestedExtension | ||
| val Project.android: CommonExtension<*, *, *, *, *, *> | ||
| get() = this.extensions.findByType(ApplicationExtension::class.java) | ||
| ?: this.extensions.findByType(LibraryExtension::class.java) | ||
| ?: throw GradleException("Gradle project must contain an `android` closure") | ||
|
|
||
| val Project.isVerbose: Boolean | ||
|
|
@@ -59,30 +61,32 @@ val Project.inferredAndroidTestInstallTask: String? | |
|
|
||
| val Project.inferredDefaultTestVariantId: String | ||
| get() { | ||
| val testVariant = this.android.testVariants.sortedBy { it.testedVariant.flavorName }.firstOrNull() | ||
| return try { | ||
| testVariant?.applicationId | ||
| } catch (e: Throwable) { | ||
| this.applicationTargetPackageId?.let { "$it.test" } ?: "" | ||
| } ?: "" | ||
| return this.applicationTargetPackageId?.let { "$it.test" } ?: "" | ||
| } | ||
|
|
||
| val Project.applicationTargetPackageId: String? | ||
| get() { | ||
| var targetPackageId: String? = null | ||
| val appExtension = this.extensions.findByType(ApplicationExtension::class.java) ?: return null | ||
| return try { | ||
| val baseApplicationId = appExtension.defaultConfig.applicationId ?: return null | ||
|
|
||
| // Prefer the debug variant | ||
| if (this.android is AppExtension) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this might be the opportunity I've been looking for to support all of the variants properly. Instead of trying to infer/guess a single task to extend, it's probably overdue that we evolve to the more modern approach. Handling onVariant and building separate tasks (as appropriate) for each variant is pretty standard in most gradle plugins and I've always felt it kind of weird for the way Testify used to insist on supporting only a single variant. I haven't really looked at your chained PR, but I'm thinking we just go with a breaking change and modify the plugin to support multiple variants
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm already pretty near the edge of my level of understanding for Gradle development, so I'm not sure I've wrapped my head around how to approach coding that. If we do want to use onVariants to support multiple variants, I think we'd want to do it starting with my stacked PR dfabulich#1 What are you imagining we'd do with this PR? Options include:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll definitely help with accomplishing this. I think the best strategy is to merge this pr, then you can open the stacked PR against main.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't mind have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, it sounds like the next step is for you to do the merge. When that happens, I'll retarget my PR. (LMK if you need anything from me.) |
||
| val appExtension = this.android as AppExtension | ||
| val allDebugVariants = appExtension.applicationVariants.filter { | ||
| it.name == "debug" || it.name.endsWith("Debug") | ||
| }.sortedBy { it.name } | ||
| targetPackageId = allDebugVariants.firstOrNull()?.applicationId | ||
| } | ||
| // Prefer debug build type suffix (most common for testing), fall back to any build type | ||
| val debugBuildType = appExtension.buildTypes.findByName("debug") | ||
| val buildType = debugBuildType ?: appExtension.buildTypes.firstOrNull() | ||
|
|
||
| // For apks without a debug variant, use the default applicationId | ||
| if (targetPackageId.isNullOrEmpty()) { | ||
| targetPackageId = this.android.defaultConfig.applicationId | ||
| val suffix = buildType?.applicationIdSuffix | ||
| if (suffix != null && suffix.isNotEmpty()) { | ||
| // Remove leading dot if present, then append with dot | ||
| val cleanSuffix = suffix.removePrefix(".") | ||
| "$baseApplicationId.$cleanSuffix" | ||
| } else { | ||
| baseApplicationId | ||
| } | ||
| } catch (e: Throwable) { | ||
| try { | ||
| appExtension.defaultConfig.applicationId | ||
| } catch (e2: Throwable) { | ||
| null | ||
| } | ||
| } | ||
| return targetPackageId | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,13 +102,23 @@ open class ScreenshotPullTask : TestifyDefaultTask() { | |
| private fun String.toLocalPath(): String { | ||
| val src = screenshotDirectory | ||
| val dst = destinationImageDirectory | ||
| val dstFile = if (File(dst).isAbsolute) { | ||
| File(dst) | ||
| } else { | ||
| File(project.projectDir, dst) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tracked down the configuration break to this line. In order to support gradle configuration caching, the |
||
| } | ||
| val key = this.removePrefix("$src/").replace('/', File.separatorChar) | ||
| return "$dst${File.separatorChar}$SCREENSHOT_DIR${File.separatorChar}$key" | ||
| return File(dstFile, "$SCREENSHOT_DIR${File.separatorChar}$key").path | ||
| } | ||
|
|
||
| private fun pullScreenshots() { | ||
| val dst = destinationImageDirectory | ||
| File(dst).assurePath() | ||
| val dstFile = if (File(dst).isAbsolute) { | ||
| File(dst) | ||
| } else { | ||
| File(project.projectDir, dst) | ||
| } | ||
| dstFile.assurePath() | ||
|
|
||
| val failedScreenshots = listFailedScreenshotsWithPath( | ||
| src = screenshotDirectory, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was verifying the changes and found that Plugin:test is failing when run against an emulator. I noticed that the CI verification fails to launch an emulator and so is an incomplete test. This allows for CI to pass, but hides a problem.
The
ConfigurationCacheTestfails for all but the first test with the error:It seems like the adbPathProvider is capturing a stale
projectand breaking the configuration cache.I'll try to fix it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a fix here (#274) but I need your changes on
mainbefore I can open my PR. So, I'm going to approve and merge your changes.