Protective layers applied directly to the device before packaging