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

Allow configuring Gradle, AGP, various SDK and Kotlin versions for Espresso server #496

Merged
merged 23 commits into from
Oct 22, 2019

Conversation

tinder-ktarasov
Copy link
Contributor

@tinder-ktarasov tinder-ktarasov commented Sep 13, 2019

Currently, appium-espresso-driver uses same Gradle, AGP, SDK, and Kotlin versions when building espresso-server for all apps. Such versions might be different from the versions used to build AUT. Such setup is unusual as androidTest APKs are usually built with the same SDKs as the main app. It can lead to various issues as Android building infrastructure is quite complex.
This PR proposes changes that will allow configuring those versions to keep them in sync with the versions in the main app.

To build espresso-server with custom versions forceEspressoRebuild capability should be set to true.
I didn't change anything regarding caching, so I suppose rebuilt APK is not cached and it will be rebuilt even when versions are same.

Unfortunately, it doesn't fix that Resource issue, I'll make a separate PR for it.

New desired capabilities

  • showGradleLog (boolean) - show Gradle build log in the server log
  • espressoBuildConfig (path as a string) - path to build configuration JSON

Build configuration JSON keys
Configuration example:

{
  "toolsVersions": {
    "gradle": "5.1.1",
    "androidGradlePlugin": "3.4.2",
    "compileSdk": 28,
    "buildTools": "28.0.3",
    "minSdk": 18,
    "targetSdk": 28,
    "kotlin": "1.3.31"
  },
  "additionalAppDependencies": [
    "com.google.android.material:material:1.0.0"
  ]
}

Minimum supported versions here and default versions are current versions in espresso-server project (not changed in this PR)

  • toolsVersion - versions of various tools and SDKs used to build espresso-server
    • gradle - version of Gradle to use for building espresso-server
    • androidGradlePlugin - version of Android Gradle Plugin
    • buildTools - Android SDK build tools version
    • compile_sdk_version - compileSdk in build.gradle
    • minSdk - minSdk in build.gradle
    • targetSdk - targetSdk in build.gradle
    • kotlin - Kotlin version
  • additionalAppDependencies - array containing additional dependencies of the tested app that build tools should know about. Items of the array maps to 'implementation' lines in build.gradle. I don't know exact causes but adding 'com.google.android.material:material:1.0.0' here fixes resource related startup issues for some apps.

Possible improvements (not implemented)

  • Cache espresso-server APKs and reuse them when versions are the same
  • Building espresso-server will spawn Gradle daemon process that is not stopped after the build (and will be reused for next builds). Probably some would want to avoid it.

@jsf-clabot
Copy link

jsf-clabot commented Sep 13, 2019

CLA assistant check
All committers have signed the CLA.

lib/driver.js Outdated Show resolved Hide resolved
@mykola-mokhnach
Copy link
Contributor

We will need the feature and all the properties documented properly. https://github.com/appium/appium/tree/master/docs/en/writing-running-appium/android would be a good place to keep the document.

Altogether, I like the implementation, good job.

@KazuCocoa
Copy link
Member

Awesome!

And it's good to add a description about the caps in https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md after finalising this change.

@dpgraham dpgraham changed the title Allow configuring Gradle, AGP, various SDK and Kotlin versions for Espresso server [WIP] Allow configuring Gradle, AGP, various SDK and Kotlin versions for Espresso server Sep 19, 2019
@tinder-ktarasov
Copy link
Contributor Author

I've done some additional testing and found that our app require additional dependency on com.google.android.material:material:1.0.0 in espresso-server. So I'd like to propose this configuration format:

{
  "toolsVersions": {
    "gradle": "5.1.1",
    "androidGradlePlugin": "3.4.2",
    "compileSdk": 28,
    "buildTools": "28.0.3",
    "minSdk": 18,
    "targetSdk": 28,
    "kotlin": "1.3.31"
  }
  "additionalAppDependencies": [// maps to 'implementation' lines in build.gradle
    "com.google.android.material:material:1.0.0"
  ]
}

What do you think?

@KazuCocoa
Copy link
Member

ah, nice. thanks :)
Will it allow to exclude or include as additionalAppDependencies? Or simply just add dependencies?

(I think only adding them is enough so far.)

@hunzai
Copy link

hunzai commented Oct 14, 2019

@mykola-mokhnach @tinder-ktarasov let me know if I can help testing, at least :)

Copy link
Contributor

@mykola-mokhnach mykola-mokhnach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added minor comments, but I like the PR altogether

@mykola-mokhnach
Copy link
Contributor

It is necessary to make the tests green though.

@tinder-ktarasov
Copy link
Contributor Author

@mykola-mokhnach it doesn't look like the failing test case can be affected by these changes. Could you confirm that the test case about pointers is passing on master branch and it is not flaky?

@tinder-ktarasov
Copy link
Contributor Author

@hunzai you could check if additionalAppDependencies part of build configuration (see top comment in this PR) fixes issues with your app. You will need npm link the driver from this branch and restart Appium server to do it.

@mykola-mokhnach
Copy link
Contributor

@tinder-ktarasov Yep, the test is flaky. Restarting the job usually helps to resolve the problem

// if we have an error we want to output the logs
// otherwise the failure is inscrutible
// but do not log expected errors
const ignoreError = IGNORED_ERRORS.some((x) => line.includes(x));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we keep IGNORED_ERRORS array empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For possible future filtering. Removed it now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YAGNI ;)

const ignoreError = IGNORED_ERRORS.some((x) => line.includes(x));

if (this.showGradleLog && !ignoreError) {
gradleLog.error(line);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are all strings in the Gradle log errors? I would rather print them at debug or info level

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably keeping STDERR lines as error (that would be actual errors and task names) and changing other to info would be better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error is still too much. We only mark critical things as error. I would mark them as warnings and normal messages as info

Copy link
Contributor

@dpgraham dpgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Nice work on this @tinder-ktarasov !

@mykola-mokhnach mykola-mokhnach merged commit a402a53 into appium:master Oct 22, 2019
@mykola-mokhnach
Copy link
Contributor

@tinder-ktarasov It would be nice to document the feature properly. You could put the resulting document to https://github.com/appium/appium/tree/master/docs/en/writing-running-appium/android

@tinder-ktarasov
Copy link
Contributor Author

👍
I'm going to work on other tasks for some time. After that I'll work on documenting this feature. That would be next week in the worst case.

@dpgraham
Copy link
Contributor

@tinder-ktarasov do you want an invite to the Appium Slack channel?

@KazuCocoa KazuCocoa mentioned this pull request Dec 7, 2019
10 tasks
@tinder-ktarasov
Copy link
Contributor Author

@mykola-mokhnach @KazuCocoa @dpgraham, sorry for being absent. I've added docs about this feature - appium/appium#13766

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants