diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index b01c00b1..7944816c 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -65,7 +65,7 @@ jobs: uses: usefulness/agp-version-finder-action@v1 - id: build-agp-matrix - run: echo '::set-output name=agp-versions::["${{ steps.agp-version-finder.outputs.latest-stable }}", "${{ steps.agp-version-finder.outputs.latest-alpha }}"]' + run: echo '::set-output name=agp-versions::["${{ steps.agp-version-finder.outputs.latest-stable }}","${{ steps.agp-version-finder.outputs.latest-beta }}", "${{ steps.agp-version-finder.outputs.latest-alpha }}"]' build-all-sample-apps: runs-on: ubuntu-latest @@ -108,7 +108,7 @@ jobs: gradle-version: ${{ matrix.gradle }} arguments: assemble lint -PuseMavenLocal -PagpVersion=${{ matrix.agp }} - build-sample-apps-with-confgiuration-cache: + build-sample-apps-with-configuration-cache: runs-on: ${{ matrix.os }} name: Configuration Cache Java-${{ matrix.javaVersion }} OS-${{ matrix.os }} strategy: diff --git a/easylauncher/src/main/kotlin/com/project/starter/easylauncher/plugin/AgpUtils.kt b/easylauncher/src/main/kotlin/com/project/starter/easylauncher/plugin/AgpUtils.kt index a43d2091..761a836b 100644 --- a/easylauncher/src/main/kotlin/com/project/starter/easylauncher/plugin/AgpUtils.kt +++ b/easylauncher/src/main/kotlin/com/project/starter/easylauncher/plugin/AgpUtils.kt @@ -2,6 +2,7 @@ package com.project.starter.easylauncher.plugin import com.android.build.api.component.analytics.AnalyticsEnabledApplicationVariant import com.android.build.api.dsl.AndroidSourceDirectorySet +import com.android.build.api.dsl.AndroidSourceFile import com.android.build.api.variant.Variant import com.android.build.gradle.internal.component.ComponentCreationConfig import org.gradle.api.model.ObjectFactory @@ -34,3 +35,7 @@ internal val Variant.isDebuggable: Boolean @Suppress("DEPRECATION") // https://issuetracker.google.com/issues/170650362 internal val AndroidSourceDirectorySet.srcDirs get() = (this as? com.android.build.gradle.api.AndroidSourceDirectorySet)?.srcDirs.orEmpty() + +@Suppress("DEPRECATION") // https://issuetracker.google.com/issues/235266670 +internal val AndroidSourceFile.srcFile + get() = (this as? com.android.build.gradle.api.AndroidSourceFile)?.srcFile diff --git a/easylauncher/src/main/kotlin/com/project/starter/easylauncher/plugin/EasyLauncherPlugin.kt b/easylauncher/src/main/kotlin/com/project/starter/easylauncher/plugin/EasyLauncherPlugin.kt index ca417072..e26127b6 100644 --- a/easylauncher/src/main/kotlin/com/project/starter/easylauncher/plugin/EasyLauncherPlugin.kt +++ b/easylauncher/src/main/kotlin/com/project/starter/easylauncher/plugin/EasyLauncherPlugin.kt @@ -1,12 +1,11 @@ package com.project.starter.easylauncher.plugin +import com.android.build.api.AndroidPluginVersion import com.android.build.api.variant.AndroidComponentsExtension import com.android.build.api.variant.Variant -import com.android.build.gradle.internal.api.DefaultAndroidSourceFile -import com.android.build.gradle.internal.scope.InternalArtifactType +import com.android.build.gradle.BaseExtension import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.configurationcache.extensions.capitalized import java.io.File @Suppress("UnstableApiUsage") @@ -25,7 +24,7 @@ class EasyLauncherPlugin : Plugin { androidComponents.finalizeDsl { common -> common.sourceSets - .mapNotNull { sourceSet -> (sourceSet.manifest as? DefaultAndroidSourceFile)?.srcFile?.let { sourceSet.name to it } } + .mapNotNull { sourceSet -> sourceSet.manifest.srcFile?.let { sourceSet.name to it } } .forEach { manifestBySourceSet[it.first] = it.second } common.sourceSets @@ -95,7 +94,8 @@ class EasyLauncherPlugin : Plugin { } .flatten() - val task = project.tasks.register("easylauncher${variant.name.capitalized()}", EasyLauncherTask::class.java) { + val capitalisedVariantName = variant.name.replaceFirstChar(Char::titlecase) + val task = project.tasks.register("easylauncher$capitalisedVariantName", EasyLauncherTask::class.java) { it.manifestFiles.set(manifests) it.manifestPlaceholders.set(variant.manifestPlaceholders) it.resourceDirectories.set(resSourceDirectories) @@ -104,11 +104,27 @@ class EasyLauncherPlugin : Plugin { it.minSdkVersion.set(variant.minSdkVersion.apiLevel) } - variant - .artifacts - .use(task) - .wiredWith(EasyLauncherTask::outputDir) - .toCreate(InternalArtifactType.GENERATED_RES) + val apgVersion = androidComponents.pluginVersion + if (apgVersion >= AndroidPluginVersion(7, 4).beta(2)) { + // proper solution, unavailable in 7.3. https://issuetracker.google.com/issues/237303854 + variant.sources.res?.addGeneratedSourceDirectory(task, EasyLauncherTask::outputDir) + } else if (apgVersion >= AndroidPluginVersion(7, 3).alpha(1)) { + // has side-effects, but "works". @see: https://github.com/usefulness/easylauncher-gradle-plugin/issues/382 + variant + .artifacts + .use(task) + .wiredWith(EasyLauncherTask::outputDir) + .toCreate(com.android.build.gradle.internal.scope.InternalArtifactType.GENERATED_RES) + } else { + // legacy way to hook up the plugin + val generatedResDir = buildDir.resolve("generated/easylauncher/res/${variant.name}") + task.configure { it.outputDir.set(generatedResDir) } + project.afterEvaluate { + val android = extensions.getByName("android") as BaseExtension + android.sourceSets.getByName(variant.name).res.srcDir(generatedResDir) + tasks.named("generate${capitalisedVariantName}Resources") { it.dependsOn(task) } + } + } } } else { log.info { "disabled for ${variant.name}" } diff --git a/easylauncher/src/main/kotlin/com/project/starter/easylauncher/plugin/log.kt b/easylauncher/src/main/kotlin/com/project/starter/easylauncher/plugin/log.kt index 4e99127b..c9f98056 100644 --- a/easylauncher/src/main/kotlin/com/project/starter/easylauncher/plugin/log.kt +++ b/easylauncher/src/main/kotlin/com/project/starter/easylauncher/plugin/log.kt @@ -10,7 +10,7 @@ internal object log { fun info(message: () -> String) { if (logger.isInfoEnabled) { - logger.debug("[$TAG] $message") + logger.info("[$TAG] ${message()}") } } } diff --git a/sample/build.gradle b/sample/build.gradle index fa4de268..79558a5b 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -86,7 +86,7 @@ subprojects { // https://github.com/usefulness/easylauncher-gradle-plugin/issues/114 disable("IconLauncherShape") - if (agpVersion.contains("alpha")) { + if (agpVersion.contains("alpha") || agpVersion.contains("beta")) { disable("MonochromeLauncherIcon") } @@ -174,7 +174,7 @@ subprojects { // https://github.com/usefulness/easylauncher-gradle-plugin/issues/114 disable("IconLauncherShape") - if (agpVersion.contains("alpha")) { + if (agpVersion.contains("alpha") || agpVersion.contains("beta")) { disable("MonochromeLauncherIcon") } diff --git a/sample/example-vector/build.gradle b/sample/example-vector/build.gradle index 3b8a14ea..e4cca375 100644 --- a/sample/example-vector/build.gradle +++ b/sample/example-vector/build.gradle @@ -1,3 +1,7 @@ +import com.android.build.api.variant.ResValue +import com.android.build.api.AndroidPluginVersion +import kotlin.Pair + apply plugin: 'com.starter.application.android' apply plugin: 'com.starter.easylauncher' @@ -49,6 +53,35 @@ android { register("allFilters") { dimension "reportedBugs" } + register("usingResValues") { + dimension "reportedBugs" + } + } +} + + +androidComponents { + if (pluginVersion >= new AndroidPluginVersion(7, 3).alpha(1) && pluginVersion < new AndroidPluginVersion(7, 4).beta(2)) { + tasks.register("agpHasBugs") { + def resourcesFile = file("src/usingResValues/res/values/generated_strings.xml") + + doLast { + resourcesFile.parentFile.mkdirs() + resourcesFile.write(""" + + New AGP apis are broken + +""") + } + } + tasks.withType(com.android.build.gradle.tasks.GenerateResValues).configureEach { + dependsOn("agpHasBugs") + } + } else { + onVariants(selector().withFlavor(new Pair("reportedBugs", "usingResValues"))) { variant -> + def value = new ResValue(variant.applicationId.get(), "Covers https://github.com/usefulness/easylauncher-gradle-plugin/issues/382") + variant.resValues.put(variant.makeResValueKey("string", "generated_key"), value) + } } } @@ -103,5 +136,8 @@ easylauncher { chromeLike(label: "aaa"), overlayFilter(file("launcherOverlay/beta.png")) } + usingResValues { + filters chromeLike(label: "res-values", ribbonColor: "#6600CC", labelColor: "#FFFFFF", position: "bottom") + } } } diff --git a/sample/example-vector/screenshots/Icons_doScreenshot(usingResValues).png b/sample/example-vector/screenshots/Icons_doScreenshot(usingResValues).png new file mode 100644 index 00000000..fffcad3b Binary files /dev/null and b/sample/example-vector/screenshots/Icons_doScreenshot(usingResValues).png differ diff --git a/sample/example-vector/src/usingResValues/.gitignore b/sample/example-vector/src/usingResValues/.gitignore new file mode 100644 index 00000000..0ad0e956 --- /dev/null +++ b/sample/example-vector/src/usingResValues/.gitignore @@ -0,0 +1 @@ +generated_strings.xml diff --git a/sample/example-vector/src/usingResValues/AndroidManifest.xml b/sample/example-vector/src/usingResValues/AndroidManifest.xml new file mode 100644 index 00000000..8bcaba1a --- /dev/null +++ b/sample/example-vector/src/usingResValues/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/sample/record_all.sh b/sample/record_all.sh index 8bcb773b..107c92bf 100755 --- a/sample/record_all.sh +++ b/sample/record_all.sh @@ -80,4 +80,6 @@ addToIndex addToIndex ./../gradlew :example-vector:recordUsingAndroidVersionDebugAndroidTestScreenshotTest --no-configuration-cache addToIndex +./../gradlew :example-vector:recordUsingResValuesDebugAndroidTestScreenshotTest --no-configuration-cache +addToIndex echo "Completed"