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

[Feature request] Can Appium espresso server apk be build without starting the Appium server? #851

Closed
pr4bh4sh opened this issue Jan 24, 2023 · 15 comments

Comments

@pr4bh4sh
Copy link
Contributor

pr4bh4sh commented Jan 24, 2023

I'm trying to find a stand-alone command to build the appium espresso server apk.

Currently, to build a server apk I use the below step.

  1. Clone this repo and run ./gradlew clean assembleDebug assembleAndroidTest inside appium-espresso-driver/espresso-server directory.
  2. Run npm install && npm link in appium-espresso-driver directory.
  3. Add the below additional caps in appium driver caps
  noSign:               false,
  useKeystore:          true,
  keystorePath:         File.expand_path(<keystore_path>),
  keystorePassword:     KEYSTORE_PASSWORD
  keyAlias:             KEYSTORE_ALIAS,
  keyPassword:          KEYSTORE_PASSWORD,
  forceEspressoRebuild: true,
  showGradleLog:        true,
  espressoBuildConfig:    '{"toolsVersions": {"gradle": "7.5.1", "androidGradlePlugin": "7.3.1", "composeVersion": "1.3.1", "compileSdk": "33", "kotlin": "1.7.10"}, "additionalAndroidTestDependencies": ["androidx.compose.ui:ui-test-junit4:1.3.0"]}',
  1. Execute a test so the appium espresso server apk would be generated.

I saw this Gradle command in the appium server log while creating the server apk

/var/folders/jj/0gsw19wd55n8vfrpmc6r961w0000gq/T/appium_temp/0/espresso-server-emulator-5556/gradlew 
-PappiumCompileSdk=32 
-PappiumKotlin=1.6.21 
-PappiumComposeVersion=1.2.1 
-PappiumZipAlign=true 
-PappiumKeystoreFile=pathh_to_kyastore
-PappiumKeystorePassword=password
-PappiumKeyAlias=keyalias 
-PappiumKeyPassword=password
-PappiumTargetPackage=<app_package>
app:assembleAndroidTest' 
in directory '/var/folders/jj/0gsw19wd55n8vfrpmc6r961w0000gq/T/appium_temp/0/espresso-server-emulator-5556'

Is there a command option where the capability can be passed as a command line argument?

or possibly a node js command line tool to build the appium espresso server which accepts the keystore details, espressoBuildConfig and builds the apk file.

cc @KazuCocoa

@KazuCocoa
Copy link
Member

KazuCocoa commented Jan 25, 2023

Sounds good. Let me try to prepare something subcommand to build an espresso server like https://github.com/appium/appium-xcuitest-driver/blob/master/package.json#L34-L35

@KazuCocoa
Copy link
Member

Still wip, but adding like.... https://github.com/appium/appium-espresso-driver/compare/master...KazuCocoa:appium-espresso-driver:kazucocoa/espresso-server-build?expand=1
e.g. TEST_APP_PACKAGE="io.appium.test.app" npm run build:server_js

@jamesvanhorn
Copy link

I'd like to use this for running Espresso automation with a cloud service. I pulled down the change and ran the script. It did build the apk, but executing tests using the built server did not work due to missing grade build dependencies.

How can I execute the build:server_js command and also pass in the espressoBuildConfig?

@jamesvanhorn
Copy link

@pr4bh4sh As a workaround, you can try this.... worked for me for now.

  1. Run an espresso session as normal, allowing Appium to handle build and installation of espresso test server apk.
  2. Find this log statement
  3. Copy the apk from the temp folder to wherever you need it.
Copying built apk from '/var/folders/22/9dxnk2js3274f0l_64mmd8bw0000gn
 /T/espresso-server-RZ8R704ZZCY/app/build/outputs/apk/androidTest/debug
 /app-debug-androidTest.apk' to '/var/folders/22
 /9dxnk2js3274f0l_64mmd8bw0000gn/T/io.appium.espressoserver.test_2.7.0
 _com.example.jetpackcomposeplayground_RZ8R704ZZCY.apk'

I understand this doesn't totally solve your issue of getting the apk without needing to start the Appium server and create a session, but its a couple less steps than your current solution.

@pr4bh4sh
Copy link
Contributor Author

pr4bh4sh commented Feb 28, 2023

Thanks, @jamesvanhorn The simplified steps work fine. The extra step is done to ensure that it picks the local change when making changes in the espresso driver apk.

@pr4bh4sh
Copy link
Contributor Author

@KazuCocoa just checking if you got a chance to look into this feature.

@KazuCocoa
Copy link
Member

I did some other appum stuff, which needs fixes, but I do not forget this

@KazuCocoa
Copy link
Member

The PR #858 is ready.
Available environment variables to configure the build will be https://github.com/appium/appium-espresso-driver/pull/858/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R46

@KazuCocoa
Copy link
Member

2.18.0+ will have https://github.com/appium/appium-espresso-driver#scripts

Currently, it supports gradle log, app package customization and espresso build config.

https://github.com/appium/appium-espresso-driver/blob/master/scripts/build-espresso.js is the change, so feel free to create a pr to add your necessary configs. Basically only environment variables can give

@pr4bh4sh
Copy link
Contributor Author

pr4bh4sh commented Mar 22, 2023

@KazuCocoa Not sure if I should create a new issue or this can be address here, Let me know I'll create a new issue if needed.

I can't run the new build-espresso script, I used the instructions from https://github.com/appium/appium-espresso-driver#scripts

❯ appium -v
2.0.0-beta.57
❯ appium driver list --installed
✔ Listing installed drivers
- espresso@2.18.0 [installed (NPM)]
❯ SHOW_GRADLE_LOG=true TEST_APP_PACKAGE=com.bumble.com ESPRESSO_BUILD_CONFIG=/Users/prabhash/espresso-demo/espresso_build_config.json appium driver run espresso build-espresso
Error: ✖ The driver named 'espresso' does not support the script: 'build-espresso'

print-espresso-path works fine

❯ SHOW_GRADLE_LOG=true TEST_APP_PACKAGE=com.bumble.com ESPRESSO_BUILD_CONFIG=/Users/prabhash/espresso-demo/espresso_build_config.json appium driver run espresso print-espresso-path
/Users/prabhash/.appium/node_modules/appium-espresso-driver/espresso-server
✔ print-espresso-path successfully ran
❯ SHOW_GRADLE_LOG=true TEST_APP_PACKAGE=com.bumble.com ESPRESSO_BUILD_CONFIG=/Users/prabhash/espresso-demo/espresso_build_config.json appium driver run build-espresso
usage: appium driver run [-h] [--json] driver scriptName

appium driver run: error: the following arguments are required: scriptName

espresso-demo directory has nothing inside it except the espresso_build_config.json file.

@KazuCocoa
Copy link
Member

What about 2.18.1? The command had .js as a mistake. The new version dropped it so build-espresso command name should be ok

@pr4bh4sh
Copy link
Contributor Author

Works with 2.18.1, Thanks for fixing it @KazuCocoa.

The issue can be closed now. I'll raise a PR if anything else is required.

@pr4bh4sh
Copy link
Contributor Author

pr4bh4sh commented Mar 23, 2023

For future visitors' reference:

The command introduced in this PR builds the espresso apk without signing it. Use apksigner to sign the espresso server after it is created, rather than trying to pass keys to this command. As this command will log your key and password in the logs.

Sign the apk locally on your machine or if you are using CI use secret env vars so your key and password are not exposed in the logs.

@jamesvanhorn
Copy link

For future visitors' reference:

The command introduced in this PR builds the espresso apk without signing it. Use apksigner to sign the espresso server after it is created, rather than trying to pass keys to this command. As this command will log your key and password in the logs.

Sign the apk locally on your machine or if you are using CI use secret env vars so your key and password are not exposed in the logs.

Can you give an example of how to use apksigner? Not something I have experience with and I’m unsure of the difficulty involved here.

@pr4bh4sh
Copy link
Contributor Author

https://developer.android.com/studio/command-line/apksigner

Example:

apksigner sign --ks path_to.keystore --ks-key-alias <alias> --ks-pass 'pass:<pass>' path_to_espresso_server.apk

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

No branches or pull requests

3 participants