An electrochemomechanical theory of defects in ionic solids. I. Theory