def link_android(self, path, pkg):
bundle_id = self.ctx['<STR_LIT>']<EOL>pkg_root = join(path, pkg)<EOL>with open(join('<STR_LIT>', '<STR_LIT>')) as f:<EOL><INDENT>settings_gradle = f.read()<EOL><DEDENT>with open(join('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')) as f:<EOL><INDENT>build_gradle = f.read()<EOL><DEDENT>main_app_java_path = join('<STR_LIT>', '<STR_LIT>', '<STR_LIT:src>', '<STR_LIT>', '<STR_LIT>',<EOL>join(*bundle_id.split("<STR_LIT:.>")),<EOL>'<STR_LIT>')<EOL>with open(main_app_java_path) as f:<EOL><INDENT>main_application_java = f.read()<EOL><DEDENT>try:<EOL><INDENT>new_packages = Link.find_packages(join(path, pkg))<EOL>if not new_packages:<EOL><INDENT>print("<STR_LIT>".format(<EOL>pkg))<EOL>return<EOL><DEDENT>if not Link.is_settings_linked(settings_gradle, pkg):<EOL><INDENT>new_settings = settings_gradle.split("<STR_LIT:\n>")<EOL>new_settings.append("<STR_LIT>")  <EOL>new_settings.append("<STR_LIT>".format(name=pkg))<EOL>new_settings.append("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>.format(name=pkg, path=self.package_dir))<EOL>with open(join('<STR_LIT>', '<STR_LIT>'), '<STR_LIT:w>') as f:<EOL><INDENT>f.write("<STR_LIT:\n>".join(new_settings))<EOL><DEDENT>print("<STR_LIT>".format(pkg))<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>"<EOL>"<STR_LIT>".format(pkg))<EOL><DEDENT>if not Link.is_build_linked(build_gradle, pkg):<EOL><INDENT>new_build = build_gradle.split("<STR_LIT:\n>")<EOL>found = False<EOL>for i, line in enumerate(new_build):<EOL><INDENT>if re.match(r"<STR_LIT>", line):<EOL><INDENT>found = True<EOL>continue<EOL><DEDENT>if found and "<STR_LIT:}>" in line:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if not found:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>".format(pkg=pkg))<EOL><DEDENT>new_build.insert(i, "<STR_LIT>".format(<EOL>name=pkg))<EOL>with open(join('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'), '<STR_LIT:w>') as f:<EOL><INDENT>f.write("<STR_LIT:\n>".join(new_build))<EOL><DEDENT>print("<STR_LIT>".format(pkg))<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>"<EOL>"<STR_LIT>".format(pkg))<EOL><DEDENT>new_app_java = []<EOL>for package in new_packages:<EOL><INDENT>javacls = os.path.splitext(package)[<NUM_LIT:0>].replace("<STR_LIT:/>", "<STR_LIT:.>")<EOL>if not Link.is_app_linked(main_application_java, pkg, javacls):<EOL><INDENT>new_app_java = (new_app_java or<EOL>main_application_java.split("<STR_LIT:\n>"))<EOL>j = <NUM_LIT:0><EOL>for i, line in enumerate(new_app_java):<EOL><INDENT>if fnmatch.fnmatch(line, "<STR_LIT>"):<EOL><INDENT>j = i<EOL><DEDENT><DEDENT>new_app_java.insert(j+<NUM_LIT:1>, "<STR_LIT>".format(javacls))<EOL>j = <NUM_LIT:0><EOL>for i, line in enumerate(new_app_java):<EOL><INDENT>if fnmatch.fnmatch(line.strip(), "<STR_LIT>"):<EOL><INDENT>j = i<EOL><DEDENT><DEDENT>if j == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>".format(javacls))<EOL><DEDENT>else:<EOL><INDENT>new_app_java[j] = new_app_java[j]+ "<STR_LIT:U+002C>"<EOL>new_app_java.insert(j+<NUM_LIT:1>, "<STR_LIT>"<EOL>.format(javacls.split("<STR_LIT:.>")[-<NUM_LIT:1>]))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>print("<STR_LIT>".format(<EOL>pkg, main_app_java_path))<EOL><DEDENT><DEDENT>if new_app_java:<EOL><INDENT>with open(main_app_java_path, '<STR_LIT:w>') as f:<EOL><INDENT>f.write("<STR_LIT:\n>".join(new_app_java))<EOL><DEDENT><DEDENT>print(Colors.GREEN+"<STR_LIT>".format(<EOL>pkg)+Colors.RESET)<EOL><DEDENT>except Exception as e:<EOL><INDENT>print(Colors.GREEN+"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT:{}>".format(pkg, e)+Colors.RESET)<EOL>with open(join('<STR_LIT>', '<STR_LIT>'), '<STR_LIT:w>') as f:<EOL><INDENT>f.write(settings_gradle)<EOL><DEDENT>with open(join('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'), '<STR_LIT:w>') as f:<EOL><INDENT>f.write(build_gradle)<EOL><DEDENT>with open(main_app_java_path, '<STR_LIT:w>') as f:<EOL><INDENT>f.write(main_application_java)<EOL><DEDENT>raise<EOL><DEDENT>
Link's the android project to this library.

        1. Includes this project's directory in the app's 
            android/settings.gradle
            It adds:
                include ':<project-name>'
                project(':<project-name>').projectDir = new File(
                rootProject.projectDir, '../packages/<project-name>/android')

        2. Add's this project as a dependency to the android/app/build.gradle
            It adds:
                compile project(':<project-name>')
            to the dependencies.

        3. If preset, adds the import and package statement
           to the android/app/src/main/java/<bundle/id>/MainApplication.java