Skip to content

Commit

Permalink
Fixed AGP 8.3.0 breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzo authored and nathan3d committed Mar 21, 2024
1 parent bfddcb5 commit dce5826
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
android-gradle-plugin: [8.2.0]
android-gradle-plugin: [8.2.0, 8.3.0]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion ruler-cli/src/main/java/com/spotify/ruler/cli/RulerCli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class RulerCli : CliktCommand(), BaseRulerTask {
)
InjectedToolApkCreator(aapt2Tool!!.toPath())
} else {
ApkCreator(File(projectPath))
ApkCreator()
}
) {
createSplitApks(
Expand Down
4 changes: 3 additions & 1 deletion ruler-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ val browserDist by configurations.creating {
}

dependencies {
implementation(Dependencies.ANDROID_GRADLE_PLUGIN)
compileOnly(Dependencies.ANDROID_GRADLE_PLUGIN)
testRuntimeOnly(Dependencies.ANDROID_GRADLE_PLUGIN)

compileOnly(Dependencies.BUNDLETOOL)
compileOnly(Dependencies.PROTOBUF_CORE)
compileOnly(Dependencies.ANDROID_TOOLS_COMMON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
package com.spotify.ruler.common.apk

import com.android.SdkConstants
import com.android.build.gradle.internal.SdkLocator
import com.android.builder.errors.DefaultIssueReporter
import com.android.bundle.Commands.BuildApksResult
import com.android.bundle.Devices
import com.android.prefs.AndroidLocationsSingleton
Expand All @@ -28,7 +26,6 @@ import com.android.tools.build.bundletool.commands.BuildApksCommand
import com.android.tools.build.bundletool.device.DeviceSpecParser
import com.android.tools.build.bundletool.model.Password
import com.android.tools.build.bundletool.model.SigningConfiguration
import com.android.utils.StdLogger
import com.spotify.ruler.common.models.DeviceSpec
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
Expand All @@ -50,7 +47,7 @@ import java.util.zip.ZipInputStream
*/

const val BUFFER_SIZE = 1024
open class ApkCreator(private val rootDir: File) {
open class ApkCreator(private val androidSDKDir: File? = null) {

private val rulerDebugKey = "rulerDebug.keystore"
private val rulerKeystorePassword = "rulerpassword"
Expand Down Expand Up @@ -92,20 +89,15 @@ open class ApkCreator(private val rootDir: File) {

/** Finds and returns the location of the aapt2 executable. */
open fun getAapt2Location(): Path {
val sdkLocation = getAndroidSdkLocation()
val sdkHandler = AndroidSdkHandler.getInstance(AndroidLocationsSingleton, sdkLocation)
val sdkLocation = (androidSDKDir ?: File(checkNotNull(System.getenv("ANDROID_HOME")) {
"Missing 'ANDROID_HOME' environment variable"
}))
val sdkHandler = AndroidSdkHandler.getInstance(AndroidLocationsSingleton, sdkLocation.toPath())
val progressIndicator = object : ProgressIndicatorAdapter() { /* No progress reporting */ }
val buildToolInfo = sdkHandler.getLatestBuildTool(progressIndicator, true)
return buildToolInfo.location.resolve(SdkConstants.FN_AAPT2)
}

/** Finds and returns the location of the Android SDK. */
private fun getAndroidSdkLocation(): Path {
val logger = StdLogger(StdLogger.Level.WARNING)
val issueReporter = DefaultIssueReporter(logger)
return SdkLocator.getSdkDirectory(rootDir, issueReporter).toPath()
}

/**
* Gets Ruler debug signing key from resource to sign the split apks.
* Doing this step makes sure the corresponding /META-INF/BNDLTOOL.SF and *.RSA files are created in the apks.
Expand Down Expand Up @@ -134,7 +126,7 @@ open class ApkCreator(private val rootDir: File) {
}
}

class InjectedToolApkCreator(private val aapt2Tool: Path) : ApkCreator(File("")) {
class InjectedToolApkCreator(private val aapt2Tool: Path) : ApkCreator() {
override fun getAapt2Location(): Path = aapt2Tool
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import java.io.File
import java.nio.file.Paths

class ApkCreatorTest {
private val creator = ApkCreator(File(""))
private val creator = ApkCreator()
private val bundleFile = Paths.get("src", "test", "resources", "test.aab").toFile()
private val deviceSpec = DeviceSpec("arm64-v8a", "en", 480, 27)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.spotify.ruler.common.apk

import com.android.tools.profgen.Apk
import com.google.common.truth.Truth.assertThat
import com.spotify.ruler.common.sanitizer.ClassNameSanitizer
import com.spotify.ruler.common.sanitizer.ResourceNameSanitizer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.spotify.ruler.plugin

import com.android.build.gradle.BaseExtension
import com.spotify.ruler.common.BaseRulerTask
import com.spotify.ruler.common.apk.ApkCreator
import com.spotify.ruler.common.dependency.DependencyComponent
Expand Down Expand Up @@ -124,7 +125,8 @@ abstract class RulerTask : DefaultTask(), BaseRulerTask {
override fun provideBloatyPath() = null

private fun createApkFile(): Map<String, List<File>> {
val apkCreator = ApkCreator(project.rootDir)
val android = project.extensions.findByName("android") as BaseExtension?
val apkCreator = ApkCreator(android?.sdkDirectory)

val apkFile = bundleFile.asFile.get()
return if (apkFile.extension == "apk") {
Expand Down

0 comments on commit dce5826

Please sign in to comment.