1
votes

I am using this code and not able to start app to my mobile device

package Mobileapp1;
.
.
import io.appium.java_client.remote.MobileCapabilityType;

public class Apptesting
{
    public static void main(String[] args) throws MalformedURLException
    {
    DesiredCapabilities c=new DesiredCapabilities();
    c.setCapability(CapabilityType.BROWSER_NAME, "");
    c.setCapability("deviceName", "ZZ2222HMLF");
    c.setCapability("platformName", "Android");
    c.setCapability("platformversion", "7.0");
    c.setCapability(MobileCapabilityType.APP, "D:\\Appium\\edTheSIS_11_02_2019.apk");
    c.setCapability("noReset", true);
    c.setCapability("autoGrantPermissions", "true");
    c.setCapability("appPackage","com.sisapp.in.sisapp");
    //c.setCapability("appPackage","com.sisapp.in.sisapp.SplashActivity"); Tried not working same issue
    c.setCapability("appActivity", "SplashActivity");
    //c.setCapability("appActivity",".md5b1afd03e09ce5243fd0287b176ff38ea.MainActivity");
    URL U=new URL("http://127.0.0.1:4723/wd/hub");
    WebDriver driver=new AndroidDriver(U,c);
    //driver.findElement(By.linkText("Username")).sendKeys("as@ct");
    }
}

TLDR:

Original error: Activity name '.SplashActivity' used to start the app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity

Below is my error log

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Exception in thread "main" org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Cannot start the 'com.sisapp.in.sisapp' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Cannot start the 'com.sisapp.in.sisapp' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Activity name '.SplashActivity' used to start the app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:14.666Z' System info: host: 'DELL30', ip: '10.10.4.222', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_151' Driver info: driver.version: AndroidDriver remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Cannot start the 'com.sisapp.in.sisapp' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Cannot start the 'com.sisapp.in.sisapp' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Activity name '.SplashActivity' used to start the app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity at getResponseForW3CError (C:\Users\arvind\AppData\Local\appium-desktop\app-1.10.0\resources\app\node_modules\appium-base-driver\lib\protocol\errors.js:826:9) at asyncHandler (C:\Users\arvind\AppData\Local\appium-desktop\app-1.10.0\resources\app\node_modules\appium-base-driver\lib\protocol\protocol.js:447:37) at process._tickCallback (internal/process/next_tick.js:68:7) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57) at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104) at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123) at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source) at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source) at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source) at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source) at java.util.stream.AbstractPipeline.copyInto(Unknown Source) at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source) at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source) at java.util.stream.AbstractPipeline.evaluate(Unknown Source) at java.util.stream.ReferencePipeline.findFirst(Unknown Source) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142) at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142) at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:83) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:93) at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:72) at Mobileapp1.Apptesting.main(Apptesting.java:29)

3

3 Answers

3
votes

If you are using app capability, you don't need to specify appPackage and appActivity capability. Also if you are not testing native app browserName capability is not required.

DesiredCapabilities c=new DesiredCapabilities();
c.setCapability("deviceName", "ZZ2222HMLF");
c.setCapability("platformName", "Android");
c.setCapability("app", "D:\\Appium\\edTheSIS_11_02_2019.apk");
c.setCapability("noReset", true);
c.setCapability("autoGrantPermissions", "true");
URL U=new URL("http://127.0.0.1:4723/wd/hub");
AppiumDriver<MobileElement> driver=new AndroidDriver(U,c);

If you want to know the appPackage and appActivity of your app you can connect your device to computer, open the app and run following commands:

adb shell
dumpsys window windows | grep -E 'mFocusedApp'

This will show your appActivity and appPackage. To know more about it you can check this link.

1
votes

For me using the full path of the "appActivity" usually works:

c.setCapability("appPackage","com.sisapp.in.sisapp.SplashActivity");

Or maybe your start activity has a different name. Then try to find out the real name of the current activity after you launched the app manually via ADB:

adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'

or

adb shell dumpsys activity
1
votes

Try below mentioned dependencies, you can launch the application without mentioning the MainActivity.

  1. Make sure that the Appium server is running prior executing your code
  2. To verify you can use Appium inspector session and put the desired capabilities, try to launch a session. That is the most reliable and easy way to verify your desired capabilities.

    DesiredCapabilities cap = new DesiredCapabilities();
    File appDir = new File("Folder path to .apk file location");
    File newApp = new File (appDir ,"Project.apk" );
    
            /* ANDROID DEPENDENCIES START*/
    
            cap.setCapability(CapabilityType.BROWSER_NAME, "");
            cap.setCapability("deviceName", "Nexus5XAPI26");
            cap.setCapability("udid", "YourDeviceUDID");
            cap.setCapability("platformName", "Android");
            cap.setCapability("platformVersion","7.1.1");
            cap.setCapability("automationName", "UiAutomator2");
            cap.setCapability("app", newApp.getAbsolutePath());
    
            /* ANDROID DEPENDENCIES END */
    
    cap.setCapability("app", newApp.getAbsolutePath());
    appDriver = new AppiumDriver(new URL("http://0.0.0.0:4723/wd/hub"), cap);