Why this kotlin file named Color.kt was different after two times compiled

my androidx.core library version is:
androidx.core:core-ktx:1.2.0
and compile environment is:
org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30
com.android.tools.build:gradle:4.2.2
gradle 7.4
jdk11
however i found some kotlin files was different in classes.dex after compiled the APK twice.
the different part is:

d2 order in Metadata(the order of d2 values was changed each compiled)

import androidx.annotation.RequiresApi;
import g.c3.w.k0;
import g.h0;
import k.f.a.d;
import p027c.p037b.p038a.p039a.p040a.Log;

@h0(bv = {1, 0, 3}, d1 = {"\u0000:\n\u0002\u0018\u0002\n\u0002\u0010\u0007\n\u0002\b\b\n\u0002\u0010\b\n\u0002\b\u0003\n\u0002\u0010\t\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0011\u001a\u0014\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H‡\n¢\u0006\u0004\b\u0002\u0010\u0003\u001a\u0014\u0010\u0004\u001a\u00020\u0001*\u00020\u0000H‡\n¢\u0006\u0004\b\u0004\u0010\u0003\u001a\u0014\u0010\u0005\u001a\u00020\u0001*\u00020\u0000H‡\n¢\u0006\u0004\b\u0005\u0010\u0003\u001a\u0014\u0010\u0006\u001a\u00020\u0001*\u00020\u0000H‡\n¢\u0006\u0004\b\u0006\u0010\u0003\u001a\u001c\u0010\b\u001a\u00020\u0000*\u00020\u00002\u0006\u0010\u0007\u001a\u00020\u0000H‡\u0002¢\u0006\u0004\b\b\u0010\t\u001a\u0014\u0010\u0002\u001a\u00020\n*\u00020\nH†\n¢\u0006\u0004\b\u0002\u0010\u000b\u001a\u0014\u0010\u0004\u001a\u00020\n*\u00020\nH†\n¢\u0006\u0004\b\u0004\u0010\u000b\u001a\u0014\u0010\u0005\u001a\u00020\n*\u00020\nH†\n¢\u0006\u0004\b\u0005\u0010\u000b\u001a\u0014\u0010\u0006\u001a\u00020\n*\u00020\nH†\n¢\u0006\u0004\b\u0006\u0010\u000b\u001a\u0014\u0010\f\u001a\u00020\u0000*\u00020\nH‡\b¢\u0006\u0004\b\f\u0010\r\u001a\u0014\u0010\u000f\u001a\u00020\u000e*\u00020\nH‡\b¢\u0006\u0004\b\u000f\u0010\u0010\u001a\u0014\u0010\u0002\u001a\u00020\u0001*\u00020\u000eH‡\n¢\u0006\u0004\b\u0002\u0010\u0011\u001a\u0014\u0010\u0004\u001a\u00020\u0001*\u00020\u000eH‡\n¢\u0006\u0004\b\u0004\u0010\u0011\u001a\u0014\u0010\u0005\u001a\u00020\u0001*\u00020\u000eH‡\n¢\u0006\u0004\b\u0005\u0010\u0011\u001a\u0014\u0010\u0006\u001a\u00020\u0001*\u00020\u000eH‡\n¢\u0006\u0004\b\u0006\u0010\u0011\u001a\u0014\u0010\f\u001a\u00020\u0000*\u00020\u000eH‡\b¢\u0006\u0004\b\f\u0010\u0012\u001a\u0014\u0010\u0013\u001a\u00020\n*\u00020\u000eH‡\b¢\u0006\u0004\b\u0013\u0010\u0014\u001a\u001c\u0010\u0017\u001a\u00020\u000e*\u00020\n2\u0006\u0010\u0016\u001a\u00020\u0015H‡\f¢\u0006\u0004\b\u0017\u0010\u0018\u001a\u001c\u0010\u0017\u001a\u00020\u000e*\u00020\n2\u0006\u0010\u0016\u001a\u00020\u0019H‡\f¢\u0006\u0004\b\u0017\u0010\u001a\u001a\u001c\u0010\u0017\u001a\u00020\u000e*\u00020\u000e2\u0006\u0010\u0016\u001a\u00020\u0015H‡\f¢\u0006\u0004\b\u0017\u0010\u001b\u001a\u001c\u0010\u0017\u001a\u00020\u000e*\u00020\u000e2\u0006\u0010\u0016\u001a\u00020\u0019H‡\f¢\u0006\u0004\b\u0017\u0010\u001c\u001a$\u0010\u0017\u001a\n \u001d*\u0004\u0018\u00010\u00000\u0000*\u00020\u00002\u0006\u0010\u0016\u001a\u00020\u0015H‡\f¢\u0006\u0004\b\u0017\u0010\u001e\u001a$\u0010\u0017\u001a\n \u001d*\u0004\u0018\u00010\u00000\u0000*\u00020\u00002\u0006\u0010\u0016\u001a\u00020\u0019H‡\f¢\u0006\u0004\b\u0017\u0010\u001f\u001a\u0014\u0010\u0013\u001a\u00020\n*\u00020 H‡\b¢\u0006\u0004\b\u0013\u0010!\"\u0018\u0010#\u001a\u00020\"*\u00020\u000e8Ç\u0002@\u0006¢\u0006\u0006\u001a\u0004\b#\u0010$\"\u0018\u0010\u0016\u001a\u00020\u0019*\u00020\u000e8Ç\u0002@\u0006¢\u0006\u0006\u001a\u0004\b%\u0010&\"\u0018\u0010(\u001a\u00020\n*\u00020\n8Æ\u0002@\u0006¢\u0006\u0006\u001a\u0004\b'\u0010\u000b\"\u0018\u0010*\u001a\u00020\u0001*\u00020\u000e8Ç\u0002@\u0006¢\u0006\u0006\u001a\u0004\b)\u0010\u0011\"\u0018\u0010,\u001a\u00020\u0001*\u00020\u000e8Ç\u0002@\u0006¢\u0006\u0006\u001a\u0004\b+\u0010\u0011\"\u0018\u0010.\u001a\u00020\u0001*\u00020\u000e8Ç\u0002@\u0006¢\u0006\u0006\u001a\u0004\b-\u0010\u0011\"\u0018\u00100\u001a\u00020\u0001*\u00020\u000e8Ç\u0002@\u0006¢\u0006\u0006\u001a\u0004\b/\u0010\u0011\"\u0018\u0010,\u001a\u00020\n*\u00020\n8Æ\u0002@\u0006¢\u0006\u0006\u001a\u0004\b+\u0010\u000b\"\u0018\u00100\u001a\u00020\u0001*\u00020\n8Ç\u0002@\u0006¢\u0006\u0006\u001a\u0004\b/\u00101\"\u0018\u0010.\u001a\u00020\n*\u00020\n8Æ\u0002@\u0006¢\u0006\u0006\u001a\u0004\b-\u0010\u000b\"\u0018\u0010*\u001a\u00020\n*\u00020\n8Æ\u0002@\u0006¢\u0006\u0006\u001a\u0004\b)\u0010\u000b\"\u0018\u0010(\u001a\u00020\u0001*\u00020\u000e8Ç\u0002@\u0006¢\u0006\u0006\u001a\u0004\b'\u0010\u0011\"\u0018\u00102\u001a\u00020\"*\u00020\u000e8Ç\u0002@\u0006¢\u0006\u0006\u001a\u0004\b2\u0010$¨\u00063"}, d2 = {"Landroid/graphics/Color;", "", "com
ponent1", "(Landroid/graphics/Color;)F", "component2", "component3", "component4", "c", "plus", "(Landroid/graphics/Color;Landroid/graphics/Color;)Landroid/graphics/Color;", "", "(I)I", "toColor", "(I)Landroid/graphics/Color;", "", "toColorLong", "(I)J", "(J)F", "(J)Landroid/graphics/Color;", "toColorInt", "(J)I", "Landroid/graphics/ColorSpace$Named;", "colorSpace", "convertTo", "(ILandroid/graphics/ColorSpace$Named;)J", "Landroid/graphics/ColorSpace;", "(ILandroid/graphics/ColorSpace;)J", "(JLandroid/graphics/ColorSpace$Named;)J", "(JLandroid/graphics/ColorSpace;)J", "kotlin.jvm.PlatformType", "(Landroid/graphics/Color;Landroid/graphics/ColorSpace$Named;)Landroid/graphics/Color;", "(Landroid/graphics/Color;Landroid/graphics/ColorSpace;)Landroid/graphics/Color;", "", "(Ljava/lang/String;)I", "", "isWideGamut", "(J)Z", "getColorSpace", "(J)Landroid/graphics/ColorSpace;", "getAlpha", "alpha", "getRed", "red", "getGreen", "green", "getBlue", "blue", "getLuminance", "luminance", "(I)F", "isSrgb", "core-ktx_release"}, k = 2, mv = {1, 4, 0})
/* compiled from: Color.kt */
public final class ColorKt {
    @RequiresApi(26)
    public static final float component1(@d Color color) {
        k0.q(color, "$this$component1");
        return color.getComponent(0);

the order of d2 array was different after two times compiled
source file : core/core-ktx/src/main/java/androidx/core/graphics/Color.kt - platform/frameworks/support - Git at Google

I think we shouldn’t assume that compiling the code is deterministic and always produces exactly the same bytecode. You can use kotlinx-metadata to read these binary blobs and see if there is any real difference, but if you already observe that elements are just re-ordered then I guess this is just some set of elements, so ordering doesn’t matter.

1 Like

Hello, we’re working on reproducible builds , and if 2 compilations are inconsistent, this will lead to a crisis of code engineering being untrusted.Do you know what the specific reason?

I believe even plain Java compiler doesn’t give guarantees what two compilations will result in same bytecode.

This post was flagged by the community and is temporarily hidden.