Last active
October 11, 2024 00:21
-
-
Save obfusk/eb82a810ed6aad266dab19977b18cee6 to your computer and use it in GitHub Desktop.
NB: fixed in Android Gradle Plugin >= 8.1.0 | sort baseline.profm in build.gradle using com.android.tools.profgen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NB: Android Studio can't find the imports; this does not affect the | |
// actual build since Gradle can find them just fine. | |
import com.android.tools.profgen.ArtProfileKt | |
import com.android.tools.profgen.ArtProfileSerializer | |
import com.android.tools.profgen.DexFile | |
project.afterEvaluate { | |
tasks.each { task -> | |
if (task.name.startsWith("compile") && task.name.endsWith("ReleaseArtProfile")) { | |
task.doLast { | |
outputs.files.each { file -> | |
if (file.name.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, "") | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NB: when using build.gradle.kts instead of build.gradle, save this file as | |
// app/fix-profm.gradle and add the following line to app/build.gradle.kts: | |
// apply(from = "fix-profm.gradle") | |
buildscript { | |
repositories { | |
google() | |
mavenCentral() | |
} | |
dependencies { | |
// NB: use this to specifiy the AGP version directly: | |
// classpath 'com.android.tools.build:gradle:7.4.0' | |
// NB: use this with gradle/libs.versions.toml (and modify as needed): | |
classpath "com.android.tools.build:gradle:${libs.versions.android.gradle.get()}" | |
} | |
} | |
// NB: Android Studio can't find the imports; this does not affect the | |
// actual build since Gradle can find them just fine. | |
import com.android.tools.profgen.ArtProfileKt | |
import com.android.tools.profgen.ArtProfileSerializer | |
import com.android.tools.profgen.DexFile | |
project.afterEvaluate { | |
tasks.each { task -> | |
if (task.name.startsWith("compile") && task.name.endsWith("ReleaseArtProfile")) { | |
task.doLast { | |
outputs.files.each { file -> | |
if (file.name.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, "") | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment