Unfortunately, you cannot build units for defense on your own. To get units for defense, you must request for troops from your Squad.
To do this, first join a "Squad" using the Squad icon in the bottom right of your screen. Then from the Squad Center in your base, press "Request" to send a request to your squad team members.
Upgrade your Squad Center to receive more units at a time. Tell your Squad what units you are looking for if you prefer certain units. Typically Soldiers/Stormtroopers and Speeder Bikes are best for defense.
Make sure your Squad Center is positioned in range of your other buildings so the requested units will be alerted when there's an attack. You can select the Squad Center to see get range of the response.
If your Squad is very active with donations, you can also use the ally units for attacking. However, you have to use all requested units at once in one battle and deploy them all to the same spot.
Don't forget to donate to your Squad members when they request. This is how a squad can get an advantage of over another by working together and sharing.