title: Appium desktop server error when starting session could not sign with default certificate
body: <p>I cannot start a new session on my Appium desktop server. I haven't found any fix that works for me. This is my error message:</p>
  
  <pre><code>Encountered internal error running command: Error: Could not sign with 
  default certificate. Original error Command ''C:\\Program 
  Files\\Java\\jdk1.8.0_181\\bin\\java.exe' -jar 'C:\\Program Files 
  (x86)\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium- 
  adb\\jars\\sign.jar' 'C:\\Program Files 
  (x86)\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium- 
  uiautomator2-server\\apks\\appium-uiautomator2-server-v1.12.0.apk' -- 
  override' exited with code 1
  </code></pre>
  
  <p>Logs:</p>
  
  <pre><code>[Appium] Creating new AndroidUiautomator2Driver (v1.12.0) session
  [Appium] Capabilities:
  [Appium]   app: "myapp/path/"
  [Appium]   appActivity: mydeviceActivity
  [Appium]   appPackage: base.apk
  [Appium]   automationName: UiAutomator2
  [Appium]   deviceName: OPPO F1s
  [Appium]   platformName: Android
  [Appium]   platformVersion: 5.1
  [Appium]   newCommandTimeout: 0
  [Appium]   connectHardwareKeyboard: true
  [BaseDriver] Creating session with MJSONWP desired capabilities: {"app":"https://drive.googl...
  [BaseDriver] The following capabilities were provided, but are not recognized by appium: connectHardwareKeyboard.
  [BaseDriver] Session created with session id: a231071d-b167-42f3-9c4c-ffecc32e9076
  ............
  [BaseDriver] Skipping 'https://drive.google..........' caching, because the HEAD response didn't return any valid Last-Modified headers
  [UiAutomator2] Checking whether app is actually present
  [AndroidDriver] Getting Java version
  [AndroidDriver] Java version is: 1.8.0_181
  [ADB] Checking whether adb is present
  [ADB] Found 1 'build-tools' folders under 'C:\Program Files\Android\SDK' (newest first):
  [ADB]     C:/Program Files/Android/SDK/build-tools/28.0.2
  [ADB] Using adb.exe from C:\Program Files\Android\SDK\platform-tools\adb.exe
  [AndroidDriver] Retrieving device list
  [ADB] Trying to find a connected android device
  [ADB] Getting connected devices...
  [ADB] 1 device(s) connected
  [AndroidDriver] Looking for a device with Android '5.1'
  [ADB] Setting device id to SOVW6PUS99999999
  [ADB] Getting device platform........................................
  [ADB] Running 'C:\Program Files\Android\SDK\platform-tools\adb.exe -P 5037 -s SOVW6PUS99999999 shell am force-stop io.appium.uiautomator2.server'
  [ADB] Checking app cert for C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v1.12.0.apk
  [ADB] Using apksigner.bat from C:\Program Files\Android\SDK\build-tools\28.0.2\apksigner.bat
  [ADB] Starting 'C:\Program Files\Android\SDK\build-tools\28.0.2\apksigner.bat' with args 'verify,--print-certs,C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v1.12.0.apk'
  [ADB] 'C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v1.12.0.apk' is not signed with debug cert.
  [ADB] Zip-aligning 'C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v1.12.0.apk'
  [ADB] Checking whether zipalign is present
  [ADB] Using zipalign.exe from C:\Program Files\Android\SDK\build-tools\28.0.2\zipalign.exe
  [ADB] Signing 'C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v1.12.0.apk' with default cert
  [ADB] Starting 'C:\Program Files\Android\SDK\build-tools\28.0.2\apksigner.bat' with args 'sign,--key,C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-adb\keys\testkey.pk8,--cert,C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-adb\keys\testkey.x509.pem,C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v1.12.0.apk'
  [ADB] Cannot use apksigner tool for signing. Defaulting to sign.jar. Original error: Command ''C:\\Program Files\\Android\\SDK\\build-tools\\28.0.2\\apksigner.bat' sign --key 'C:\\Program Files (x86)\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-adb\\keys\\testkey.pk8' --cert 'C:\\Program Files (x86)\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-adb\\keys\\testkey.x509.pem' 'C:\\Program Files (x86)\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-uiautomator2-server\\apks\\appium-uiautomator2-server-v1.12.0.apk'' exited with code 1; StdErr: 'C:\Program' is not recognized as an internal or external command,
  [ADB] operable program or batch file.
  [ADB] 
  [ADB] Resigning apk.
  [UiAutomator2] Deleting UiAutomator2 session
  [UiAutomator2] Deleting UiAutomator2 server session
  [UiAutomator2] Did not get confirmation UiAutomator2 deleteSession worked; Error was: Error: Trying to proxy a session command without session id
  [ADB] Running 'C:\Program Files\Android\SDK\platform-tools\adb.exe -P 5037 -s SOVW6PUS99999999 shell am force-stop base.apk'
  [ADB] Removing forwarded port socket connection: 8200 
  [ADB] Running 'C:\Program Files\Android\SDK\platform-tools\adb.exe -P 5037 -s SOVW6PUS99999999 forward --remove tcp\:8200'
  [ADB] Running 'C:\Program Files\Android\SDK\platform-tools\adb.exe -P 5037 -s SOVW6PUS99999999 forward --remove tcp\:8200'
  [UiAutomator2] Unable to remove port forward 'Error executing adbExec. Original error: 'Command ''C:\\Program Files\\Android\\SDK\\platform-tools\\adb.exe' -P 5037 -s SOVW6PUS99999999 forward --remove tcp\:8200' exited with code 1'; Stderr: 'error: listener 'tcp:8200' not found'; Code: '1''
  [BaseDriver] Event 'newSessionStarted' logged at 1534424157559 (19:55:57 GMT+0700 (SE Asia Standard Time))
  [MJSONWP] Encountered internal error running command: Error: Could not sign with default certificate. Original error Command ''C:\\Program Files\\Java\\jdk1.8.0_181\\bin\\java.exe' -jar 'C:\\Program Files (x86)\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-adb\\jars\\sign.jar' 'C:\\Program Files (x86)\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-uiautomator2-server\\apks\\appium-uiautomator2-server-v1.12.0.apk' --override' exited with code 1
  </code></pre>
  
  <p>EDIT, SOLVED:
  Thanks to <a href="https://stackoverflow.com/users/1198066/ross">Ross</a> I've found out where the problem is.
  I've solved it by changing the path of ANDROID_HOME and JAVA_HOME from <code>C:\Program Files\</code> to <code>C:\PROGRA~1\</code> like it said <a href="https://stackoverflow.com/questions/24904945/command-prompt-error-c-program-is-not-recognized-as-an-internal-or-external-c">here</a>.</p>