Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored targetSdkVersionFromManifest #187

Merged
merged 1 commit into from
Dec 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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