How prevent apktool sort global variables?

128 views Asked by At

Hi first Forgive me for my weak english . i have a class named Class A in my android application with the content below :

public class A {


public static final SomeClass1 variable_C = new SomeClass1();
public static final SomeClass1 variable_A = new SomeClass1();
public static final SomeClass1 variable_D = new SomeClass1();
public static final SomeClass1 variable_B = new SomeClass1();


}

when i compile my project and then give my project apk to apktool to decompile it , apktool decompiles Class A Like below :

public class A {


public static final SomeClass1 variable_A = new SomeClass1();
public static final SomeClass1 variable_B = new SomeClass1();
public static final SomeClass1 variable_C = new SomeClass1();
public static final SomeClass1 variable_D = new SomeClass1();

}

apktool when decompile my project apk changes global variables ordering to alphabetical order . How can i force apktool does not sort global variables in alphabetical order and keep main global variables ordering when decompile my apk ?

thanks for your answers .

1

There are 1 answers

0
Antimony On BEST ANSWER

This is not apktool's fault. Unlike the Java classfile format, the Android dex format requires that fields appear in sorted order, which means that the source level ordering is lost as soon as you compile your code.

From https://source.android.com/devices/tech/dalvik/dex-format#class-data-item

the defined static fields, represented as a sequence of encoded elements. The fields must be sorted by field_idx in increasing order.

field identifiers list. These are identifiers for all fields referred to by this file, whether defined in the file or not. This list must be sorted, where the defining type (by type_id index) is the major order, field name (by string_id index) is the intermediate order, and type (by type_id index) is the minor order. The list must not contain any duplicate entries.