Skip to content

Commit

Permalink
Merge pull request #487 from kennethshackleton/agp-8.2
Browse files Browse the repository at this point in the history
Android Gradle Plugin 8.2.2.
  • Loading branch information
kennethshackleton authored Feb 11, 2024
2 parents 8f78647 + f8cacc8 commit fd56d26
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 19 deletions.
2 changes: 1 addition & 1 deletion AndroidLibBenchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {
namespace = "com.bloomberg.selekt.android.benchmark"
defaultConfig {
minSdkVersion(21)
targetSdkVersion(32)
targetSdkVersion(34)
testInstrumentationRunner = "androidx.benchmark.junit4.AndroidBenchmarkRunner"
testInstrumentationRunnerArguments.putAll(arrayOf(
"androidx.benchmark.suppressErrors" to "EMULATOR,LOW_BATTERY,UNLOCKED"
Expand Down
1 change: 1 addition & 0 deletions SQLite3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ fun osName() = System.getProperty("os.name").lowercase(Locale.US).run {
}

fun platformIdentifier() = "${osName()}-${System.getProperty("os.arch")}"
logger.quiet("Resolved platform identifier: {}", platformIdentifier())

tasks.register<Copy>("buildHost") {
dependsOn("makeSQLite")
Expand Down
6 changes: 5 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ subprojects {
}
}
tasks.withType<Test>().configureEach {
systemProperty("com.bloomberg.selekt.lib.can_use_embedded", true)
systemProperty("com.bloomberg.selekt.can_use_load", true)
systemProperty(
"com.bloomberg.selekt.library_path",
layout.buildDirectory.dir("intermediates/assets/debugUnitTest").get().asFile.toString()
)
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ gradlePlugin {

dependencies {
implementation(kotlin("gradle-plugin", version = kotlinVersion))
implementation("com.android.tools.build:gradle:8.0.2")
implementation("com.android.tools.build:gradle:8.2.2")
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum class Versions(
) {
ANDROID_BENCHMARK("1.2.0-alpha13", URL("https://developer.android.com/studio/profile/benchmark")),
ANDROID_BUILD_TOOLS("34.0.0", URL("https://developer.android.com/studio/releases/build-tools")),
ANDROID_GRADLE_PLUGIN("8.0.2", URL("https://developer.android.com/tools/revisions/gradle-plugin.html")),
ANDROID_GRADLE_PLUGIN("8.2.2", URL("https://developer.android.com/tools/revisions/gradle-plugin.html")),
ANDROID_LINT("30.0.2", URL("https://github.com/googlesamples/android-custom-lint-rules")),
ANDROID_NDK("26.1.10909125", URL("https://developer.android.com/ndk")),
ANDROID_SDK("34", URL("https://developer.android.com/sdk")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ package com.bloomberg.selekt.android

import com.bloomberg.selekt.ExternalSQLite
import com.bloomberg.selekt.SQLite
import com.bloomberg.selekt.commons.loadEmbeddedLibrary
import com.bloomberg.selekt.commons.loadLibrary
import com.bloomberg.selekt.externalSQLiteSingleton

private const val CAN_USE_EMBEDDED_PROPERTY_KEY = "com.bloomberg.selekt.lib.can_use_embedded"
private const val CAN_USE_LOAD_PROPERTY_KEY = "com.bloomberg.selekt.can_use_load"

fun loadSQLite(): ExternalSQLite = externalSQLiteSingleton {
"selekt".let {
try {
System.loadLibrary(it)
} catch (e: UnsatisfiedLinkError) {
if (System.getProperty(CAN_USE_EMBEDDED_PROPERTY_KEY, null) == "true") {
loadEmbeddedLibrary(checkNotNull(SQLite::class.java.classLoader), "jni", it)
if (System.getProperty(CAN_USE_LOAD_PROPERTY_KEY, null) == "true") {
loadLibrary(checkNotNull(SQLite::class.java.classLoader), "jni", it)
} else {
throw e
}
Expand Down
5 changes: 3 additions & 2 deletions selekt-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ android {
buildConfigField("String", "gitCommitSha1", "\"${gitCommit()}\"")
}
}
sourceSets["test"].resources.srcDir(layout.buildDirectory.dir("intermediates/libs"))
sourceSets["test"].assets.srcDir(layout.buildDirectory.dir("intermediates/libs"))
publishing {
singleVariant("release") {
withJavadocJar()
Expand Down Expand Up @@ -92,6 +92,7 @@ tasks.register<Copy>("copyJniLibs") {
fileTree(project(":Selektric").layout.buildDirectory.dir("intermediates/libs"))
)
into(layout.buildDirectory.dir("intermediates/libs/jni"))
mustRunAfter("buildNativeHost")
}

tasks.register<Task>("buildNativeHost") {
Expand All @@ -107,7 +108,7 @@ arrayOf("Debug", "Release").map { "pre${it}UnitTestBuild" }.forEach {
}
}

arrayOf("Debug", "Release").map { "process${it}UnitTestJavaRes" }.forEach {
arrayOf("Debug", "Release").map { "merge${it}UnitTestAssets" }.forEach {
tasks.whenTaskAdded {
if (it == name) {
dependsOn("copyJniLibs")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.bloomberg.selekt.android

import com.bloomberg.selekt.commons.loadEmbeddedLibrary
import com.bloomberg.selekt.commons.loadLibrary

internal object NativeFixtures {
init {
loadEmbeddedLibrary(NativeFixtures::class.java.classLoader!!, "jni", "selektric")
loadLibrary(checkNotNull(NativeFixtures::class.java.classLoader), "jni", "selektric")
check(nativeInit() == 0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@

package com.bloomberg.selekt.commons

import java.io.BufferedOutputStream
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.nio.file.Files
import java.util.Locale
import kotlin.io.path.Path
import kotlin.io.path.createTempFile
import kotlin.jvm.Throws

private const val LIBRARY_PATH_KEY = "com.bloomberg.selekt.library_path"

@Suppress("Detekt.StringLiteralDuplication")
@JvmSynthetic
internal fun osNames(systemOsName: String = System.getProperty("os.name")) = systemOsName.lowercase(Locale.US).run {
Expand All @@ -50,7 +53,7 @@ internal fun libraryExtensions() = osNames().map {
}.toSet()

@JvmSynthetic
internal fun libraryResourceNames(
internal fun libraryNames(
parentDirectory: String,
name: String
) = (platformIdentifiers() * libraryExtensions()).map {
Expand All @@ -59,18 +62,47 @@ internal fun libraryResourceNames(

@Throws(IOException::class)
fun loadEmbeddedLibrary(loader: ClassLoader, parentDirectory: String, name: String) {
val url = checkNotNull(libraryResourceNames(parentDirectory, name).firstNotNullOfOrNull {
val url = checkNotNull(libraryNames(parentDirectory, name).firstNotNullOfOrNull {
loader.getResource(it)
}) { "Failed to find resource with name: $name" }
}) { "Failed to find resource with name: $name in directory: $parentDirectory" }
@Suppress("NewApi") // Not used by Android.
val file = createTempFile("lib$name", "lib").toFile().apply { deleteOnExit() }
val file = createTempFile("lib$name", "lib").toFile()
try {
url.openStream().use { inputStream ->
BufferedOutputStream(FileOutputStream(file)).use { outputStream -> inputStream.copyTo(outputStream) }
FileOutputStream(file).use {
inputStream.copyTo(it)
}
}
@Suppress("UnsafeDynamicallyLoadedCode")
System.load(file.absolutePath)
} finally {
file.delete()
}
}

@Suppress("NewApi")
private fun loadLibrary(
libraryPath: String,
parentDirectory: String,
name: String
) {
val path = libraryNames(parentDirectory, name).map {
Path(libraryPath, it)
}.first {
Files.exists(it)
}.toAbsolutePath()
@Suppress("UnsafeDynamicallyLoadedCode")
System.load(path.toString())
}

@Throws(IOException::class)
fun loadLibrary(
loader: ClassLoader,
parentDirectory: String,
name: String
) {
when (val libraryPath = System.getProperty(LIBRARY_PATH_KEY)) {
null -> loadEmbeddedLibrary(loader, parentDirectory, name)
else -> loadLibrary(libraryPath, parentDirectory, name)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal class NativeResourcesKtTest {

@Test
fun commonLibraryResourceName() {
libraryResourceNames("jni", "selekt").forEach {
libraryNames("jni", "selekt").forEach {
assertTrue(it.startsWith("jni"))
}
}
Expand Down

0 comments on commit fd56d26

Please sign in to comment.