Skip to content

Commit 1db1a00

Browse files
StypoxTobiGr
authored andcommitted
Add snippet to ensure baseline.profm file is sorted
Thanks to obfusk, see https://issuetracker.google.com/issues/231837768 and TeamNewPipe#6486
1 parent 353db0b commit 1db1a00

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

app/build.gradle

Lines changed: 25 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 "kotlin-android"
@@ -308,3 +312,24 @@ static String getGitWorkingBranch() {
308312
return ""
309313
}
310314
}
315+
316+
project.afterEvaluate {
317+
tasks.compileReleaseArtProfile.doLast {
318+
outputs.files.each { file ->
319+
if (file.toString().endsWith(".profm")) {
320+
println("Sorting ${file} ...")
321+
def version = ArtProfileSerializer.valueOf("METADATA_0_0_2")
322+
def profile = ArtProfileKt.ArtProfile(file)
323+
def keys = new ArrayList(profile.profileData.keySet())
324+
def sortedData = new LinkedHashMap()
325+
Collections.sort keys, new DexFile.Companion()
326+
keys.each { key -> sortedData[key] = profile.profileData[key] }
327+
new FileOutputStream(file).with {
328+
write(version.magicBytes$profgen)
329+
write(version.versionBytes$profgen)
330+
version.write$profgen(it, sortedData, "")
331+
}
332+
}
333+
}
334+
}
335+
}

0 commit comments

Comments
 (0)