Understanding a computation of a surface integral on a cube 
Calculate the flow of the vector field $$\mathbf{A} = \nabla \dfrac{\mathbf{a}\cdot\mathbf{r}}{r^3}$$ from a cube with side length $1$, centered at origin and with one space diagonal parallel with the constant vector $\mathbf{a}$. 

Attempted solution
Let the $z$-axis run parallel to $\mathbf{a}$ in a cartesian coordinate system. Introduce spherical coordinates so that $$\mathbf{A} = \nabla \dfrac{\mathbf{a}\cdot\mathbf{r}}{r^3} = \nabla \dfrac{a\cos\theta}{r^2} = \sum_{i} \dfrac{1}{h_i} \dfrac{\partial (\dfrac{a\cos\theta}{r^2})}{\partial u_i} \hat{e}_i = \dfrac{-2a\cos\theta}{r^3}\hat{e}_r - \dfrac{a\sin\theta}{r^3}\hat{e}_{\theta}$$ 
Now what my book does is saying that $\nabla \cdot\mathbf{A}=0$ for $r\neq0$ and that the flow out of the cube is the same as the flow out ofa sphere centered at origin. It then goes to show that $$\iint_{r=R}\mathbf{A}\cdot \hat{e}_r dS = -\dfrac{2a}{R}2\pi \int_{0}^{\pi}\cos\theta\sin\theta d\theta=0$$ I understand every step except for:
1) Why did they calculate the divergence? (If Gauss' theorem is applicable here (which it should be) then that would give the result instantly).
2) How can they claim the flow is the same for the cube as it is for some sphere with radius $R$? 
 A: Since the divergence vanishes away from the origin, the volume integral $\int_V (\nabla\cdot\mathbf{A})dV$ will be unchanged if we replace $V$ with some other volume $V'$ that also contains the origin; in particular, we can take $V'$ to be the unit ball $B$ with boundary $S^2$. We can then use the divergence theorem once again, so that in total we have 
$$\iint_{\partial V} \mathbf{A}\cdot d\mathbf{S}=\iiint_{V} (\nabla \cdot\mathbf{A})\,dV=\iiint_{B} (\nabla \cdot\mathbf{A})\,dV=\iint_{S^2} \mathbf{A}\cdot d\mathbf{S}.$$
As for why one can't use Gauss's law to immediately conclude that the integral is zero, suppose we instead had $\mathbf{A}=\nabla(1/r)$: this still has divergence zero away from the origin, but there's now a net flux through the unit sphere. So evidently knowing that $\nabla\cdot \mathbf{A}=0$ away from the origin isn't enough to conclude that the integral vanishes. (The point is that $\mathbf{A}\to \infty$ at the origin, so one shouldn't expect $\nabla\cdot \mathbf{A}=0$ at $r=0$. For details see the solutions to this question: https://physics.stackexchange.com/q/14095/55641.)
