The advantages of polyaniline for application in new generation solar cells include its cost-effectiveness, environmentally friendly synthesis, remarkable stability, and the ability to modify the bandgap through the synthesis of its nanocomposites. But a challenge for its nanostructures is the limited solubility in non-toxic solvents, including water, which limits their processability in coating techniques. We overcame this challenge by synthesizing its copolymer with diphenylamine-4-sulfonate and its nanocomposite with titanium dioxide nanoparticles (TiO2NPs). So through a solid-state and template-free technique and using sodium diphenylamine-4-sulfonate, aniline hydrochloride salt, TiO2NPs, and FeCl3∙6 H2O as an oxidant, poly(N-(sulfophenyl)aniline) nanoflowers (PSANFLs), poly [(aniline-co-N-(4-sulfophenyl) aniline] nanofibers (PAPSANFs), poly(N-(sulfophenyl)aniline) nanofibers/titanium dioxide nanoparticles (PSANFs/TiO2NPs), and poly (aniline-co-N-(4-sulfophenyl)aniline nanofibers/titanium dioxide nanoparticles (PAPSANFs/TiO2NPs) were synthesized. Characterization of the synthesized samples was carried out through field emission scanning electron microscopy (FE-SEM), Fourier-transform infrared spectra, ultraviolet-visible spectra (UV-Vis), cyclic voltammetry (CV), and elemental analysis (CHNS). The FE-SEM images clearly illustrate that the synthesized samples are of nanoscale dimensions. The band gap values of 2.23 eV for PSANFs/TiO2NPs and 1.96 eV for PAPSANFs/TiO2NPs nanocomposites were determined through electrochemical calculations based on cyclic voltammetry curves, showcasing the complementary properties of n and p semiconductors. Using doctor blade method to prepare films from synthesized materials and the architectural pattern of ITO│TiO2NPs│semiconductor sample│Al, all hybrid solar cells are fabricated. The I-V characteristics and power conversion efficiency (PCE) of the samples were examined and discussed. The PCE values for the four samples were found to be in the range of 0.20–0.82 %.