Skip to content

Commit

Permalink
latest gradle, agp, kotlin
Browse files Browse the repository at this point in the history
uninstall apk helper tasks via buildSrc
  • Loading branch information
trevjonez committed Apr 13, 2020
1 parent b29d47f commit 9f871be
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 90 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Items listed here may not be exhaustive, if you are seeing issues, check the git

## 1.0.0-rc06
- Print output for `adb install` commands. #59 thanks [@plastiv](https://github.com/plastiv).
- Update gradle and AGP to latest stable. `6.2.1` & `3.6.1` respectively.
- Update Gradle, AGP, and Kotlin to latest stable versions. `6.3`,`3.6.2`,`1.3.71` respectively.
- Process: Github actions for verification. #36 again, thank you [@plastiv](https://github.com/plastiv).
- Feature: Dynamic-Feature module support
- Feature: Test module support "com.android.test". #71 thanks [@dkostyrev](https://github.com/dkostyrev).
- Incubating Feature: Dynamic-Feature module support. See issue #63 for more details.
- Feature: Test module support `com.android.test`. #71 thanks [@dkostyrev](https://github.com/dkostyrev).

## 1.0.0-rc05
- Catch a specific subset of errors allowing clean disposal of underlying processes. (logcat and instrumentation)
Expand Down
20 changes: 20 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.Properties

plugins {
`kotlin-dsl`
`java-gradle-plugin`
}

repositories {
jcenter()
google()
}

gradlePlugin {
plugins {
create("adb-uninstall") {
id = "com.trevjonez.adb-uninstall"
implementationClass = "com.trevjonez.AdbUninstallPlugin"
}
}
}
56 changes: 56 additions & 0 deletions buildSrc/src/main/kotlin/com/trevjonez/AdbUninstallPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2020 Trevor Jones
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.trevjonez

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.provider.SetProperty
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.register

abstract class AdbUninstallPlugin: Plugin<Project> {

override fun apply(target: Project) {
val extension = target.extensions.create<AdbUninstallExtension>("adbUninstall")

val lifecycleTask = target.tasks.register("adbUninstallAll") {
description = "Run all adb uninstall tasks"
group = "Adb Uninstall"
}

target.afterEvaluate {
extension.packageNames.orNull.orEmpty().forEachIndexed { index, pkgName ->
val nameSuffix = pkgName.split('.')
.joinToString(separator = "") { it.capitalize() }

val uninstall = tasks.register<RemoveApkTask>("adbUninstall$nameSuffix") {
packageName.set(pkgName)
description = "Uninstall '$pkgName'"
group = "Adb Uninstall"
}

lifecycleTask.configure {
dependsOn(uninstall)
}
}
}
}
}

abstract class AdbUninstallExtension {
abstract val packageNames: SetProperty<String>
}
50 changes: 50 additions & 0 deletions buildSrc/src/main/kotlin/com/trevjonez/RemoveApkTask.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2020 Trevor Jones
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.trevjonez

import org.gradle.api.provider.Property
import org.gradle.api.tasks.AbstractExecTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import java.io.File

abstract class RemoveApkTask : AbstractExecTask<RemoveApkTask>(RemoveApkTask::class.java) {

@get:Input
abstract val packageName: Property<String>

@get:[Input Optional]
abstract val adbPath: Property<String>

private val androidHome by lazy {
requireNotNull(System.getenv("ANDROID_HOME"))
}

private val adb by lazy {
"$androidHome${File.separator}platform-tools${File.separator}adb"
}

override fun exec() {
isIgnoreExitValue = true
commandLine(
adbPath.orNull ?: adb,
"shell", "pm", "uninstall",
packageName.get()
)
super.exec()
}
}
5 changes: 5 additions & 0 deletions commander/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: "org.jetbrains.kotlin.jvm"
apply from: "$rootProject.projectDir/publish.gradle"
apply plugin: "com.trevjonez.adb-uninstall"

ext.artifactId = "commander-android"
description = "Functions to work with Android SDK Tools like adb, avdmanager, sdkmanager."
Expand All @@ -14,6 +15,10 @@ dependencies {
testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect"
}

adbUninstall {
packageNames.add("com.trevjonez.commander.testsupport")
}

test {
useJUnitPlatform {
includeEngines 'spek2'
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ group=com.trevjonez.composer

CGP_VERSION=1.0.0-rc06

AGP_VERSION=3.6.1
#AGP_VERSION=4.0.0-beta01
#AGP_VERSION=4.1.0-alpha01
AGP_VERSION=3.6.2
#AGP_VERSION=4.0.0-beta04
#AGP_VERSION=4.1.0-alpha05

MIN_SDK=23
COMPILE_SDK=29

KOTLIN_VERSION=1.3.61
KOTLIN_VERSION=1.3.71

org.gradle.caching=true
org.gradle.parallel=true
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 2 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Fri Feb 28 23:27:29 MST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 9f871be

Please sign in to comment.