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
[GRADLE] Support AGP 3.4.0 #724
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package io.sentry.android.gradle | |
import com.android.build.gradle.AppPlugin | ||
import com.android.build.gradle.LibraryPlugin | ||
import com.android.build.gradle.api.ApplicationVariant | ||
import com.android.build.gradle.api.BaseVariantOutput | ||
import org.apache.commons.compress.utils.IOUtils | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
|
@@ -144,7 +145,12 @@ class SentryPlugin implements Plugin<Project> { | |
* @return | ||
*/ | ||
static String getDebugMetaPropPath(Project project, ApplicationVariant variant) { | ||
return "${variant.mergeAssets.outputDir}/sentry-debug-meta.properties" | ||
try { | ||
return "${variant.mergeAssetsProvider.outputDir}/sentry-debug-meta.properties" | ||
} catch (Throwable ignored) { | ||
return "${variant.mergeAssets.outputDir}/sentry-debug-meta.properties" | ||
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 believe it should be 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. What @nesterov-n said. In general I'd favor an implementation where instead of try-catching possible exceptions you rather check for the expected type and then call the right method. This - together with a couple of invariants / assertions in the right places - will result in a much more consistent and stable implementation that even gives you proper diagnostics in case something will change (again). And if we learned one thing with the AGP then that change is a constant thing. |
||
} | ||
|
||
} | ||
|
||
void apply(Project project) { | ||
|
@@ -158,27 +164,27 @@ class SentryPlugin implements Plugin<Project> { | |
project.android.applicationVariants.all { ApplicationVariant variant -> | ||
variant.outputs.each { variantOutput -> | ||
def manifestPath = extension.manifestPath | ||
|
||
if (manifestPath == null) { | ||
try { | ||
// Android Gradle Plugin < 3.0.0 | ||
manifestPath = variantOutput.processManifest.manifestOutputFile | ||
} catch (Exception ignored) { | ||
// Android Gradle Plugin >= 3.0.0 | ||
def outputDir = variantOutput.processManifest.manifestOutputDirectory | ||
// Gradle 4.7 introduced the lazy task API and AGP 3.3+ adopts that, | ||
// so we apparently have a Provider<File> here instead | ||
// TODO: This will let us depend on the configuration of each flavor's | ||
// manifest creation task and their transitive dependencies, which in | ||
// turn prolongs the configuration time accordingly. Evaluate how Gradle's | ||
// new Task Avoidance API can be used instead. | ||
// (https://docs.gradle.org/current/userguide/task_configuration_avoidance.html) | ||
if (!(outputDir instanceof File)) { | ||
outputDir = outputDir.get().asFile | ||
} | ||
manifestPath = new File(outputDir, "AndroidManifest.xml") | ||
} | ||
def dir = findAndroidManifestFileDir(variantOutput) | ||
manifestPath = new File(dir, "AndroidManifest.xml") | ||
} | ||
|
||
// if (manifestPath == null) { | ||
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 guess this dead code can go away before merging? |
||
// try { | ||
// // Android Gradle Plugin < 3.0.0 | ||
// manifestPath = variantOutput.processManifest.manifestOutputFile | ||
// } catch (Exception ignored) { | ||
// // Android Gradle Plugin >= 3.0.0 | ||
// def outputDir = variantOutput.processManifest.manifestOutputDirectory | ||
// | ||
// if (!(outputDir instanceof File)) { | ||
// outputDir = outputDir.get().asFile | ||
// } | ||
// manifestPath = new File(outputDir, "AndroidManifest.xml") | ||
// } | ||
// } | ||
|
||
def mappingFile = variant.getMappingFile() | ||
def proguardTask = getProguardTask(project, variant) | ||
def dexTask = getDexTask(project, variant) | ||
|
@@ -282,4 +288,26 @@ class SentryPlugin implements Plugin<Project> { | |
} | ||
} | ||
} | ||
|
||
static File findAndroidManifestFileDir(BaseVariantOutput variantOutput) { | ||
// Gradle 4.7 introduced the lazy task API and AGP 3.3+ adopts that, | ||
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. We should create a follow up issue to get this done once we merge this PR. |
||
// so we apparently have a Provider<File> here instead | ||
// TODO: This will let us depend on the configuration of each flavor's | ||
// manifest creation task and their transitive dependencies, which in | ||
// turn prolongs the configuration time accordingly. Evaluate how Gradle's | ||
// new Task Avoidance API can be used instead. | ||
// (https://docs.gradle.org/current/userguide/task_configuration_avoidance.html) | ||
|
||
try { // Android Gradle Plugin >= 3.3.0 | ||
return variantOutput.processManifestProvider.get().manifestOutputDirectory.get().asFile | ||
} catch (Exception ignored) {} | ||
|
||
try { // Android Gradle Plugin >= 3.0.0 | ||
return variantOutput.processManifest.manifestOutputDirectory.get().asFile | ||
} catch (Exception ignored) {} | ||
|
||
try { // Android Gradle Plugin < 3.0.0 | ||
return new File(variantOutput.processManifest.manifestOutputFile).parentFile | ||
} catch (Exception ignored) {} | ||
} | ||
} |
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.
mergeAssetsProvider
has typeTaskProvider<MergeSourceSetFolders>
. I beleive we need callget()
on it to make it works.