Skip to content
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

Fixed AGP 8.3.0 breaking change #154

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -150,7 +150,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 @@ -38,7 +38,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,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
Loading