[go: nahoru, domu]

Skip to content
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

Fix incorrect wiring of the GoogleServicesTask #232

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix incorrect wiring of the GoogleServicesTask
In the process of making configuration of the GooglerServicesTask lazily
configured, the registration of the generated outputs with the Android
Gradle plugin was moved into the lazy task configuration. This only
works if the google services task is configured before any of the tasks
that consume it, which is not guaranteed, leading to the below issues.

This change also removes the partial workaround of manually adding the
task dependency to one of the consuming tasks.

Issue: #228
Also potentially related: #228
Test: Manually verified that the wiring works correctly with AGP 7.4.0-alpha03 and Gradle 7.5-rc-1
  • Loading branch information
cmwarrington committed Jun 9, 2022
commit 8192dfbf941ddcdb7db1e5225cd1b4354890f8d0
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,19 @@ class GoogleServicesPlugin implements Plugin<Project> {
.register(
"process${variant.name.capitalize()}GoogleServices",
GoogleServicesTask) { task ->
task.setIntermediateDir(outputDir)
task.outputDirectory.set(outputDir)
task.applicationId.set(variant.applicationId)
task.setBuildType(variant.buildType.name)
task.setProductFlavors(variant.productFlavors.collect { it.name })

// This is necessary for backwards compatibility with versions of gradle that do not support
// this new API.
if (variant.respondsTo("registerGeneratedResFolders")) {
task.ext.generatedResFolders = project.files(outputDir).builtBy(task)
variant.registerGeneratedResFolders(task.generatedResFolders)
} else {
//noinspection GrDeprecatedAPIUsage
variant.registerResGeneratingTask(task, outputDir)
}
}
if (variant.respondsTo("getMergeResourcesProvider")) {
variant.mergeResourcesProvider.configure { dependsOn(processTask) }
} else {
//noinspection GrDeprecatedAPIUsage
variant.mergeResources.dependsOn(processTask)
}
if (variant.respondsTo("registerGeneratedResFolders")) {
variant.registerGeneratedResFolders(
project.files(processTask.flatMap {task -> task.outputDirectory})
)
} else {
//noinspection GrDeprecatedAPIUsage Support for AGP 2.2 and below (perhaps we can drop that support?)
variant.registerResGeneratingTask(processTask.get(), processTask.get().outputDirectory.get().asFile)
}
}

public static class GoogleServicesPluginConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import com.google.gson.JsonPrimitive;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.model.ObjectFactory;

import org.gradle.api.provider.Property;
import org.gradle.api.resources.TextResource;
import org.gradle.api.tasks.Input;
Expand Down Expand Up @@ -61,7 +63,6 @@ public abstract class GoogleServicesTask extends DefaultTask {

private static final String OAUTH_CLIENT_TYPE_WEB = "3";

private File intermediateDir;
private String buildType;
private List<String> productFlavors;
private ObjectFactory objectFactory;
Expand All @@ -72,9 +73,7 @@ public GoogleServicesTask(ObjectFactory objectFactory) {
}

@OutputDirectory
public File getIntermediateDir() {
return intermediateDir;
}
public abstract DirectoryProperty getOutputDirectory();

@Input
public String getBuildType() {
Expand All @@ -86,10 +85,6 @@ public List<String> getProductFlavors() {
return productFlavors;
}

public void setIntermediateDir(File intermediateDir) {
this.intermediateDir = intermediateDir;
}

public void setBuildType(String buildType) {
this.buildType = buildType;
}
Expand Down Expand Up @@ -125,6 +120,7 @@ public void action() throws IOException {
getLogger().info("Parsing json file: " + quickstartFile.getPath());

// delete content of outputdir.
File intermediateDir = getOutputDirectory().get().getAsFile();
deleteFolder(intermediateDir);
if (!intermediateDir.mkdirs()) {
throw new GradleException("Failed to create folder: " + intermediateDir);
Expand Down Expand Up @@ -260,7 +256,7 @@ private void handleAnalytics(JsonObject clientObject, Map<String, String> resVal

resValues.put("ga_trackingId", trackingId.getAsString());

File xml = new File(intermediateDir, "xml");
File xml = new File(getOutputDirectory().get().getAsFile(), "xml");
if (!xml.exists() && !xml.mkdirs()) {
throw new GradleException("Failed to create folder: " + xml);
}
Expand Down