%%%%
% (from an answer by cyberSingularity at http://tex.stackexchange.com/a/69832/226)
%%%
\documentclass[12pt]{article}
\title{Example using xr on Overleaf}
%%%% HELPER CODE FOR DEALING WITH EXTERNAL REFERENCES
% (from an answer by cyberSingularity at http://tex.stackexchange.com/a/69832/226)
%%%
\usepackage{xcite}
\usepackage{xr}
\makeatletter
\newcommand*{\addFileDependency}[1]{% argument=file name and extension
\typeout{(#1)}% latexmk will find this if $recorder=0 (however, in that case, it will ignore #1 if it is a .aux or .pdf file etc and it exists! if it doesn't exist, it will appear in the list of dependents regardless)
\@addtofilelist{#1}% if you want it to appear in \listfiles, not really necessary and latexmk doesn't use this
\IfFileExists{#1}{}{\typeout{No file #1.}}% latexmk will find this message if #1 doesn't exist (yet)
}
\makeatother
\newcommand*{\myexternaldocument}[1]{%
\externaldocument{#1}%
\addFileDependency{#1.tex}%
\addFileDependency{#1.aux}%
}
%%% END HELPER CODE
% put all the external documents here!
\myexternaldocument{file2}
\begin{document}
Label1 is section \ref{label1} in file2.tex.
\end{document}