Enable --relaxed-security programmatically in Java

Hi there,

How can I enable --relaxed-security programatically?
I need that in order to run driver.executeScript(), to run shell commands. Is there a workaround for that?

My code:

public void setUpServer() {
serviceBuilder = new AppiumServiceBuilder()
.withAppiumJS(new File(establishServerPath()))
.withArgument(GeneralServerFlag.LOG_LEVEL, “info”)
service = serviceBuilder.build();

public void startServer() {

public void setCapabilities(Device device, Command command) throws DeviceException {
caps = new DesiredCapabilities();

    caps.setCapability(MobileCapabilityType.DEVICE_NAME, device.getModel());
    caps.setCapability(MobileCapabilityType.UDID, device.getSerialNo());
    caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
    caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, device.getOS());
    caps.setCapability("autoGrantPermissions", "true");
    caps.setCapability("automationName", "UiAutomator2");
    caps.setCapability("automationName", "--relaxed-security");

    caps.setCapability("appPackage", command.getAppPackage());
    caps.setCapability("appActivity", command.getAppActivity());

public void initDriver() {
try {
driver = new AndroidDriver(service.getUrl(), caps);
} catch (WebDriverException ex) {
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Also, I found a solution to do that with Runtime:
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec(“cmd.exe /c start cmd.exe /k \“appium -a -p 4723 --session-override -dc \”{\”\“noReset\”\": \"\“false\”\"}\"\"");
} catch (IOException | InterruptedException e) {

But if I do that, I’m not able to set the capabilities like I did before.

Thank you!

Did you by any chance find a solution?

this is SERVER argument. not driver capability. http://appium.io/docs/en/writing-running-appium/server-args/index.html

Is it possible to send the argument progamatically? I execute mobile tests on browserstack on a real device. Hence I need to pass the argument in my code

such scenario is not possible. Only the cloud provider could enable this option if they want to

1 Like

Thank you for the response