I do not think the answer changes much from the basic situation. Consider a situation where $N$ takes two possible values: $N_1$ and $N_2$ with probabilities $p$ and $1-p$ respectively. Then you want to maximize the following function:

$f(.) = p E\Bigl(\displaystyle\sum_{i=1}^{N_1} u(a_i X_i )\Bigr) + (1-p) E\Bigl(\sum_{i=1}^{N_2} u(a_i X_i )\Bigr) $

Without loss of generality assume that $N_2$ > $N_1$. Then we can simplify the above and re-write as:

$f(.) = E\Bigl(\displaystyle\sum_{i=1}^{N_1} u(a_i X_i )\Bigr) + (1-p) E\Bigl(\sum_{i=N_1 +1}^{N_2} u(a_i X_i )\Bigr) $

The maximum value of $f(.)$ can be computed by taking the maximum of the two terms independently as the set of 'parameters' ${a_i}$ are disjoint between the two terms. Thus, the maximum for the above case occurs at:

$a_i= \frac{1}{N_1}$ for $i=1, 2, ...N_1$

and

$a_i = \frac{1}{N_2-N_1}$ for $i=N_1 + 1, 2, ...N_2$