weixin_39531183
weixin_39531183
2021-01-08 13:06

appium-uiautomator2-server-debug-androidTest.apk is not writeable, could not sign with the default certificate (SOLVED)

The problem

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.

Environment

  • Appium version (or git revision) that exhibits the issue: 1.14.2
  • Last Appium version that did not exhibit the issue (if applicable):
  • Desktop OS/version used to run Appium: Windows 10
  • Node.js version (unless using Appium.app|exe): 10.16.3
  • Npm or Yarn package manager: Npm
  • Mobile platform/version under test: Android 7.1
  • Real device or emulator/simulator: Real device - Honeywell Dolphin CT60
  • Appium CLI or Appium.app|exe: Appium.exe

Details

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:\Users\christine.harbour\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\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."

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.

Link to Appium logs

https://gist.github.com/harbourc/56f8317c611359f617917c2b9ed482d0

Code To Reproduce Issue [ Good To Have ]

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(Env.ServerUri(), capabilities, Env.INIT_TIMEOUT_SEC); "

该提问来源于开源项目:appium/appium-desktop

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

20条回答

  • weixin_39613540 weixin_39613540 4月前

    It's the problem of Appium Desktop itself. You can use Appium downloaded via npm as a workaround

    点赞 评论 复制链接分享
  • weixin_39531183 weixin_39531183 4月前

    Thanks for the speedy reply, I really appreciate it.

    Is this a workaround for C# as well? I don’t think I have control over how C# initializes an AndroidDriver, so I’m not sure how to do that.

    点赞 评论 复制链接分享
  • weixin_39685024 weixin_39685024 4月前

    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

    点赞 评论 复制链接分享
  • weixin_39531183 weixin_39531183 4月前

    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.

    点赞 评论 复制链接分享
  • weixin_39685024 weixin_39685024 4月前
    • Start Appium from the command line
    • Start a new session using File > New Session (in the menu bar)
    • Select Custom Server
    • Enter host and port
    点赞 评论 复制链接分享
  • weixin_39685024 weixin_39685024 4月前

    You 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.

    点赞 评论 复制链接分享
  • weixin_39531183 weixin_39531183 4月前

    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:

    • Starting Appium from command line, then starting new session pointing to that instance
    • Passing host / port number URI into AndroidDriver session create

    If there are any additional details I can provide for you, please let me know. I really appreciate your help with this issue.

    点赞 评论 复制链接分享
  • weixin_39685024 weixin_39685024 4月前

    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
    </your>

    can be found with 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.

    点赞 评论 复制链接分享
  • weixin_39531183 weixin_39531183 4月前

    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:

    1. Commented out try / catch block checking to see if appium-uiautomator2-server-debug-androidTest.apk is writeable

    2. Received error message complaining that appium-uiautomator2-server-debug-androidTest.apk does not exist

    3. Investigated appium/node_modules/appium-uiautomator2-server directory and noticed appium-uiautomator2-server-debug-androidTest.apk had been changed to (some random string).tmp

    4. 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

    5. Modified /appium/node_modules/appium-uiautomator2-driver/build/lib/helpers.js and commented out try / catch block that checks for write access

    6. Re-ran Appium C# code with UiAutomator2

    7. 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);

    点赞 评论 复制链接分享
  • weixin_39685024 weixin_39685024 4月前

    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
    

    -mokhnach made a fix recently (https://github.com/appium/appium-uiautomator2-driver/pulls?q=is%3Apr+is%3Aclosed) that addresses this.

    点赞 评论 复制链接分享
  • weixin_39531183 weixin_39531183 4月前

    I followed the above steps where I cloned appium repo & built from master appium/appium, then ran Appium from CL using node .

    1. Attempted to start new session by attaching to the custom Appium server, but received same error message 'Could not sign with the default certificate'

    2. Opened up appium/sample-code/csharp/test.sln and navigated to test > TestAndroidCreateSession.cs, to attempt to run a test directly from the repo

    3. 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.

    4. Navigate to appium\node_modules\appium-uiautomator2-server\apks to look for missing file

    5. 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:

    • Attempt to start new session using UiAutomator2
    • Receive error Could not sign with the default certificate
    • Attempt to start new session using UiAutomator2 again
    • Receive error appium-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.

    点赞 评论 复制链接分享
  • weixin_39685024 weixin_39685024 4月前

    No problem. Thanks for helping us troubleshoot this.

    -mokhnach do you have any thoughts on this? I'm stumped.

    点赞 评论 复制链接分享
  • weixin_39613540 weixin_39613540 4月前

    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

    点赞 评论 复制链接分享
  • weixin_39531183 weixin_39531183 4月前

    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.

    点赞 评论 复制链接分享
  • weixin_39531183 weixin_39531183 4月前

    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 -mokhnach and 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.

    点赞 评论 复制链接分享
  • weixin_39739170 weixin_39739170 4月前

    Run appium as administrator. Read official Docs.

    点赞 评论 复制链接分享
  • weixin_39531183 weixin_39531183 4月前

    I did that, and it is clearly stated in the description of this issue. That was not the solution to the problem.

    点赞 评论 复制链接分享
  • weixin_39643679 weixin_39643679 4月前

    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...

    点赞 评论 复制链接分享
  • weixin_39531183 weixin_39531183 4月前

    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.

    点赞 评论 复制链接分享
  • weixin_39520353 weixin_39520353 4月前

    Hi , 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 '‪C:\Users\Name\TestApp.apk' does not exist or is not accessible [debug] [35m[W3C][39m at C:\Users\Name\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\helpers.js:235:13 [debug] [35m[W3C][39m Destroying socket connection

    The code i am using on VS: ` var appPath = @"‪C:\Users\MyName\TestApp.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", @"‪C:\TestLogs\chromedriver.exe");
    
            _driver = new AndroidDriver<AndroidElement>(new Uri("http://localhost:4723/wd/hub"), driverOptions);
    

    `

    Any advice here? -mokhnach

    点赞 评论 复制链接分享

相关推荐