diff --git a/lib/tools/android-manifest.js b/lib/tools/android-manifest.js index 23eb34fba..8c409cadb 100644 --- a/lib/tools/android-manifest.js +++ b/lib/tools/android-manifest.js @@ -96,10 +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.warn(`Ran into problem getting target SDK; ignoring: ${e.message}`); - return null; + log.errorAndThrow(`fetching targetSdkVersion from local APK failed. Original error: ${e.message}`); } }; diff --git a/lib/tools/apk-utils.js b/lib/tools/apk-utils.js index 1419b800d..c19002480 100644 --- a/lib/tools/apk-utils.js +++ b/lib/tools/apk-utils.js @@ -193,7 +193,13 @@ apkUtilsMethods.install = async function (apk, replace = true, timeout = 60000) } if (apk.includes('.apk')) { let apiLevel = await this.getApiLevel(); - let targetSdk = await this.targetSdkVersionFromManifest(apk); + 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)); }