"By avoiding doing something" is the correct form.
Depending on the meaning required, verbs will either need to be followed by a present participle (gerund) or by an infinitive form:
"Preparing to do something", "I prepared to do something", "To prepare
to do something", etc.
The choice of present participle or infinitive depends entirely on the preceding verb, and will be the same regardless of the form that verb takes.
(Note that there are some verbs where either pres. ppl. or infinitive is possible:
"I hate doing this", "I hate to do this"
Usually in such cases the meaning is different depending on which is used.)
There's more info on this here and here. The former gives examples of verbs that can take either gerund or infinitive, with a note of the change in meaning between the two.