forked from getsentry/sentry-android-gradle-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that the sentry debug properties are added to final APK
To ensure that the asset file is added it needs to be available before the proguard task runs. So instead of relying on the CLI to generate the UUID there is now a separate task that creates it and --uuid is used in the CLI to match the mappings to the build. This fixes getsentry#37
- Loading branch information
Showing
4 changed files
with
180 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
plugin-build/src/main/groovy/io/sentry/android/gradle/GenerateSentryProguardUuidTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.sentry.android.gradle; | ||
|
||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.file.DirectoryProperty; | ||
import org.gradle.api.file.RegularFile; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.provider.Provider; | ||
import org.gradle.api.tasks.Internal; | ||
import org.gradle.api.tasks.OutputDirectory; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
import java.io.Writer; | ||
import java.util.UUID; | ||
|
||
abstract class GenerateSentryProguardUuidTask extends DefaultTask { | ||
@OutputDirectory | ||
public abstract DirectoryProperty getOutputDirectory(); | ||
|
||
@Internal | ||
public Provider<UUID> getOutputUuid() { | ||
return getOutputUuidInternal(); | ||
} | ||
|
||
@Internal | ||
protected abstract Property<UUID> getOutputUuidInternal(); | ||
|
||
@Internal | ||
private final Provider<RegularFile> outputFile = getOutputDirectory().map(dir -> dir.file("sentry-debug-meta.properties")); | ||
|
||
public GenerateSentryProguardUuidTask() { | ||
getOutputs().upToDateWhen(spec -> false); | ||
setDescription("Generates a unique build ID"); | ||
} | ||
|
||
@Internal | ||
public Provider<RegularFile> getOutputFile() { | ||
return outputFile; | ||
} | ||
|
||
@TaskAction | ||
protected void generateProperties() throws IOException { | ||
UUID uuid = UUID.randomUUID(); | ||
getOutputUuidInternal().set(uuid); | ||
|
||
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile.get().getAsFile())))) { | ||
writer.write("io.sentry.ProguardUuids="); | ||
writer.write(uuid.toString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
plugin-build/src/main/groovy/io/sentry/android/gradle/SentryUploadProguardMappingsTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package io.sentry.android.gradle; | ||
|
||
import org.apache.tools.ant.taskdefs.condition.Os; | ||
import org.gradle.api.file.RegularFile; | ||
import org.gradle.api.file.RegularFileProperty; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.tasks.Exec; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.InputFile; | ||
import org.gradle.api.tasks.Optional; | ||
|
||
import java.util.ArrayList; | ||
import java.util.UUID; | ||
|
||
abstract class SentryUploadProguardMappingsTask extends Exec { | ||
@Input | ||
public abstract Property<String> getCliExecutable(); | ||
|
||
@Input | ||
public abstract Property<UUID> getMappingsUuid(); | ||
|
||
@InputFile | ||
public abstract RegularFileProperty getMappingsFile(); | ||
|
||
@Optional | ||
@InputFile | ||
public abstract RegularFileProperty getSentryProperties(); | ||
|
||
@Optional | ||
@Input | ||
public abstract Property<String> getSentryOrganization(); | ||
|
||
@Optional | ||
@Input | ||
public abstract Property<String> getSentryProject(); | ||
|
||
@Input | ||
public abstract Property<Boolean> getAutoUpload(); | ||
|
||
public SentryUploadProguardMappingsTask() { | ||
setDescription("Uploads the proguard mappings file"); | ||
} | ||
|
||
@Override | ||
protected void exec() { | ||
RegularFile sentryProperties = getSentryProperties().getOrNull(); | ||
if (sentryProperties != null) { | ||
environment("SENTRY_PROPERTIES", sentryProperties); | ||
} else { | ||
getLogger().info("propsFile is null"); | ||
} | ||
|
||
ArrayList<Object> args = new ArrayList<>(); | ||
|
||
args.add(getCliExecutable().get()); | ||
args.add("upload-proguard"); | ||
args.add("--uuid"); | ||
args.add(getMappingsUuid().get()); | ||
args.add(getMappingsFile().get()); | ||
|
||
if (!getAutoUpload().get()) { | ||
args.add("--no-upload"); | ||
} | ||
|
||
String org = getSentryOrganization().getOrNull(); | ||
if (org != null) { | ||
args.add("--org"); | ||
args.add(org); | ||
} | ||
|
||
String project = getSentryProject().getOrNull(); | ||
if (project != null) { | ||
args.add("--project"); | ||
args.add(project); | ||
} | ||
|
||
if (Os.isFamily(Os.FAMILY_WINDOWS)) { | ||
args.add(0, "cmd"); | ||
args.add(1, "/c"); | ||
} | ||
commandLine(args); | ||
|
||
getLogger().info("cli args: " + getArgs()); | ||
|
||
super.exec(); | ||
} | ||
} |