2

For some raison I do not yet understand, aapt and aapt2 do not output the same ID. is their any way to force aapt2 to output the same ID generated by aapt ?

zeus
  • 12,173
  • 9
  • 63
  • 184
  • 1
    ids are not meant to be stable values so even two versions of aapt or two consecutive runs of aapt would be free to give you different results. https://stackoverflow.com/questions/27302044/is-it-possible-force-stable-android-resource-ids might work but would require you to predefine all of them. In code, you can access them via the id-by-name methods so you don't have to know their actual value – zapl Oct 03 '22 at 23:37

1 Answers1

1

No, you can't even force aapt resp aapt2 to guaranteedly assign the same resource IDs in consecutive runs. The IDs in the R.java file are static during the app's runtime but will be dynamically assigned during compile time.

For a short discussion on the reasons you might take a look at this Stackoverflow thread on the purpose and structure of resource IDs.

Further, it's discouraged to even touch the R.java file and with that the resource IDs. You also don't need to know those ID's for any purpose. Just use the common documented ways to access the app resources and you'll be perfectly fine.

NB: There are some methods to predefine IDs as e.g. described in this Stackoverflow thread, employing the R.id class. But there shouldn't be many real use cases for tricks like that. Usually you'll make things just unnecessarily complicated.

Krokomot
  • 3,208
  • 2
  • 4
  • 20