|
| 1 | +import com.android.tools.profgen.ArtProfileKt |
| 2 | +import com.android.tools.profgen.ArtProfileSerializer |
| 3 | +import com.android.tools.profgen.DexFile |
| 4 | + |
1 | 5 | plugins { |
2 | 6 | id 'com.android.application' |
3 | 7 | id 'org.jetbrains.kotlin.android' |
@@ -91,3 +95,33 @@ dependencies { |
91 | 95 | kapt { |
92 | 96 | correctErrorTypes true |
93 | 97 | } |
| 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