Context. With a clear circular aperture, the vortex coronagraph perfectly cancels an on-axis point source and offers a 0.9 or 1.75λ/D inner working angle for topological charge 2 or 4, respectively. Current and near-future large telescopes are on-axis, however, and the diffraction effects of the central obscuration, and the secondary supports are strong enough to prevent the detection of companions 10 −3 -10 −5 as bright as, or fainter than, their host star. Aims. Recent advances show that a ring apodizer can restore the performance of this coronagraph by compensating for the diffraction effects of a circular central obscuration in a 1D modeling of the pupil. Our aim is to extend this work and design optimal apodizers for arbitrary apertures in 2D in order to tackle the diffraction effects of the spiders and other noncircular artifacts in the pupil. Methods. We fold this analytical result into a numerical optimization scheme that yields hybrid coronagraph designs that combine the advantages of the vortex coronagraph (small in IWA) and of shaped pupils coronagraphs (robustness to central obscuration and pupil asymmetric structures). The transmission of the apodizer is maximized, while constraints are set on the extremum values of the electric field that is computed in chosen regions of the Lyot plane through closed form expressions derived even for topological charges. Optimal apodizers are computed for topological charges 2 and 4 vortex coronagraphs and for telescope apertures with 10-30% central obscurations and 0%, 0.5%, and 1% thick spiders. Results. We put the results of our numerical optimizations in perspective with the analytical solutions and show that our apodizations converge to the ring apodizations. We then characterize the impacts of the obscuration ratio and the thickness of the spiders on the throughput and the IWA. For the apodized charge-2 vortex coronagraph the throughputs are slightly below those of the ring apodized vortex coronagraph, and the inner working angle is mostly unaffected by the apodization. The throughputs of the apodizers for the charge-4 vortex coronagraph are higher than those of the ring apodized vortex coronagraph. This effect increases with the obscuration ratio, though the inner working angle does, too, and it ranges between 2 and 3λ/D. Conclusions. The results presented in this paper show that high contrast at small inner working angles can be obtained with a vortex coronagraph for on-axis telescopes, in spite of the presence of a secondary mirror and its secondary support structures.