parse apk and return manifest
@param  {String} apkPath apk path
@param  {String} target target extract dir, default to ${os.tmpdir()}/apktoolDecodes
@return {Promise} resolve manifest
485260
async function parse(apkPath, target = `${os.tmpdir()}/apktoolDecodes`) {
  const cmd = `java -jar ${apktoolPath} d ${apkPath} -f -o ${target}`
  await shell(cmd)
  const MainfestFilePath = `${target}/AndroidManifest.xml`
  const doc = await parseManifest(MainfestFilePath)
  return parseDoc(doc)
}
1104996
function determineTargetDir(source, target) {
	return stat(source).
		then(results => results.isDirectory() ? target : path.dirname(target));
}
1332255
public static String getManifestXml(String apkFilePath, Locale locale) throws IOException {
        try (ApkFile apkFile = new ApkFile(apkFilePath)) {
            apkFile.setPreferredLocale(locale);
            return apkFile.getManifestXml();
        }
    }
686913
public Content getTargetPackageLink(PackageElement pkg, String target,
            Content label) {
        return getHyperLink(pathString(pkg, DocPaths.PACKAGE_SUMMARY), label, "", target);
    }
850819
async function getTargetEngines(asset, isTargetApp) {
  let targets = {};
  let path = isTargetApp
    ? Path.join(asset.options.rootDir, 'index')
    : asset.name;
  let compileTarget =
    asset.options.target === 'browser' ? 'browsers' : asset.options.target;
  let pkg = await asset.getConfig(['package.json'], {path});
  let engines = pkg && pkg.engines;
  let nodeVersion = engines && getMinSemver(engines.node);

  if (compileTarget === 'node') {
    // Use package.engines.node by default if we are compiling for node.
    if (typeof nodeVersion === 'string') {
      targets.node = nodeVersion;
    }
  } else {
    if (
      engines &&
      (typeof engines.browsers === 'string' || Array.isArray(engines.browsers))
    ) {
      targets.browsers = engines.browsers;
    } else if (pkg && pkg.browserslist) {
      targets.browsers = pkg.browserslist;
    } else {
      let browserslist = await loadBrowserslist(asset, path);
      if (browserslist) {
        targets.browsers = browserslist;
      } else {
        let babelTargets = await loadBabelrc(asset, path);
        if (babelTargets && babelTargets.browsers) {
          targets.browsers = babelTargets.browsers;
        } else if (babelTargets && babelTargets.node && !nodeVersion) {
          nodeVersion = babelTargets.node;
        }
      }
    }

    // Fall back to package.engines.node for node_modules without any browser target info.
    if (!isTargetApp && !targets.browsers && typeof nodeVersion === 'string') {
      targets.node = nodeVersion;
    }
  }

  // If we didn't find any targets, set some default engines for the target app.
  if (
    isTargetApp &&
    !targets[compileTarget] &&
    DEFAULT_ENGINES[compileTarget]
  ) {
    targets[compileTarget] = DEFAULT_ENGINES[compileTarget];
  }

  // Parse browser targets
  if (targets.browsers) {
    if (
      typeof targets.browsers === 'object' &&
      !Array.isArray(targets.browsers)
    ) {
      let env = asset.options.production
        ? 'production'
        : process.env.NODE_ENV || 'development';
      targets.browsers = targets.browsers[env] || targets.browsers.defaults;
    }

    if (targets.browsers) {
      targets.browsers = browserslist(targets.browsers).sort();
    }
  }

  // Dont compile if we couldn't find any targets
  if (Object.keys(targets).length === 0) {
    return null;
  }

  return targets;
}
105027
function elixir(file, buildDirectory) {
        if (!buildDirectory) {
            buildDirectory = 'build';
        }

        var manifestPath = path.join(publicPath(buildDirectory), 'rev-manifest.json');
        var manifest = require(manifestPath);


        if (isset(manifest[file])) {
            return '/'+ str.trim(buildDirectory + '/' + manifest[file], '/');
        }


        throw new Error("File " + file + " not defined in asset manifest.");
    }
804008
public static boolean isPackageInstalled(Context context, String targetPackage) {
        PackageManager manager = context.getPackageManager();
        Intent intent = new Intent();
        intent.setPackage(targetPackage);
        return manager.resolveActivity(intent, 0) != null;
    }
1138936
function targetPath(fromPath, basePath, targetDirectory) {
  // console.log('targetPath:fromPath: ' + fromPath);
  // console.log('targetPath:basePath: ' + basePath);
  // console.log('targetPath:targetDirectory: ' + targetDirectory);
  var relativePath = path.relative(basePath, fromPath);
  // console.log('targetPath:relativePath: ' + relativePath);
  // console.log('targetPath: ' + path.resolve(targetDirectory, relativePath));
  return path.resolve(targetDirectory, relativePath);
}
566898
function renamePackageFiles () {
  return new Promise((resolve) => {
    const parents = 'android/app/src/main/java/'
    const oldPath = fullPath(parents + oldInfo.packageID.split('.').join('/'))
    const newPath = fullPath(parents + newInfo.packageID.split('.').join('/'))

    console.log('Renaming android path...')
    console.log(`From ${relative(oldPath)}`)
    fs.renameSync(oldPath, newPath)
    console.log(`  to ${relative(newPath)}`)

    resolve()
  })
}
936509
function parseFile(target) {
  return new Promise((resolve, reject) => {
    fs.readFile(target, 'utf8', (err, data) => {
      if (err) reject(err)
      // const doc = parser.parseFromString(data, 'application/xml')
      const doc = cheerio.load(data, { xmlMode: true })
      resolve(doc)
    })
  })
}
233285
function(project_dir) {
        var mDoc = xml_helpers.parseElementtreeSync(path.join(project_dir, 'AndroidManifest.xml'));

        return mDoc._root.attrib['package'];
    }
1293618
function (abspath, targetFilePath, pattern, files, staticBlock) {
        if (targetFilePath in files) {
            grunt.warn('In the file: ' + abspath + ', the target filename: ' + targetFilePath + ' has already defined in this or other html template file.');
        }
        var results = staticBlock.match(pattern);
        if (results) {
            files[targetFilePath] = [];
            for (var index in results) {
                // results[index] could be like below, use staticPattern to fetch real static filepath further.
                // <link href="${request.static_url('zuoyeproject:static/css/bootstrap.css')}" rel="stylesheet" media="screen">
                // <script src="${request.static_url('zuoyeproject:static/editor/common.js')}">
                var result = results[index].match(applyminGlobal.staticPattern);
                if (result === null || result.length < 2) {
                    grunt.warn('Please check whether your "options.staticPattern": ' + applyminGlobal.staticPattern + '\n\ncould be used to fetch the static resource:\n\n' + results[index] + '\n\nin the file ' + '"' + abspath + '"');
                }
                if (!grunt.file.exists(result[1])) {
                    grunt.warn('This file does not exist: "' + result[1] + '"');
                }
                files[targetFilePath].push(result[1]);
            }
        }
    }
580143
function fetchArchive(targetPath, template) {
  var q = Q.defer();
  var replace = require("replace");

  var archiveUrl = template.repo
  // The folder name the project will be downloaded and extracted to
  var message = ['Downloading:'.bold, archiveUrl].join(' ');
  console.log(message);

  var tmpFolder = os.tmpdir();
  var tempZipFilePath = path.join(tmpFolder, 'mobilecaddy-' + new Date().getTime());

  new Download({mode: '755', extract: true})
    .get(archiveUrl)
    .dest(tempZipFilePath)
    .run(function (err, files) {
        if (!err) {
          fs.rename(files[0].path, targetPath,
            function(res){
              if (!res) {
                replace({
                    regex: template.name,
                    replacement: targetPath,
                    paths: [targetPath],
                    recursive: true,
                    silent: true,
                });
                q.resolve();
              } else {
                console.error('Renaming template repo failed '.error);
                console.error(res);
                q.reject(res);
              }
            })
        } else {
          console.error(err);
          q.reject(err);
        }
    });

  return q.promise;
}
57778
function downloadTools(toolDirName) {
	if(!toolDirName){
		toolDirName = 'platform-tools';
	}
	return new Promise((resolve, reject) =>{
		const androidToolZipPath = path.join(WORKING_DIRECTORY, 'android-sdk.zip');
		const androidToolDir = path.join(WORKING_DIRECTORY, toolDirName);
		const downloadUrl = helper.getOSUrl();
		console.log(`Downloading Android platform tools from: ${downloadUrl}`);
		const requestOptions = {timeout: 30000, 'User-Agent': helper.getUserAgent()};
		request(downloadUrl, requestOptions)
			.on('error', (error)  => {
				debug(`Request Error ${error}`);
				reject(error);
			})
			.on('response', (response)  => {
				const len = parseInt(response.headers['content-length'], 10);
				let bar = new ProgressBar('  downloading [:bar] :percent :etas', {
					complete: '=',
					incomplete: ' ',
					width: 20,
					total: len
				});

				response.on('data', function (chunk) {
					if (chunk.length){
						bar.tick(chunk.length);
					}
				});

				response.on('end', function () {
					console.log('\n');
				});
				debug(response.statusCode);
				debug(response.headers['content-type']);
			})
			.pipe(fs.createWriteStream(androidToolZipPath))
			.on('finish', ()  => {
				debug('wstream finished');
				console.log('Extracting Android SDK');
				extract(androidToolZipPath, {dir: WORKING_DIRECTORY},(error) =>{
					if(error){
						debug(`Extraction failed: ${error}`);
						reject(error);
					} else{
						console.log('Extraction complete');
						debug('downloadSDK complete');
						if(zipCache !== null){
							resolve({path:androidToolDir, message:'downloadSDK complete', zipPath:androidToolZipPath});
							return;
						}
						fs.remove(androidToolZipPath, err => {
							if (err) {
								console.error(`removing zip file failed: ${err}`);
								reject(err);
							} else {
								console.log('Removed platform-tools zip file, please specify ADB_ZIP_CACHE if you wish to keep it');
								resolve({path:androidToolDir, message:'downloadSDK complete'});
							}
						});
					}
				});
			});
	});
}
1224363
function parse_targets (targets) {
    debug('Parse: parse targets');
    for (let i = 0; i < targets.length; i++) {
        const target = targets[i];
        const name   = path.basename(target);
        if (is_special(name)) {
            special_targets.push(target);
            continue;
        }
        parse_target(target);
    }
}
174663
function checkSourceInfo () {
  return new Promise((resolve, reject) => {
    let ok = pjson.name === oldInfo.packageName
    ok = ok && readSync('android/app/src/main/AndroidManifest.xml').includes(`package="${oldInfo.packageID}"`)

    if (!ok) {
      reject(new Error('The App name is already modified.'))
      return
    }

    console.log()
    console.log('---------------------------------------------------------')
    console.log('New project parameters:')
    console.log('---------------------------------------------------------')
    console.log('App display name :', newInfo.appName)
    console.log('Project name     :', newInfo.projectName)
    console.log('Package name     :', newInfo.packageName)
    console.log('Package id       :', newInfo.packageID)
    console.log('---------------------------------------------------------')

    let r = null
    try {
      r = readline.createInterface({
        input: process.stdin,
        output: process.stdout,
      })
      r.question('Is this correct?', (answer) => {
        r.close()
        resolve(answer)
      })
    } catch (e) {
      if (r) {
        r.close()
      }
      reject(e)
    }
  })
}
1136299
function resolveApp(dir) {
  if (path.isAbsolute(dir)) return dir;
  return path.join(process.cwd(), dir);
}