Skip to content

Commit

Permalink
Merge pull request #2 from 2BAB/dev
Browse files Browse the repository at this point in the history
AGP 8.1 Support
  • Loading branch information
2BAB committed Dec 29, 2023
2 parents ae075ac + dd36345 commit 5bd4fa3
Show file tree
Hide file tree
Showing 22 changed files with 337 additions and 262 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'
- uses: actions/cache@v2
with:
path: |
Expand All @@ -51,11 +51,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'
- uses: actions/cache@v2
with:
path: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
- name: Check out
uses: actions/checkout@v2

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'

- name: Prepare environment
env:
Expand Down
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.1.2")
classpath("me.2bab:bundle-tool-plugin:1.2.0")
classpath("com.android.tools.build:gradle:8.1.2")
classpath("me.2bab:bundle-tool-plugin:1.3.0")
}
}
```
Expand Down Expand Up @@ -136,10 +136,16 @@ abstract class UploadTask : DefaultTask() {

bundle-tool-gradle-plugin is only supported & tested on LATEST 2 Minor versions of Android Gradle Plugin.

| AGP | BundleTool | bundle-tool-gradle-plugin |
|-------|------------|---------------------------|
| 7.1.x | 1.8.0 | 1.2.0 |
| 7.0.x | 1.6.0 | 1.1.0 |
| AGP | BundleTool | bundle-tool-gradle-plugin |
|--------|------------|---------------------------|
| 8.1.x | 1.14.0 | 1.3.0 |
| 7.1.x | 1.8.0 | 1.2.0 |
| 7.0.x | 1.6.0 | 1.1.0 |

Tips:

1. How to swiftly find the companion BundleTool version from AGP: create/open a vanilla Android project, take a look at the *External Libraries* -> *Gradle Script dependencies* -> you will see something like *builder-8.1.2-sources.jar* & *bundletool-1.14.0.jar*, which means the AGP 8.1.2 uses the BundleTool 1.14.0.
2. How to determine the BundleTool features' compatibility: check the [`VersionGuardedFeature`](https://github.com/google/bundletool/blob/0b00e4a8d3129cdfa2a98119fe7a3373ff49cdd3/src/main/java/com/android/tools/build/bundletool/model/version/VersionGuardedFeature.java) Enumeration file.

## Git Commit Check

Expand Down
26 changes: 17 additions & 9 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import me.xx2bab.bundletool.*
import java.util.Properties
import java.io.FileInputStream
import java.util.Locale

plugins {
id("com.android.application")
Expand All @@ -9,12 +10,12 @@ plugins {
}

android {
compileSdk = 31

compileSdk = 34
namespace = "me.xx2bab.sample.bundle"
defaultConfig {
applicationId = "me.xx2bab.sample.bundle"
minSdk = 28
targetSdk = 31
targetSdk = 34
versionCode = 1
versionName = "1.0"

Expand Down Expand Up @@ -77,10 +78,10 @@ android {

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "11"
jvmTarget = "17"
}
}

Expand Down Expand Up @@ -141,6 +142,8 @@ bundleTool {
GetSizeDimension.SCREEN_DENSITY.name,
GetSizeDimension.LANGUAGE.name
)
modules.set("")
instant.set(false)
}
}
}
Expand All @@ -150,20 +153,25 @@ bundleTool {
androidComponents {
// Pls use the same rule as `enableByVariant{...}` over
onVariants(selector().withBuildType("debug")) { variant ->
tasks.register<UploadTask>("UploadApksFor${variant.name.capitalize()}") {
this.outputDirProperty.set(variant.getBundleToApksOutputDir())
tasks.register<UploadTask>(
"UploadApksFor${variant.name.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(
Locale.getDefault()
) else it.toString()
}}") {
uploadDir.set(variant.getBundleToApksOutputDir())
}
}
}

abstract class UploadTask : DefaultTask() {

@get:org.gradle.api.tasks.InputDirectory
abstract val outputDirProperty: DirectoryProperty
abstract val uploadDir: DirectoryProperty

@org.gradle.api.tasks.TaskAction
fun upload() {
outputDirProperty.get().asFile.listFiles().forEach { artifact ->
uploadDir.get().asFile.listFiles().forEach { artifact ->
logger.lifecycle("Uploading bundle-tool outputs: ${artifact.absolutePath}")
// upload(artifact)
}
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.xx2bab.sample.bundle">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:text="Hello World"
android:layout_centerInParent="true"/>


</RelativeLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">BundleToolGradlePlugin</string>
<string name="app_name2">BundleToolGradlePlugin</string>
</resources>
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ buildscript {
repositories {
mavenCentral()
maven {
setUrl( "https://plugins.gradle.org/m2/")
setUrl("https://plugins.gradle.org/m2/")
}
}
}
2 changes: 1 addition & 1 deletion bundle-tool-plugin/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

dependencies {
// Github Release
implementation("com.github.breadmoirai:github-release:2.2.12")
implementation("com.github.breadmoirai:github-release:2.5.2")
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion bundle-tool-plugin/buildSrc/src/main/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object BuildConfig {

object Versions {
const val pluginVersion = "1.2.0"
const val pluginVersion = "1.3.0"
}

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask
import java.util.*

val libs = File(project.buildDir.absoluteFile, "libs")
val taskName = "releaseArtifactsToGithub"
val artifacts: DirectoryProperty = project.objects.directoryProperty()
artifacts.set(libs)

// Temporary workaround for directory is not recognized by ReleaseAssets
gradle.taskGraph.whenReady {
beforeTask {
if (this is GithubReleaseTask) {
this.setReleaseAssets(libs.listFiles())
}
}
}

val tokenFromEnv: String? = System.getenv("GH_DEV_TOKEN")
val token: String = if (!tokenFromEnv.isNullOrBlank()) {
Expand All @@ -31,30 +19,37 @@ val repo = "bundle-tool-gradle-plugin"
val tagBranch = "main"
val version = BuildConfig.Versions.pluginVersion
val releaseNotes = ""
createGithubReleaseTaskInternal(artifacts, token, repo, tagBranch, version, releaseNotes)


fun createGithubReleaseTaskInternal(artifacts: DirectoryProperty,
token: String,
repo: String,
tagBranch: String,
version: String,
releaseNotes: String): TaskProvider<GithubReleaseTask> {
return project.tasks.register<GithubReleaseTask>("releaseArtifactsToGithub") {
setAuthorization("Token $token")
setOwner("2bab")
setRepo(repo)
setTagName(version)
setTargetCommitish(tagBranch)
setReleaseName(version)
setBody(releaseNotes)
setDraft(false)
setPrerelease(false)
setReleaseAssets(artifacts)
setOverwrite(true)
setAllowUploadToExisting(true)
setApiEndpoint("https://api.github.com")
setDryRun(false)
createGithubReleaseTaskInternal(token, repo, tagBranch, version, releaseNotes)


fun createGithubReleaseTaskInternal(
token: String,
repo: String,
tagBranch: String,
version: String,
releaseNotes: String
): TaskProvider<GithubReleaseTask> {
return project.tasks.register<GithubReleaseTask>(taskName) {
authorization.set("Token $token")
owner.set("2bab")
this.repo.set(repo)
tagName.set(version)
targetCommitish.set(tagBranch)
releaseName.set("v${version}")
body.set(releaseNotes)
draft.set(false)
prerelease.set(false)
overwrite.set(true)
allowUploadToExisting.set(true)
apiEndpoint.set("https://api.github.com")
dryRun.set(false)
generateReleaseNotes.set(false)
releaseAssets.from(
tasks.getByName<Jar>("jar").archiveFile, // seal-${version}.jar
tasks.getByName<Jar>("sourcesJar").archiveFile, // seal-${version}-sources.jar
tasks.getByName<Jar>("javadocJar").archiveFile, // seal-${version}-javadoc.jar
//tasks.getByName<Sign>("signPluginMavenPublication").outputs, // seal-${version}-asc.jar, seal-${version}-sources-asc.jar, seal-${version}-sources-asc.jar,
)
}
}

Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
plugins{
plugins {
`maven-publish`
signing
}


// Stub secrets to let the project sync and build without the publication values set up
ext["signing.keyId"] = null
ext["signing.password"] = null
Expand All @@ -29,9 +28,6 @@ if (secretPropsFile.exists()) {
ext["ossrh.username"] = System.getenv("OSSRH_USERNAME")
ext["ossrh.password"] = System.getenv("OSSRH_PASSWORD")
}
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}
fun getExtraString(name: String) = ext[name]?.toString()


Expand All @@ -52,23 +48,44 @@ val username = "2BAB"


publishing {
// Configure MavenCentral repository
repositories {
maven {
name = "sonatype"
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = getExtraString("ossrh.username")
password = getExtraString("ossrh.password")
}
}
}

publications {
create<MavenPublication>("BTPlugin") {
artifact(javadocJar.get())
from(components["java"])
pom {
// Description
name.set(projectName)
description.set(mavenDesc)
url.set(siteUrl)
// Configure MavenLocal repository
repositories {
maven {
name = "myMavenlocal"
url = uri(System.getProperty("user.home") + "/.m2/repository")
}
}
}

// Archive
afterEvaluate {
publishing.publications.all {
signing.sign(this)
val publicationName = this.name
(this as MavenPublication).apply {
if (publicationName == "pluginMaven") {
groupId = groupName
artifactId = projectName
version = BuildConfig.Versions.pluginVersion
}
version = BuildConfig.Versions.pluginVersion
pom {
if (publicationName == "pluginMaven") {
name.set(project.name)
}
description.set(mavenDesc)
url.set(siteUrl)

// License
inceptionYear.set(inception)
licenses {
licenseNames.forEachIndexed { ln, li ->
Expand All @@ -91,28 +108,4 @@ publishing {
}
}
}

// Configure MavenCentral repository
repositories {
maven {
name = "sonatype"
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = getExtraString("ossrh.username")
password = getExtraString("ossrh.password")
}
}
}

// Configure MavenLocal repository
repositories {
maven {
name = "myMavenlocal"
url = uri(System.getProperty("user.home") + "/.m2/repository")
}
}
}

signing {
sign(publishing.publications)
}
Loading

0 comments on commit 5bd4fa3

Please sign in to comment.