I fixed the issue by using the same sdk version in the other modules.
Well, since everything was right in my case, this had to be a gradle issue(bug probably). This happens mostly due to implementation(project-lib) part, probably when the project is added for the first time, or when due to any issue the project-lib module fails to build, and this error occurs in the subsequent tries to build the project, even if the issues are addressed.
I suppose there’s some kind of cyclic dependency that triggers this. So the hack to go around this are the following steps.
1. Go to build.gradle inside app folder, and comment out the implementation(project-lib) dependency.
2. Press Sync Now on the option that appears after changing anything in gradle.
You don’t get an error, good. You get one? Better. In any case proceed.
3. Go to the Gradle option on right side of the studio(look at the right edge) press it, click on main-project, you will see your project-lib option, click it, then ->Tasks->Build->Assemble Debug and Assemble Release.
If you don’t see your project-lib there, you have to delete all build folders and iml files manually, invalidate caches and restart. You will then see your project.
4. Uncomment the dependency line in your app level build.gradle, that you previously commented, and DO NOT press Sync Now. Go to -> Build-> Rebuild project. Then if the Sync now option is still there, you can sync.
Now the error will be gone.
N.B This answer is after you ensure, there are no loopholes from your side.