I am unable to start a new Appium session when setting the capability "automationName: "UiAutomator2". With the exact same settings, I can successfully start a session when setting "automationName" to "UiAutomator1". I understand that this driver is deprecated, so I would like to change my code to use UiAutomator2 as soon as possible. I am using a Honeywell Dolphin CT60 scanner device that runs Android 7.1 to perform my testing.
In Appium desktop, I am setting my capabilities to the following:
{
"deviceName": "Honeywell CT60",
"udid": "19025D8359",
"platformName": "Android",
"platformVersion": "7.1",
"app": "C:\Users\christine.harbour\repos\HoneywellAutomation\Framework\Setup\Apks\Photos.apk",
"automationName": "UiAutomator2"
}
When attempting to start a new driver with these settings, I am getting an error message that says the following:
"The application at 'C:Userschristine.harbourAppDataLocalProgramsAppiumresourcesappnode_modulesappiumnode_modulesappium-uiautomator2-serverapksappium-uiautomator2-server-debug-androidTest.apk' is not writeable. Please grant write permissions to this file or to its parent folder for the Appium process, so it could sign the application."
I have checked the privileges on both this file, and its containing folders, and verified that all users have 'Full control', 'Read', 'Write', 'Modify', and every other permission enabled. I am also an administrator on the machine that I am using. I have tried running desktop Appium.exe as an administrator and received the same error message when starting a new session.
I also receive the same error message both through C# code and in Appium desktop. I am also able to successfully start sessions in Appium desktop and C# when changing "automationName" to "UiAutomator1". My only suspicion is that UiAutomator2 may not support my physical device, Honeywell CT60. I can provide specific drivers for that device if necessary -- I had to install Honeywell-specific drivers on my computer in order for this device to work correctly.
I have also re-installed Appium several times, only to receive the same error message.
I would like to use UiAutomator2 as soon as possible. If you would like any additional details on my setup, please let me know. I have attached the exported Appium error log. As I mentioned, my code runs without issue when using UiAutomator1.
https://gist.github.com/harbourc/56f8317c611359f617917c2b9ed482d0
I have reproduced the error in the appium/sample-code/csharp repo. The file I am testing is TestAndroidCreateSession.cs. I have modified the capabilities in public void BeforeAll() & reproduced the issue as such:
[OneTimeSetUp()]
public void BeforeAll()
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability(MobileCapabilityType.PlatformName, "Android");
capabilities.SetCapability(MobileCapabilityType.PlatformVersion, "7.1");
capabilities.SetCapability(MobileCapabilityType.AutomationName, "UIAutomator2");
capabilities.SetCapability(MobileCapabilityType.DeviceName, "Honeywell CT60");
capabilities.SetCapability(MobileCapabilityType.App, "C:\\Users\\christine.harbour\\Repos\\HoneywellAutomation\\Framework\\Setup\\Apks\\Photos.apk");
capabilities.SetCapability(MobileCapabilityType.Udid, "19025D8359");
driver = new AndroidDriver<AndroidElement>(Env.ServerUri(), capabilities, Env.INIT_TIMEOUT_SEC);
driver.Manage().Timeouts().ImplicitWait = Env.IMPLICIT_TIMEOUT_SEC;
}
The error is produced on the line " driver = new AndroidDriver
It's the problem of Appium Desktop itself. You can use Appium downloaded via npm as a workaround
Thanks for the speedy reply, I really appreciate it.
Is this a workaround for C# as well? I don鈥檛 think I have control over how C# initializes an AndroidDriver, so I鈥檓 not sure how to do that.
This is a known issue. The best workaround is to run Appium from the command line and not use the pre-bundled Appium server.
See https://github.com/appium/appium-desktop#connect-to-local-appium-server
Does this mean that, instead of using something like:
// start appium service
var builder = new AppiumServiceBuilder();
_appiumLocalService = builder.UsingAnyFreePort().Build();
_appiumLocalService.Start();
it would be better to start the Appium server through the command line, and then start the AndroidDriver session by attaching it to the Appium server that was started through CL?
Based on the documentation, I think I understand how to start Appium from CL, but I'm still a bit confused about how starting a new session works here. I am assuming that I can bind my AndroidDriver session to the Appium server that I start through CL. Which means the line:
// start the driver
var driver = new AndroidDriver<AppiumWebElement>(options);
can technically stay the way that it is, as long as I include details about the CL Appium server that was started earlier. Please correct me if I have the wrong idea about this.
File > New Session (in the menu bar)Custom ServerYou can still use
// start appium service
var builder = new AppiumServiceBuilder();
_appiumLocalService = builder.UsingAnyFreePort().Build();
_appiumLocalService.Start();
But then point your session to whatever port that this service is on.
The Desktop explanation makes sense to me, but I am still receiving the same error message as mentioned in my issue description when automationName capability is set to UiAutomator2. I checked with UiAutomator1 as well, to make sure my host & port number were keyed in correctly, and the session successfully started.
Additionally, I am receiving the same error message in C# when starting a new AndroidDriver session as such:
var driver = new AndroidDriver<AppiumWebElement>(_appiumLocalService.ServiceUrl, options);
where _appiumLocalService.ServiceUri is the host and port URI that Appium is running on.
Just to clarify, I've tried:
If there are any additional details I can provide for you, please let me know. I really appreciate your help with this issue.
I won't have time in the near future to troubleshoot this but some things to point you in the right direction:
This is the line of code that's throwing the exception: https://github.com/appium/appium-uiautomator2-driver/blob/6b1ad42163dda1e91a758f9af60319b9e5330258/lib/helpers.js#L19
It's testing fs.access("PATH", fs.access(appPath, _fs.W_OK); to see if APK is writable.
Try commenting out that try -> catch block so it skips the check.
The file is:
<YOUR NPM ROOT>/appium/node_modules/appium-uiautomator2-driver/build/lib/helpers.js
npm -g root.
Try running Appium again with that block commented out.
If that fixes the issue, then we can confirm it's a bug and I'll transfer this issue to appium/appium.
Just an update to this issue, after following instructions above to comment out the try / catch block checking to see if APK is write-able:
Commented out try / catch block checking to see if appium-uiautomator2-server-debug-androidTest.apk is writeable
Received error message complaining that appium-uiautomator2-server-debug-androidTest.apk does not exist
Investigated appium/node_modules/appium-uiautomator2-server directory and noticed appium-uiautomator2-server-debug-androidTest.apk had been changed to (some random string).tmp
Executed npm uninstall -g appium && npm install -g appium to get a 'fresh copy' of missing apk -- it was changed to .tmp file while attempting to start a (failed) new UiAutomator2 sesson
Modified /appium/node_modules/appium-uiautomator2-driver/build/lib/helpers.js and commented out try / catch block that checks for write access
Re-ran Appium C# code with UiAutomator2
Received error message stating An unknown server-side error occurred while processing the command. Original error: Could not sign with default certificate. Original error Command ''C:\\Program Files\\Java\\jdk-12.0.2\\bin\\java.exe' -jar C\:\\Users\\christine.harbour\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-adb\\jars\\sign.jar C\:\\Users\\christine.harbour\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-uiautomator2-server\\apks\\appium-uiautomator2-server-debug-androidTest.apk --override' exited with code 1
The same issue is happening when starting a new AndroidDriver session in C# and also with Appium desktop, even when starting the server manually and pointing new session to that server. Hope this additional info helps.
I am assuming the error is now being thrown on the line await adb.sign(appPath);
Can you try building from master appium/appium?
git clone https://github.com/appium/appium && cd appium
rm -rf node_modules && npm install
node . // runs Appium
@mykola-mokhnach made a fix recently (https://github.com/appium/appium-uiautomator2-driver/pulls?q=is%3Apr+is%3Aclosed) that addresses this.
I followed the above steps where I cloned appium repo & built from master appium/appium, then ran Appium from CL using node .
Attempted to start new session by attaching to the custom Appium server, but received same error message 'Could not sign with the default certificate'
Opened up appium/sample-code/csharp/test.sln and navigated to test > TestAndroidCreateSession.cs, to attempt to run a test directly from the repo
Received error message An unknown server-side error occurred while processing the command. Original error: C:\Users\christine.harbour\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk file doesn't exist.
Navigate to appium\node_modules\appium-uiautomator2-server\apks to look for missing file
Noticed appium-uiautomator2-server-debug-androidTest.apk has been changed to 1568402111461.tmp -- I believe this file name gets changed whenever I encounter the 'Could not sign with the default certificate error'.
In order, here's what I think is happening with that .apk file:
Could not sign with the default certificateappium-uiautomator2-server-debug-androidTest.apk file doesn't exist.I can uninstall and re-install appium through npm to 'reset' the .tmp file back to appium-uiautomator2-server-debug-androidTest.apk, but I think that will just start the 'cycle' over again, where I receive the Could not sign with the default certificate error.
To summarize -- I cloned the Appium repo just a few minutes ago, ensured I was working in the 'master' branch, and attempted to start a new session through CL + Desktop session. After that, I attempted to start a new session through appium/sample-code/csharp/test/TestAndroidCreateSession.cs. Receiving same error messages in both cases. However, I did NOT see the appium-uiautomator2-server-debug-androidTest.apk' is not writeable. Please grant write permissions to this file or to its parent folder for the Appium process, so it could sign the application." error message. So maybe that is some progress.
Apologies for the extremely lengthy explanation, I just want to make sure you are aware of the exact steps I am taking, in case I am doing it wrong.
No problem. Thanks for helping us troubleshoot this.
@mykola-mokhnach do you have any thoughts on this? I'm stumped.
You must either downgrade java to version 8 or set the proper JAVA_HOME value for the Appium process. Android SDK does not support Java versions newer than 8 and there is nothing we can do about it
My JAVA_HOME variable was originally pointing to jdk-12.0.2. I changed JAVA_HOME to point to jdk-1.8.0_211, updated Path to point to jdk-1.8.0, and restarted my computer.
After that, I re-ran my code and I am seeing The file at 'C:\Users\christine.harbour\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk' does not exist or is not accessible. This is because the file is named 1568402111461.tmp when I navigate to the directory to look.
I will attempt to re-install Appium to reset the file to appium-uiautomator2-server-debug-androidTest.apk and see if that helps.
Updates from my previous comment:
Initial steps taken before testing with capability "automationName": "UiAutomator2":
-Verify JAVA_HOME is pointing to jdk-1.8.0_211
-Verify Path is referencing jdk-1.8.0_211
-Verify C:\Users\christine.harbour\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk exists
-Verify new session can be created using automationName = UiAutomator1
Results:
-Session started successfully. Java version was the ultimate culprit for this one. Huge thanks to Appium / Appium desktop devs @mykola-mokhnach and @dpgraham for taking the time to troubleshoot this. Closing this issue, as it is now resolved.
In case anyone else is experiencing this issue -- CHECK YOUR JAVA VERSION! It's tempting to install the latest jdk version but you need to downgrade to 1.8.0 for this to work.
Run appium as administrator.
Read official Docs.
@dreamingtech I did that, and it is clearly stated in the description of this issue. That was not the solution to the problem.
@harbourc yes i can confirm that downgrading to java version "1.8.0_241" solved the problem.
But curious to know what are the reasons for appium not supporting newer JDKs? And also, how can we document that so that anybody setting up an appium server knows to use java 1.8.0? I personally couldnt find any documentation on appium regarding recommended or supported JDK versions...
@tavramov from what I understand, the limitation is with the Android SDK and not with Appium specifically. The response from Appium dev above mentions this.
I do agree that documentation would be helpful, because I was unaware of this limitation until I ran into the issue and opened this ticket. Perhaps you can submit a pull request to the README and include this detail.
Hi @harbourc , I need your help since i saw you had this issue on C# with Appium-Desktop.
I followed your last comments and i still have the issue.
The log from Appium:
Encountered internal error running command: Error: The application at '鈥狢:UsersNameTestApp.apk' does not exist or is not accessible
[debug] [35m[W3C][39m at C:UsersNameAppDataLocalProgramsAppiumresourcesappnode_modulesappiumnode_modulesappium-base-driverlibbasedriverhelpers.js:235:13
[debug] [35m[W3C][39m Destroying socket connection
The code i am using on VS:
`
var appPath = @"鈥狢:UsersMyNameTestApp.apk";
var driverOptions = new AppiumOptions();
driverOptions.AddAdditionalCapability(AutomationName.AndroidUIAutomator2, "Android");
driverOptions.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android");
driverOptions.AddAdditionalCapability(MobileCapabilityType.DeviceName, "Pixel 3a");
driverOptions.AddAdditionalCapability(MobileCapabilityType.App, appPath);
driverOptions.AddAdditionalCapability("chromedriverExecutable", @"鈥狢:\TestLogs\chromedriver.exe");
_driver = new AndroidDriver<AndroidElement>(new Uri("http://localhost:4723/wd/hub"), driverOptions);
`
Any advice here? @mykola-mokhnach @harbourc
Most helpful comment
Updates from my previous comment:
Initial steps taken before testing with capability
"automationName": "UiAutomator2":-Verify JAVA_HOME is pointing to
jdk-1.8.0_211-Verify Path is referencing
jdk-1.8.0_211-Verify
C:\Users\christine.harbour\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apkexists-Verify new session can be created using automationName = UiAutomator1
Results:
-Session started successfully. Java version was the ultimate culprit for this one. Huge thanks to Appium / Appium desktop devs @mykola-mokhnach and @dpgraham for taking the time to troubleshoot this. Closing this issue, as it is now resolved.
In case anyone else is experiencing this issue -- CHECK YOUR JAVA VERSION! It's tempting to install the latest jdk version but you need to downgrade to 1.8.0 for this to work.