Skip to content

Commit

Permalink
Add workaround for non reproducible baseline profiles in AGP to libre…
Browse files Browse the repository at this point in the history
… builds (#1065)

Add workaround for non reproducible baseline profiles in AGP
  • Loading branch information
nielsvanvelzen authored May 17, 2023
1 parent 22689a6 commit e2f358f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/baselineWorkaround.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
buildscript {
repositories {
mavenCentral()
google()
}

dependencies {
classpath libs.android.gradle
}
}

import com.android.tools.profgen.ArtProfileKt
import com.android.tools.profgen.ArtProfileSerializer
import com.android.tools.profgen.DexFile

/**
* This is a temporary workaround for https://issuetracker.google.com/issues/231837768
* which will be fixed in AGP 8.1.0, at which point the workaround may be deleted.
*/
project.afterEvaluate {
tasks.compileLibreReleaseArtProfile.doLast {
outputs.files.each { file ->
if (file.toString().endsWith(".profm")) {
println("Sorting ${file}")
def version = ArtProfileSerializer.valueOf("METADATA_0_0_2")
def profile = ArtProfileKt.ArtProfile(file)
def keys = new ArrayList(profile.profileData.keySet())
def sortedData = new LinkedHashMap()
Collections.sort keys, new DexFile.Companion()
keys.each { key -> sortedData[key] = profile.profileData[key] }
new FileOutputStream(file).with {
write(version.magicBytes$profgen)
write(version.versionBytes$profgen)
version.write$profgen(it, sortedData, "")
}
}
}
}
}
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ plugins {
alias(libs.plugins.dependencyupdates)
}

// Apply workaround
apply("baselineWorkaround.gradle")

detekt {
buildUponDefaultConfig = true
allRules = false
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutin
# Core
koin = { group = "io.insert-koin", name = "koin-android", version.ref = "koin" }
koin-compose = { group = "io.insert-koin", name = "koin-androidx-compose", version.ref = "koin-compose" }
android-gradle = { module = "com.android.tools.build:gradle", version.ref = "android-plugin" }
androidx-core = { group = "androidx.core", name = "core-ktx", version.ref = "androidx-core" }
androidx-core-splashscreen = { group = "androidx.core", name = "core-splashscreen", version.ref = "androidx-core-splashscreen" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidx-appcompat" }
Expand Down

0 comments on commit e2f358f

Please sign in to comment.