Two-sided assembly lines are widely applied in plants for producing large-sized high volume products, such as trucks and buses. Since the two-sided assembly line balancing problem (TALBP) is NP-hard, it is difficult to get an optimal solution in polynomial time. Therefore, a novel swarm based heuristic algorithm named gravitational search algorithm (GSA) is proposed to solve this problem with the objective of minimizing the number of mated-stations and the number of stations simultaneously. In order to apply GSA to solving the TALBP, an encoding scheme based on the random-keys method is used to convert the continuous positions of the GSA into the discrete task sequence. In addition, a new decoding scheme is implemented to decrease the idle time related to sequence-dependent finish time of tasks. The corresponding experiment results demonstrate that the proposed algorithm outperforms other well-known algorithms.