Appium真机启动应用后脚本无法继续及uiautomator2签名报错求助
Hi there, let's work through these two frustrating Appium issues you're hitting on your real device. I'll break down each problem with likely causes and actionable fixes:
1. Script Halts After Application Launch
It's super common for scripts to get stuck right after the app opens—usually this happens because Appium can't detect that the app is fully loaded, or there's a block like a permission popup in the way. Here's what to try:
Verify your Desired Capabilities: Make sure
appWaitPackageandappWaitActivityare set to match your app's actual package and main activity. For example:capabilities.setCapability("appWaitPackage", "com.your.app.package"); capabilities.setCapability("appWaitActivity", "com.your.app.package.MainActivity");If your app has multiple splash screens or entry activities, you can use a wildcard like
com.your.app.package.*to cover all possible launch activities.Add wait strategies: Increase implicit wait time to give the app enough time to load:
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);Or use an explicit wait for a key UI element that appears once the app is ready:
WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("your_element_id")));Auto-grant permissions: Enable the
autoGrantPermissionscapability to let Appium automatically accept any permission popups on launch:capabilities.setCapability("autoGrantPermissions", true);Check device settings: Double-check that USB debugging is enabled on your device, and you've allowed the computer to connect to the device (you might see a popup on the device the first time you connect). Also ensure "Install unknown apps" is enabled for your computer's connection.
2. 'Cannot use apksigner tool for signing.' Error with UIAutomator2
That exit code 20 error with apksigner typically points to a compatibility issue between the build tools version you're using and the UIAutomator2 server APK, or a problem with the signing keys. Here's how to fix it:
Update Android Build Tools: The 28.0.3 build tools version you're using might be outdated and incompatible with the newer UIAutomator2 server. Open Android Studio's SDK Manager, go to the "SDK Tools" tab, and install a newer stable version (like 30.0.3 or 33.0.2). Then make sure Appium is using this updated version—you can confirm the path in your Appium logs or set the
ANDROID_HOMEenvironment variable to point to your SDK root.Re-sign the UIAutomator2 server APK manually: Sometimes the pre-signed APK from Appium has issues. Grab the testkey files from your Appium installation path and re-sign the server APK with your updated apksigner tool:
/Users/tapan.khimani/Library/Android/sdk/build-tools/[NEW_VERSION]/apksigner sign --key /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-adb/keys/testkey.pk8 --cert /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-adb/keys/testkey.x509.pem /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v4.3.0.apkReplace
[NEW_VERSION]with the updated build tools version you installed.Reinstall the UIAutomator2 server module: Corrupted module files can cause this issue. If you're using a local Appium installation, uninstall and reinstall the module via npm:
npm uninstall appium-uiautomator2-server npm install appium-uiautomator2-serverIf you're using the Appium desktop app, try reinstalling the app itself to get fresh copies of all dependencies.
Check file permissions: Ensure the testkey.pk8 and testkey.x509.pem files have read permissions. Fix this with:
chmod 644 /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-adb/keys/testkey.pk8 chmod 644 /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-adb/keys/testkey.x509.pem
内容的提问来源于stack exchange,提问作者Tapan Khimani

