How to automate an already installed andoird app on my device?

I want to automate an already installed third-party app which is on mu android device.

How can I set the app path in my java client code?

I saw a post:

unless your phone is rooted, you cannot access /data/app/ where installed applications are present , this path is protected.

How can I still run the automation?

Can I create my own app the just opens thew other app?

Any other way?

@Eladbdv,
Install ‘Apk Info’ app from play store and get app-package, app-activity using this app,
or if you want apk file then install ‘super backup’ app from play store and backup your app and in backup folder you will get apk file.

Thanks.

‘apk info’ gives me only the apk name. not package and activity.

how would you do the same for iOS?

@Appium_Master

obtaining the apk name using “apk info” app.
I have tried this code:

@Before
public void setUp() throws Exception {
    File classpathRoot = new File(System.getProperty("user.dir"));
    File appDir = new File(classpathRoot, "../../../data/app/");
    File app = new File(appDir, "com.gapp.android-1.apk");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
    capabilities.setCapability("deviceName","Android Emulator");
    capabilities.setCapability("platformVersion", "4.4");
    capabilities.setCapability("platformName","Android");
    capabilities.setCapability("app", app.getCanonicalPath());
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

and the Appium Server logs this error:

error: Failed to start an Appium session, err was: Error: Bad app: /Users/data/app/com.gapp.android-1.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat '/Users/data/app/com.gapp.android-1.apk'

info: [debug] Error: Bad app: /Users/data/app/com.gapp.android-1.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat '/Users/data/app/com.gapp.android-1.apk'
    at null.<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/android/android-common.js:56:13)
    at /Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/device.js:81:16
    at FSReqWrap.oncomplete (fs.js:99:15)

info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Bad app: /Users/data/app/com.gapp.android-1.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat '/Users/data/app/com.gapp.android-1.apk')","origValue":"Bad app: /Users/data/app/com.gapp.android-1.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat '/Users/data/app/com.gapp.android-1.apk'"},"sessionId":null}

FYI:- ‘apk info’ app gives both pkg, activity name , check the attached snapshot

and you need to give capabilities
app-activity
app-package
and if app is already installed then you no need to give app path, please watch my video which i added on your other question

Thanks
Srikanth

Thanks

I have downloaded a different “Apk info” app. and now i can see the package and activity.

however with this code:

public class AndroidTest {

    private AppiumDriver driver;

    @Before
    public void setUp() throws Exception {
        File classpathRoot = new File(System.getProperty("user.dir"));
        File appDir = new File(classpathRoot, "../../../data/app/");
        File app = new File(appDir, "Facebook.apk");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
        capabilities.setCapability("deviceName","Android Emulator");
        capabilities.setCapability("platformVersion", "4.4");
        capabilities.setCapability("platformName","Android");
        //capabilities.setCapability("app", app.getCanonicalPath());

        capabilities.setCapability("appPackage", "com.grindrapp.android");
        capabilities.setCapability("appActivity", ".activity.SplashActivity");
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
    }

    @Test
    public void apiDemo(){
        WebElement el = driver.findElement(By.name("Animation"));
        assertEquals("Animation", el.getText());
        el = driver.findElementByClassName("android.widget.TextView");

The execution is stuck on

`driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);`

and I get this error:

info: [debug] Creating new appium session 566fdbb4-bbcc-4d46-ac30-7f9211881bb6

info: Starting android appium

info: [debug] Getting Java version

info: Java version is: 1.8.0_31

info: [debug] Checking whether adb is present

warn: The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for adb.

info: [debug] executing cmd: which adb

info: [debug] Using adb from /usr/local/bin/adb


info: [debug] Using fast reset? true
info: [debug] Preparing device for session

info: [debug] Not checking whether app is present since we are assuming it's already on the device

info: Retrieving device

info: [debug] Trying to find a connected android device

info: [debug] Getting connected devices...

info: [debug] executing cmd: "/usr/local/bin/adb" devices

info: [debug] 1 device(s) connected

info: Found device 4df1250c1d449f4d
info: [debug] Setting device id to 4df1250c1d449f4d

info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)

info: [debug] executing cmd: "/usr/local/bin/adb" -s 4df1250c1d449f4d wait-for-device

info: [debug] executing cmd: "/usr/local/bin/adb" -s 4df1250c1d449f4d shell "echo 'ready'"

info: [debug] Starting logcat capture

info: [debug] Stopping logcat capture

error: Logcat capture failed: spawn "/usr/local/bin/adb" ENOENT

info: --> GET /wd/hub/status {}

info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.3.5","revision":"a124a15677e26b33db16e81c4b3b34d9c6b8cac9"}},"sessionId":"566fdbb4-bbcc-4d46-ac30-7f9211881bb6"}

info: <-- GET /wd/hub/status 200 1.653 ms - 155 {"status":0,"value":{"build":{"version":"1.3.5","revision":"a124a15677e26b33db16e81c4b3b34d9c6b8cac9"}},"sessionId":"566fdbb4-bbcc-4d46-ac30-7f9211881bb6"}

info: --> GET /wd/hub/status {}

info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.3.5","revision":"a124a15677e26b33db16e81c4b3b34d9c6b8cac9"}},"sessionId":"566fdbb4-bbcc-4d46-ac30-7f9211881bb6"}
info: <-- GET /wd/hub/status 200 1.292 ms - 155 {"status":0,"value":{"build":{"version":"1.3.5","revision":"a124a15677e26b33db16e81c4b3b34d9c6b8cac9"}},"sessionId":"566fdbb4-bbcc-4d46-ac30-7f9211881bb6"}

info: --> GET /wd/hub/status {}

info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.3.5","revision":"a124a15677e26b33db16e81c4b3b34d9c6b8cac9"}},"sessionId":"566fdbb4-bbcc-4d46-ac30-7f9211881bb6"}
info: <-- GET /wd/hub/status 200 0.836 ms - 155 {"status":0,"value":{"build":{"version":"1.3.5","revision":"a124a15677e26b33db16e81c4b3b34d9c6b8cac9"}},"sessionId":"566fdbb4-bbcc-4d46-ac30-7f9211881bb6"}

my .zprofile:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
export ANDROID_HOME='/Users/eladb/MyWorkspace2/adt-bundle-mac-x86_64/sdk/'

how can i fix this?

can you click on appium doctor icon to find what is the issue.As per the logs your android_home is not set correctly.

That’s not it.

The Doctor passed OK even beforehand:

Last login: Sat Feb 21 11:02:43 on ttys000
‘/Applications/Appium.app/Contents/Resources/node/bin/node’ ‘/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium-doctor.js’
➜ ~ ‘/Applications/Appium.app/Contents/Resources/node/bin/node’ ‘/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium-doctor.js’
Running iOS Checks
:heavy_check_mark: Xcode is installed at /Applications/Xcode.app/Contents/Developer
:heavy_check_mark: Xcode Command Line Tools are installed.
:heavy_check_mark: DevToolsSecurity is enabled.
:heavy_check_mark: The Authorization DB is set up properly.
:heavy_check_mark: Node binary found using .appiumconfig.json at /Applications/Appium.app/Contents/Resources/node/bin/node
:heavy_check_mark: iOS Checks were successful.

Running Android Checks
:heavy_check_mark: ANDROID_HOME is set to “/Users/eladb/MyWorkspace2/adt-bundle-mac-x86_64/sdk/”
:heavy_check_mark: JAVA_HOME is set to “/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home.”
:heavy_check_mark: ADB exists at /Users/eladb/MyWorkspace2/adt-bundle-mac-x86_64/sdk/platform-tools/adb
:heavy_check_mark: Android exists at /Users/eladb/MyWorkspace2/adt-bundle-mac-x86_64/sdk/tools/android
:heavy_check_mark: Emulator exists at /Users/eladb/MyWorkspace2/adt-bundle-mac-x86_64/sdk/tools/emulator
:heavy_check_mark: Android Checks were successful.

:heavy_check_mark: All Checks were successful
➜ ~

Try this code, I tried it and it is working for me
import io.appium.java_client.android.AndroidDriver;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeTest;

public class grindr {

public static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException {
    

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
        capabilities.setCapability("deviceName","10.0.0.9:5555");
        capabilities.setCapability("platformVersion", "4.4.2");
        capabilities.setCapability("platformName","Android");
        capabilities.setCapability("appPackage", "com.grindrapp.android");
        capabilities.setCapability("appActivity", ".activity.SplashActivity");
        
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);

}}

Thanks

few things I didn’t understand:

  1. How do you know it works? you cannot install the app on the emulator i guess?

  2. The error says: The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for adb.

and your answer didn’t relate to the environment variable. I guess this is where I should fix something?

  1. There is no much difference between your code and mine. So how can this solve my problem?