Difference between Android ID and device ID
While your question targets a development issue (which is off-topic here), the answer is relevant for users as well, so I'm going to answer it:


DeviceID: This is the serial of the device, which should persist even a factory reset.
AndroidID: This will be set at the first boot (either with a brand new device, or after a factory reset). As implicated, it does not survive a factory-reset
There's a second "Android_ID" which is generated and used by the Google Services Framework (GSF), and thus often referenced as "GSF ID". Behaves basically like the AndroidID mentioned before (e.g. doesn't survive a factory-reset), and co-exists with it.
Furthermore, there's the GAID (Google Advertising ID), which can be reset by the user via the Google Settings app.


During "normal operation" (i.e. as long as you not factory-reset your device or reset the GAID), all these IDs can be used to identify the device. When using multiple users (via user profiles) on a device, all except the DeviceID would even identify the user (profile).

To my knowledge, all those IDs are available across all Android versions (at least across those which are currently relevant, i.e. GB/2.3 and up). The last two obviously only if GApps are installed – so on devices running a Custom ROM without GApps, they might not exist.