Skip to content

Commit 21793ae

Browse files
committed
Bug: baseline.profm not deterministic :: Patch 1
1 parent 4ff2c7d commit 21793ae

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

app/build.gradle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import com.android.tools.profgen.ArtProfileKt
2+
import com.android.tools.profgen.ArtProfileSerializer
3+
import com.android.tools.profgen.DexFile
4+
15
plugins {
26
id 'com.android.application'
37
id 'org.jetbrains.kotlin.android'
@@ -91,3 +95,33 @@ dependencies {
9195
kapt {
9296
correctErrorTypes true
9397
}
98+
99+
// Workaround for "Bug: baseline.profm not deterministic"
100+
//
101+
// Reference : https://f-droid.org/docs/Reproducible_Builds/#bug-baselineprofm-not-deterministic
102+
// Fix snippet : https://gist.github.com/obfusk/61046e09cee352ae6dd109911534b12e
103+
// Issue tracker : https://issuetracker.google.com/issues/231837768
104+
project.afterEvaluate {
105+
tasks.each { task ->
106+
if (task.name.startsWith("compile") && task.name.endsWith("ReleaseArtProfile")) {
107+
task.doLast {
108+
outputs.files.each { file ->
109+
if (file.name.endsWith(".profm")) {
110+
println("Sorting ${file} ...")
111+
def version = ArtProfileSerializer.valueOf("METADATA_0_0_2")
112+
def profile = ArtProfileKt.ArtProfile(file)
113+
def keys = new ArrayList(profile.profileData.keySet())
114+
def sortedData = new LinkedHashMap()
115+
Collections.sort keys, new DexFile.Companion()
116+
keys.each { key -> sortedData[key] = profile.profileData[key] }
117+
new FileOutputStream(file).with {
118+
write(version.magicBytes$profgen)
119+
write(version.versionBytes$profgen)
120+
version.write$profgen(it, sortedData, "")
121+
}
122+
}
123+
}
124+
}
125+
}
126+
}
127+
}

0 commit comments

Comments
 (0)