The unique properties of metal halide perovskites give them great potential for applications in portable and wearable optoelectronics. However, the intrinsic brittleness of perovskites favors easy crack propagation that deteriorates the optoelectronic performance of the devices. Inspired by nacre, we propose flexible perovskite thin films fabricated by antisolvent-assisted self-encapsulation of polymer and imprinting techniques during crystallization. Such an approach results in synchronous formation of polymer-glued perovskite grains exhibiting nacre-like “brick-and-mortar” structure. The deformable composite architecture bonding hemisphere-shaped grating (HG) and porous photonic crystal (PC) (HG-PC) improves its crystalline quality and light-harvesting capability. An HG-PC photodetector (PD) with high responsivity of 17.31 A/W and detectivity of 5.02 × 1013 Jones is achieved. Our flexible HG-PC PD retains 95% of the initial photocurrent after 1000 bending cycles at 2 mm curvature radius. This solvent-driven self-encapsulation strategy offers an innovative and universal approach for highly efficient flexible optoelectronics.