I am having error when running the command $ ionic build android
Did you install Android SDK and configure your Android_Home correctly ?
See Here for a detailed, step by step documentation.