Derivation of Gibbs free energy formula
I think you are using the first approach that I described.  So, here is the analysis based on the first approach.  Suppose you have the following numbers of moles of A, B, C, and D in the reaction mixture at some time: $n_A$, $n_B$, $n_C$, and $n_D$. 

And the total pressure of the mixture (in bars) is held constant at P.  So the partial pressure of species A is $$p_A=\frac{n_A}{n_A+n_B+n_C+n_D}P$$And the partial molar free energy of species A is $$\bar{G}_A=G^0_A+RT\ln{\left(\frac{n_A}{n_A+n_B+n_C+n_D}P\right)}$$where $G^0_A$ is the free energy of pure species A at the reference pressure of 1 bar.  Similar equations can be written for the other species.  The total free energy of the mixture at any point in time during the reaction is:  $$G=n_A\bar{G}_A+n_B\bar{G}_B+n_C\bar{G}_C+n_D\bar{G}_D$$
Now, let the concentrations of the chemical species in the reaction mixture be expressed as follows:
$$n_A=n_{A0}-a\xi$$
$$n_B=n_{B0}-b\xi$$
$$n_C=n_{C0}+c\xi$$
$$n_A=n_{D0}+d\xi$$
where the subscript 0 refers to the initial state and $\xi$ is the conversion.  To find the equilibrium condition, you want to find the value of $ \xi $ that minimizes the free energy of the solution mixture.  To do that, you have a calculus problem to solve.