Skip to content

Commit

Permalink
feat: support AGP 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Jan 11, 2021
1 parent 1d1c1c9 commit 29d388b
Show file tree
Hide file tree
Showing 20 changed files with 232 additions and 77 deletions.
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,39 @@ jobs:
env:
- AGP_VERSION=3.4.0
- GRADLE_WRAPPER_VERSION=5.1.1
script: bundle exec maze-runner -c --verbose
script: bundle exec maze-runner -c --verbose --fail-fast

# AGP 3.5.0 E2E tests
- name: AGP 3.5.0 E2E tests
env:
- AGP_VERSION=3.5.0
- GRADLE_WRAPPER_VERSION=5.4.1
script: bundle exec maze-runner -c --verbose
script: bundle exec maze-runner -c --verbose --fail-fast

# AGP 3.6.0 E2E tests
- name: AGP 3.6.0 E2E tests
env:
- AGP_VERSION=3.6.0
- GRADLE_WRAPPER_VERSION=5.6.4
script: bundle exec maze-runner -c --verbose
script: bundle exec maze-runner -c --verbose --fail-fast

# AGP 4.0.0 E2E tests
- name: AGP 4.0.0 E2E tests
env:
- AGP_VERSION=4.0.0
- GRADLE_WRAPPER_VERSION=6.1.1
script: bundle exec maze-runner -c --verbose
script: bundle exec maze-runner -c --verbose --fail-fast

# AGP 4.1.0 E2E tests
- name: AGP 4.1.0 E2E tests
env:
- AGP_VERSION=4.1.0-beta04
- GRADLE_WRAPPER_VERSION=6.5.1
script: bundle exec maze-runner -c --verbose
script: bundle exec maze-runner -c --verbose --fail-fast

# AGP 4.2.0 E2E tests
- name: AGP 4.2.0 E2E tests
env:
- AGP_VERSION=4.2.0-alpha07
- GRADLE_WRAPPER_VERSION=6.6-rc-6
script: bundle exec maze-runner -c --verbose
- AGP_VERSION=4.2.0-beta03
- GRADLE_WRAPPER_VERSION=6.7.1
script: bundle exec maze-runner -c --verbose --fail-fast
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## TBD

* Support AGP 4.2
[#350](https://github.com/bugsnag/bugsnag-android-gradle-plugin/pull/350)

* Prevent windows crash when generating Unity mapping files
[#344](https://github.com/bugsnag/bugsnag-android-gradle-plugin/pull/344)

Expand Down
34 changes: 24 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ buildscript {
google()
}

ext.agpVersion = "4.2.0-beta03" // compile against 4.1, but maintain compat to 3.4.0
ext.kotlinVersion = "1.3.72"

dependencies {
classpath "com.android.tools.build:gradle:4.1.0-rc01" // compile against 4.1.0-rc01, but maintain compat to 3.4.0
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
classpath "com.android.tools.build:gradle:$agpVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.9.1"
}
}

plugins {
id "com.github.hierynomus.license" version "0.15.0"
}

// Gradle plugins
plugins {
id "java-gradle-plugin"
id "groovy"
id "com.gradle.plugin-publish" version "0.12.0"
id "com.bmuschko.nexus" version "2.3.1"
id "com.jfrog.bintray" version "1.8.5"
id "com.github.hierynomus.license" version "0.15.0"
}

apply plugin: "org.jetbrains.kotlin.jvm"
apply plugin: "org.jetbrains.kotlin.kapt"
apply plugin: "maven-publish"
Expand All @@ -49,6 +49,20 @@ repositories {
google()
}

compileGroovy {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}

// compile groovy first, see
// https://docs.gradle.org/6.1-rc-1/release-notes.html#compilation-order
tasks.named("compileGroovy") {
classpath = sourceSets.main.compileClasspath
}
tasks.named("compileKotlin") {
classpath += files(sourceSets.main.groovy.classesDirectory)
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "1.8"
Expand All @@ -58,8 +72,8 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
// Build dependencies
dependencies {
kapt "com.squareup.moshi:moshi-kotlin-codegen:1.9.3"
compileOnly "com.android.tools.build:gradle:4.1.0-rc01"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72"
compileOnly "com.android.tools.build:gradle:$agpVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"

// For uploading proguard/ndk files
implementation "com.squareup.okhttp3:okhttp:4.8.0"
Expand All @@ -73,7 +87,7 @@ dependencies {
// For multiple I/O use cases
implementation "com.squareup.okio:okio:2.7.0"

testImplementation "com.android.tools.build:gradle:4.1.0-rc01"
testImplementation "com.android.tools.build:gradle:$agpVersion"
testImplementation "junit:junit:4.12"
testImplementation "org.mockito:mockito-core:2.28.2"
testImplementation "com.squareup.okhttp3:mockwebserver:4.8.0"
Expand Down
2 changes: 1 addition & 1 deletion detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ID>MagicNumber:BugsnagReleasesTask.kt$BugsnagReleasesTask$200</ID>
<ID>MaxLineLength:BugsnagManifestUuidTask.kt$BugsnagManifestUuidTask$private</ID>
<ID>ReturnCount:BugsnagPlugin.kt$BugsnagPlugin$ @Suppress("SENSELESS_COMPARISON") internal fun isUnityLibraryUploadEnabled(bugsnag: BugsnagPluginExtension, android: AppExtension): Boolean</ID>
<ID>ReturnCount:ManifestUuidTaskV2Compat.kt$internal fun createManifestUpdateTask( bugsnag: BugsnagPluginExtension, project: Project, variantName: String ): TaskProvider&lt;BugsnagManifestUuidTaskV2&gt;?</ID>
<ID>ReturnCount:SharedObjectMappingFileFactory.kt$SharedObjectMappingFileFactory$ fun generateSoMappingFile(project: Project, params: Params): File?</ID>
<ID>SpreadOperator:BugsnagReleasesTask.kt$BugsnagReleasesTask$(*cmd)</ID>
<ID>TooGenericExceptionCaught:BugsnagHttpClientHelper.kt$exc: Throwable</ID>
Expand All @@ -17,6 +18,5 @@
<ID>TooGenericExceptionCaught:SharedObjectMappingFileFactory.kt$SharedObjectMappingFileFactory$e: Exception</ID>
<ID>TooGenericExceptionCaught:SharedObjectMappingFileFactory.kt$SharedObjectMappingFileFactory$ex: Throwable</ID>
<ID>TooManyFunctions:BugsnagPlugin.kt$BugsnagPlugin$BugsnagPlugin</ID>
<ID>TooManyFunctions:SharedObjectMappingFileFactory.kt$SharedObjectMappingFileFactory$SharedObjectMappingFileFactory</ID>
</Whitelist>
</SmellBaseline>
Binary file modified features/fixtures/app/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Binary file modified features/fixtures/ndkapp/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Binary file modified features/fixtures/rnapp/android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Binary file modified features/fixtures/unity_2019/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
26 changes: 26 additions & 0 deletions src/main/groovy/com/bugsnag/android/gradle/GroovyCompat.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.bugsnag.android.gradle

import com.android.build.api.artifact.Artifacts
import com.android.build.gradle.AppExtension
import org.gradle.api.Action

/**
* Contains functions which exploit Groovy's metaprogramming to provide backwards
* compatibility for older AGP versions that would be impractical to achieve with
* Kotlin's static type system.
*/
class GroovyCompat {

static void registerUuidTaskAGP41(
AppExtension android,
Action<String> onVariantsCallback,
Action<Artifacts> onPropertiesCallback
) {
android.onVariants {
onVariantsCallback.execute(name)
onProperties {
onPropertiesCallback.execute(artifacts)
}
}
}
}
48 changes: 4 additions & 44 deletions src/main/kotlin/com/bugsnag/android/gradle/BugsnagPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.bugsnag.android.gradle

import com.android.build.api.artifact.ArtifactType
import com.android.build.api.dsl.CommonExtension
import com.android.build.gradle.AppExtension
import com.android.build.gradle.api.ApkVariant
import com.android.build.gradle.api.ApkVariantOutput
Expand All @@ -13,15 +11,17 @@ import com.bugsnag.android.gradle.internal.TASK_JNI_LIBS
import com.bugsnag.android.gradle.internal.UNITY_SO_MAPPING_DIR
import com.bugsnag.android.gradle.internal.UploadRequestClient
import com.bugsnag.android.gradle.internal.computeManifestInfoOutputV1
import com.bugsnag.android.gradle.internal.computeManifestInfoOutputV2
import com.bugsnag.android.gradle.internal.hasDexguardPlugin
import com.bugsnag.android.gradle.internal.intermediateForGenerateJvmMapping
import com.bugsnag.android.gradle.internal.intermediateForMappingFileRequest
import com.bugsnag.android.gradle.internal.intermediateForNdkSoRequest
import com.bugsnag.android.gradle.internal.intermediateForReleaseRequest
import com.bugsnag.android.gradle.internal.intermediateForUnitySoRequest
import com.bugsnag.android.gradle.internal.isVariantEnabled
import com.bugsnag.android.gradle.internal.newUploadRequestClientProvider
import com.bugsnag.android.gradle.internal.newUuidProvider
import com.bugsnag.android.gradle.internal.register
import com.bugsnag.android.gradle.internal.registerV2ManifestUuidTask
import com.bugsnag.android.gradle.internal.taskNameForGenerateJvmMapping
import com.bugsnag.android.gradle.internal.taskNameForGenerateNdkMapping
import com.bugsnag.android.gradle.internal.taskNameForGenerateUnityMapping
Expand All @@ -38,7 +38,6 @@ import org.gradle.api.file.RegularFile
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskProvider
import java.io.File
import java.util.UUID

/**
* Gradle plugin to automatically upload ProGuard mapping files to Bugsnag.
Expand Down Expand Up @@ -86,34 +85,7 @@ class BugsnagPlugin : Plugin<Project> {

val android = project.extensions.getByType(AppExtension::class.java)
if (BugsnagManifestUuidTaskV2.isApplicable()) {
check(android is CommonExtension<*, *, *, *, *, *, *, *>)
android.onVariants {
if (!bugsnag.enabled.get()) {
return@onVariants
}
val variant = VariantFilterImpl(name)
if (!isVariantEnabled(bugsnag, variant)) {
return@onVariants
}
val variantName = name
val taskName = taskNameForManifestUuid(variantName)
val manifestInfoOutputFile = project.computeManifestInfoOutputV2(variantName)
val buildUuidProvider = project.newUuidProvider()
val manifestUpdater = project.tasks.register(taskName,
BugsnagManifestUuidTaskV2::class.java) {
it.buildUuid.set(buildUuidProvider)
it.manifestInfoProvider.set(manifestInfoOutputFile)
}
onProperties {
artifacts
.use(manifestUpdater)
.wiredWithFiles(
taskInput = BugsnagManifestUuidTaskV2::inputManifest,
taskOutput = BugsnagManifestUuidTaskV2::outputManifest
)
.toTransform(ArtifactType.MERGED_MANIFEST)
}
}
registerV2ManifestUuidTask(android, bugsnag, project)
}

project.afterEvaluate {
Expand Down Expand Up @@ -142,12 +114,6 @@ class BugsnagPlugin : Plugin<Project> {
}
}

private fun isVariantEnabled(bugsnag: BugsnagPluginExtension,
variant: VariantFilterImpl): Boolean {
bugsnag.filter.execute(variant)
return variant.variantEnabled ?: true
}

private fun registerNdkLibInstallTask(project: Project) {
val ndkTasks = project.tasks.withType(ExternalNativeBuildTask::class.java)
val cleanTasks = ndkTasks.filter { it.name.contains(CLEAN_TASK) }.toSet()
Expand Down Expand Up @@ -634,10 +600,4 @@ class BugsnagPlugin : Plugin<Project> {
}
return searchPaths
}

private fun Project.newUuidProvider(): Provider<String> {
return provider {
UUID.randomUUID().toString()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ internal object AgpVersions {
val VERSION_3_4: VersionNumber = VersionNumber.parse("3.4.0")
val VERSION_3_5: VersionNumber = VersionNumber.parse("3.5.0")
val VERSION_4_0: VersionNumber = VersionNumber.parse("4.0.0")
val VERSION_4_1: VersionNumber = VersionNumber.parse("4.1.0")
val VERSION_4_2: VersionNumber = VersionNumber.parse("4.2.0")
}

/** A fast file hash that don't load the entire file contents into memory at once. */
Expand Down
Loading

0 comments on commit 29d388b

Please sign in to comment.