Skip to content

Commit

Permalink
Refactored targetSdkVersionFromManifest
Browse files Browse the repository at this point in the history
  • Loading branch information
sravanmedarapu committed Dec 6, 2016
1 parent f2876e6 commit 478d97e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/tools/android-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ manifestMethods.targetSdkVersionFromManifest = async function (localApk) {
let args = ['dump', 'badging', localApk];
let {stdout} = await exec(this.binaries.aapt, args);
let targetSdkVersion = new RegExp(/targetSdkVersion:'([^']+)'/g).exec(stdout);
if (!targetSdkVersion) {
throw new Error(`targetSdkVersion is not specified in the application.`);
}
return parseInt(targetSdkVersion[1], 10);
} catch (e) {
log.errorAndThrow(`targetSdkVersionFromManifest failed. Original error: ${e.message}`);
log.errorAndThrow(`fetching targetSdkVersion from local APK failed. Original error: ${e.message}`);
}
};

Expand Down
10 changes: 8 additions & 2 deletions lib/tools/apk-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,14 @@ apkUtilsMethods.install = async function (apk, replace = true, timeout = 60000)
}
if (apk.includes('.apk')) {
let apiLevel = await this.getApiLevel();
let targetSdk = await this.targetSdkVersionFromManifest(apk);
if (apiLevel >= 23 && targetSdk >= 23) {
let targetSdk = null;
try {
targetSdk = await this.targetSdkVersionFromManifest(apk);
} catch (e) {
//avoiding logging error stack, as calling library function would have logged
log.warn(`Ran into problem getting target SDK version; ignoring...`);
}
if (apiLevel >= 23 && (!targetSdk || targetSdk >= 23)) {
await this.grantAllPermissions(await this.getPackageName(apk));
}
}
Expand Down

0 comments on commit 478d97e

Please sign in to comment.