-
-
Notifications
You must be signed in to change notification settings - Fork 170
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
Introduce apks support #367
Conversation
lib/helpers.js
Outdated
async function unzipFile (zipPath) { | ||
log.debug(`Unzipping ${zipPath}`); | ||
async function unzipFile (zipPath, dstRoot = null) { | ||
dstRoot = dstRoot || path.dirname(zipPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done in the default parameter
async function unzipFile (zipPath, dstRoot = path.dirname(zipPath)) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok to use other arguments in default value calculation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as long as they are later in the argument list. So
function a (b = c, c) {
console.log(b, c);
}
would fail if you called a(undefined, 1)
, with a reference error, because c
would not have been defined when b
is initialized to it.
But, for every situation, the follow is fine:
function a (b, c = b) {
console.log(b, c);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, fixed
@KazuCocoa Would you like to run some tests on this PR? |
…into apks_support # Conflicts: # lib/tools/apk-signing.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Of course. I'll take a look & test
`the current API level ${apiLevel} does not support applications ` + | ||
`permissions customization`); | ||
} else { | ||
additionalArgs.push('-g'); | ||
} | ||
} | ||
|
||
if (appPath.endsWith(APKS_EXTENSION)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
The installation depends on device environment. Configuring device env, including language preference, is called in first step in startAndroidSession
. The bundle-install command doesn't install unused languages resources.
https://github.com/appium/appium-android-driver/blob/2bac1672019be24c74fec7b4b5e4301558bfcb66/lib/driver.js#L234
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in theory we could additionally install these language resources manually or change the setup flow sequence. Which way does look more convenient to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KazuCocoa I've changed the way we install apks. Now it is much more customizable.
lib/helpers.js
Outdated
* @returns {string} The calculated hash as hexadecimal string | ||
* @throws {Error} If hash calculation fails | ||
*/ | ||
async function fileHash (filePath, algorithm = 'sha1') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feels like this should be in appium-support?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
into which submodule of appium-support it would be better to put it? util or fs?
additionalArgs.push('-g'); | ||
} | ||
} | ||
options = Object.assign({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object.assign
mutates, dunno if that changes how you'd want to use it here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we just assign the default values to options. The argument dictionary itself is not mutated, but a new copy is created
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right, only the target is mutated and in this case it's an object literal
lib/tools/apks-utils.js
Outdated
* | ||
* @param {string} apks - The full path to the .apks file | ||
* @param {string|Array<String>} dstPath - The relative path to the destination file, | ||
* which is going to be extract3ed, where each path component is an array item |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extracted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks good to me. I'll install real apks
after my work.
lib/tools/apks-utils.js
Outdated
await this.execBundletool(args, `Cannot extract the application bundle at '${apks}'`); | ||
const installArgs = buildInstallArgs(await this.getApiLevel(), options); | ||
const apksToInstall = (await fs.readdir(tmpRoot)) | ||
.filter((name) => name.endsWith('.apk')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nits]
Is it better to define .apk
const like APKS_EXTENSION?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense
lib/tools/apks-utils.js
Outdated
.filter((name) => name.endsWith('.apk')) | ||
.map((name) => path.resolve(tmpRoot, name)); | ||
log.debug(`Got the following apk files to install: ${JSON.stringify(apksToInstall)}`); | ||
const output = await this.adbExec(['install-multiple', ...installArgs, ...apksToInstall], { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the install apks has unsuitable architecture, installing apks fail. (adb install
failed before. It happen if users use ML related libraries, for example.)
base-vi.apk 11K
base-x86.apk 483K
base-x86_64.apk 453K
base-xhdpi.apk 2.4M
What about add considering abis?
=> ah, we use '--device-spec', specPath,
. nice 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. also this strategy allows to alter the actual spec set if, for example, we need to install more locales, by just modifying the spec json
lib/tools/adb-commands.js
Outdated
*/ | ||
methods.initBundletool = async function () { | ||
try { | ||
const bundletoolPath = await fs.which('bundletool.jar'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should export the path to 'bundletool.jar', right? 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. bundletool.jar binary should be in any of folders enumerated in system PATH
I've implemented https://github.com/KazuCocoa/AppBundleSample/blob/master/test.rb and run it to make sure the behaviour. Then, I noticed below three points.
|
Regarding p1 I will try to do some internal testing and check on what can be done there. For p2 should be an easy fix. Many thanks for help on this |
Yes, but it's the final way, I believe.
|
I would just assume this is the main purpose of bundling, that we only install the necessary resources. So it would be logically to assume we need to reinstall the app in order to get the new locale from the bundle (real users would also have to do the same in case of apks). Also, sometimes full reset might be even faster than soft reset, since it does not require to set permissions on the package (these are set during installation) |
ah, it's reasonable to enable fullReset for |
@KazuCocoa Are you fine with merging this PR in the current state or you'd like to add something? |
Let me run the test again once with fullRest cap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worked perfectly 👍 Thanks!
This PR continues what was started by @KazuCocoa in #366
the main idea behind the current implementation is to introduce .apks format support without making additional changes in the depending driver modules (aka it should simply work).