Appium Error - java.lang.SecurityException: Permission Denial: starting Intent

I am an Appium and Android noob, thrown into a startup and asked to build their Appium testing for iOS and Android. I am having incredible trouble with Appium connections.

1: What does this error even mean?

java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.truckpay.truckpay/com.truckpay.Activity.Activity_ScreenSlide } from null (pid=6246, uid=2000) not exported from uid 10150
        at com.android.server.wm.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1043)
        at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:760)
        at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:583)
        at com.android.server.wm.ActivityStarter.startActivityMayWait(ActivityStarter.java:1288)
        at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:514)
        at com.android.server.wm.ActivityTaskManagerService.startActivityAndWait(ActivityTaskManagerService.java:1231)
        at com.android.server.am.ActivityManagerService.startActivityAndWait(ActivityManagerService.java:3512)
        at com.android.server.am.ActivityManagerShellCommand.runStartActivity(ActivityManagerShellCommand.java:513)
        at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:172)
        at android.os.ShellCommand.exec(ShellCommand.java:104)
        at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:9774)
        at android.os.Binder.shellCommand(Binder.java:881)
        at android.os.Binder.onTransact(Binder.java:765)
        at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:4498)
        at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2741)
        at android.os.Binder.execTransactInternal(Binder.java:1021)
        at android.os.Binder.execTransact(Binder.java:994)

2: These are the solutions I have tried/looked at:

I saw something saying that the app activity and package might be wrong but I found them while running the app’s initial page using

  mCurrentFocus=Window{e28bfc5 u0 com.truckpay.truckpay/com.truckpay.Activity.Activity_ScreenSlide}

Here is the code, I’m getting the same error with and without the app part commented out:


// webdriverio is an automation FrameWork built to automate applications - Helps create a scalable, robust and stable test suite
const wdio = require("webdriverio");

// The assert module provides a way of testing expressions. If the expression evaluates to 0, or false, an assertion failure is being caused, and the program is terminated.
const assert = require("assert");

// Desired Capabilities are just a set of keys and values that get sent to the Appium server during session initialization, that tell Appium what kind of thing we want to automate.
// DESIRED CAPABILITIES:
const opts = {
  path: '/wd/hub',
  port: 4723,
  capabilities: {
    platformName: "android",
    platformVersion: "10",
    deviceName: "Pixel4",
    // app: "/Users/christianfortin/Desktop/TRUCKPAY/android/android-official-new/app",
    // app: "/data/app/com.truckpay.truckpay-wgEmERr3YM5Q32mK_1krSw==/base.apk=com.truckpay.truckpay",
    // app: "/Users/christianfortin/Desktop/TRUCKPAY/android/android-official-new/app/build/outputs/apk/debug/app-debug.apk",
    appPackage: "com.truckpay.truckpay",
    // appPackage is for java for androids
    appActivity: "com.truckpay.Activity.Activity_ScreenSlide",
    //  appActivity: Where to go in the app initially
    automationName: "UiAutomator2",
    // automationName: the name of the driver you wish to use
    remoteAppsCacheLimit: "0",

  }
};

async function main () {
  const client = await wdio.remote(opts);
  // Puts your phone and the application into the variable "client"

  // const field = await client.$("android.widget.EditText");
  // // Opens the "Edit text" application
  // await field.setValue("Hello World!");
  // Type this into the field
//   const value = await field.getText();
//   // This puts the value into a variable
//   assert.strictEqual(value,"Hello World!");
//   // This checks value against the value we expect it to give us
//   await client.deleteSession();
// // This ends the session
}

main();

It’s impossible to tell what that error is without looking at the code. However, a lot of times people come on this board with very little knowledge and just try to jump start things. Could I suggest taking a step or 2 back, reading a good tutorial (below) and using it as a guide? I think you will get up and running much faster, without the cryptic errors:

https://appium.io/docs/en/about-appium/getting-started/index.html

It will also serve as a guide to those who are trying to help. If you say, “I tried this tutorial and it’s failing on this step”, that is way easier to figure out than, “What does this error mean”, with no context.

Also, since you are at a startup, you should make sure everything runs on the command line from the beginning. I can guarantee you they will want it in CI ASAP. Use a good IDE (your choice) but run the tests outside it to be ready for the next step. My $0.02. Good luck.

I have gone through that tutorial. I’m trying to connect Appium to the app that is on the emulator. I will edit it so I can show the code.

Ok. Is this running from command line or some IDE?

Appium is running from the command line within my IDE (VScode), I’m using “node PROJECT_NAME” to run the script above.

Can you also try running from a terminal? Sometimes the IDE will need additional setup. I’m not familiar with VScode, but at least it’s not Eclipse :slight_smile:

Meanwhile I’ll take a look at VScode errors of the type you listed above.

Not specific to VScode, but I’m seeing references to build/run configuration:

https://rotadev.com/android-java-lang-securityexception-permission-denial-starting-intent-dev/

It would be great to see this run outside the IDE, but also take a look at build/run config. Make sure it is not overriding your code in some way. Remember that you will probably have to run this in CI sometime soon (it’s usually the next ask after POC, and basic test suite) and you can’t run CI from VScode.

Check https://github.com/appium/appium/blob/1.x/docs/en/writing-running-appium/android/activity-startup.md