Skip to content
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
108 changes: 0 additions & 108 deletions realm-transformer/build.gradle

This file was deleted.

48 changes: 48 additions & 0 deletions realm-transformer/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Local fork of io.realm:realm-transformer:10.19.0 with AGP 9 compatibility patches.
// Published to the composite build under the same coordinates so dependency substitution
// kicks in automatically for any consumer that pulls `io.realm:realm-gradle-plugin:10.19.0`.

plugins {
kotlin("jvm") version "2.2.21"
`java-library`
`maven-publish`
}

group = "io.realm"
version = "10.19.0"

repositories {
google()
mavenCentral()
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

kotlin {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
}
}

dependencies {
implementation(gradleApi())
implementation("io.realm:realm-annotations:10.19.0")
compileOnly("com.android.tools.build:gradle:9.0.0")
implementation("org.javassist:javassist:3.25.0-GA")
implementation("com.google.guava:guava:31.0.1-jre")
implementation("javax.xml.bind:jaxb-api:2.3.1")
}

publishing {
publications {
create<MavenPublication>("realmPublication") {
groupId = "io.realm"
artifactId = "realm-transformer"
version = "10.19.0"
from(components["java"])
}
}
}
1 change: 0 additions & 1 deletion realm-transformer/settings.gradle

This file was deleted.

1 change: 1 addition & 0 deletions realm-transformer/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "realm-transformer"
10 changes: 10 additions & 0 deletions realm-transformer/src/main/java/io/realm/transformer/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.realm.transformer;

/**
* Hand-authored replacement for the original Ant-templated Version.java. Coordinates pinned
* to upstream Realm Java 10.19.0 (and its Realm Core dependency) so this fork is a drop-in.
*/
public class Version {
public static final String VERSION = "10.19.0";
public static final String SYNC_VERSION = "13.26.0";
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ abstract class RealmTransformerTask : DefaultTask() {
val jarFileOutput: FileSystem = output.get().let { jarFile ->
// Workaround to create the Jar if does not exist, as FileSystems fails to do so.
touchJarFile(jarFile)
FileSystems.newFileSystem(output.get().asFile.toPath(), null)
FileSystems.newFileSystem(output.get().asFile.toPath(), null as ClassLoader?)
}

val build: BuildTemplate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@
* 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.
*
* --
* Modified by Butterfly Network for AGP 9 compatibility. The legacy
* `com.android.build.gradle.BaseExtension` API was removed in AGP 9; this file now
* reads `bootClasspath` from `AndroidComponentsExtension.sdkComponents` and treats the
* SDK-version analytics fields as best-effort (returning "unknown" if the modern DSL
* shape ever changes again).
*/

package io.realm.transformer.ext

import com.android.build.gradle.BaseExtension
import com.android.build.api.dsl.CommonExtension
import com.android.build.api.variant.AndroidComponentsExtension
import org.gradle.api.Project
import java.io.File

Expand All @@ -25,69 +33,56 @@ import java.io.File
*/
fun Project.getAppId(): String {
// Use the Root project name, usually set in `settings.gradle`
// This means that we don't treat apps with multiple flavours as different, nor
// if a project contains more than one app (probably unlikely).
// This seems acceptable. These cases would just show up as more builds for the
// same AppId.
return this.rootProject.name
}

/**
* Returns the `targetSdk` property for this project if it is available.
* Reflectively reads `defaultConfig.targetSdk` so the same code works against both
* `ApplicationExtension` (which has it) and `LibraryExtension` (which does not).
*/
fun Project.getTargetSdk(): String {
return getAndroidExtension(this).defaultConfig.targetSdkVersion?.apiString ?: "unknown"
}
fun Project.getTargetSdk(): String = readDefaultConfigInt("getTargetSdk")

/**
* Returns the `minSdk` property for this project if it is available.
*/
fun Project.getMinSdk(): String {
return getAndroidExtension(this).defaultConfig.minSdkVersion?.apiString ?: "unknown"
}
fun Project.getMinSdk(): String = readDefaultConfigInt("getMinSdk")

private fun Project.readDefaultConfigInt(getter: String): String =
runCatching {
@Suppress("UnstableApiUsage")
val ext = extensions.getByType(CommonExtension::class.java)
val defaultConfig: Any = ext.defaultConfig
val method = defaultConfig.javaClass.methods.firstOrNull { it.name == getter && it.parameterCount == 0 }
method?.invoke(defaultConfig)?.toString() ?: "unknown"
}.getOrDefault("unknown")

/**
* Returns the version of the Android Gradle Plugin that is used.
*/
fun Project.getAgpVersion(): String {
// This API is only available from AGP 7.0.0. And it is a bit unclear exactly which part of
// this is actually stable. Also, there appear to be problems with depending on AGP 7.* on
// the compile classpath (it cannot load BaseExtension).
//
// So for now, this code assumes that we are compiling against AGP 4.1 and uses reflection
// to try to grap the AGP version.
//
// This is done with a best-effort, but we just
// accept finding the version isn't possible if anything goes wrong.
return try {
val extension = this.extensions.getByName("androidComponents") as Object
val method = extension.`class`.getMethod("getPluginVersion")
val version = method.invoke(extension)
if (version != null) {
return version.toString()
} else {
return "unknown"
}
version?.toString() ?: "unknown"
} catch (e: Exception) {
"unknown"
}
}

/**
* Returns the `bootClasspath` for this project
* Returns the `bootClasspath` for this project. AGP 9 exposes this via the modern
* `AndroidComponentsExtension.sdkComponents.bootClasspath` provider; we resolve it
* eagerly here because the transformer task needs a `List<File>`.
*/
fun Project.getBootClasspath(): List<File> {
return getAndroidExtension(this).bootClasspath
}

private fun getAndroidExtension(project: Project): BaseExtension {
// This will always be present, otherwise the android build would not be able to
// trigger the transformer code in the first place.
return project.extensions.getByName("android") as BaseExtension
val androidComponents = extensions.getByType(AndroidComponentsExtension::class.java)
return androidComponents.sdkComponents.bootClasspath.get().map { it.asFile }
}

fun Project.areIncrementalBuildsDisabled() =
if(extensions.extraProperties.has("io.realm.disableIncrementalBuilds")){
if (extensions.extraProperties.has("io.realm.disableIncrementalBuilds")) {
extensions.extraProperties["io.realm.disableIncrementalBuilds"] == "true"
} else {
false
Expand All @@ -103,4 +98,4 @@ fun Project.targetType(): String = with(project.plugins) {

fun Project.usesKotlin(): Boolean {
return project.pluginManager.hasPlugin("kotlin-kapt")
}
}
6 changes: 0 additions & 6 deletions realm-transformer/src/main/templates/Version.java

This file was deleted.

Loading