Cannot run appium Could not find aapt Please set the ANDROID_HOME environment variable - even though it is set

I have these capabilities:

enter image description here

but when I try to call AndroidDriver

public AndroidDriver(URL remoteAddress, Capabilities desiredCapabilities) {
	super(remoteAddress, substituteMobilePlatform(desiredCapabilities,
	this.setElementConverter(new JsonToAndroidElementConverter(this));

I get this error:

Original error: packageAndLaunchActivityFromManifest failed. Original error: Could not find aapt Please set the ANDROID_HOME environment variable with the Android SDK root directory path. (WARNING: The server did not provide any stacktrace information)

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: packageAndLaunchActivityFromManifest failed. Original error: Could not find aapt Please set the ANDROID_HOME environment variable with the Android SDK root directory path. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.58 seconds
Build info: version: '2.47.1', revision: 'unknown', time: '2015-07-30 11:02:44'
System info: host: '', ip: '', 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.5', java.version: '1.8.0_77'
Driver info:
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
	at java.lang.reflect.Constructor.newInstance(
	at org.openqa.selenium.remote.ErrorHandler.createThrowable(
	at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(
	at org.openqa.selenium.remote.RemoteWebDriver.execute(
	at io.appium.java_client.DefaultGenericMobileDriver.execute(
	at io.appium.java_client.AppiumDriver.execute(
	at org.openqa.selenium.remote.RemoteWebDriver.startSession(
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(
	at io.appium.java_client.DefaultGenericMobileDriver.<init>(
	at io.appium.java_client.AppiumDriver.<init>(
	at io.appium.java_client.AppiumDriver.<init>(
	at com.waze.mobileautomation.common.appiumdrivers.AppiumDriverFactory.createAndroidDriver(
	at com.waze.mobileautomation.sdk.setup.PartnerSetupManager.createAndroidPartner(
	at com.waze.mobileautomation.sdk.setup.PartnerSetupManager.installAppAndStartIt(
	at com.waze.mobileautomation.partner.SanityIntegrationDebug.bOnboardAsDriverTest(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(
	at org.junit.runners.ParentRunner.runLeaf(
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
	at org.junit.runners.ParentRunner$
	at org.junit.runners.ParentRunner$1.schedule(
	at org.junit.runners.ParentRunner.runChildren(
	at org.junit.runners.ParentRunner.access$000(
	at org.junit.runners.ParentRunner$2.evaluate(
	at org.junit.internal.runners.statements.RunBefores.evaluate(
	at org.junit.internal.runners.statements.RunAfters.evaluate(
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(
	at com.intellij.rt.execution.junit.JUnitStarter.main(

what am i missing?

echo $ANDROID_HOME leads to my sdk

I have tried to add

androidCapabilities.setCapability("appWaitActivity", "com.example.eliran.myapplication.MainActivity");

My ANDROID_HOME is set to my sdk folder.

but it didn’t help. What can it be?

You don’t mention the IDE you are using, but I can see it’s intellij. Hopefully this will help:

Did you remember to export your ANDROID_HOME variable in the shell you used to spawn Appium?

I’m not sure what do you mean?

My ANDROID_HOME is set to my sdk folder.

like this:
❯ echo $ANDROID_HOME [10:54:50]

here is the folder content

I use intellij
but set the ANDROID_HOME in my .zshrc file

So you stackoverflow post is relevant?

In your test make a system call to ‘echo $ANDROID_HOME’. If you find it’s not set, you need to make intellij read your environment variables. In other words, intellij (like any ide) can ignore your environment variables. Follow the steps in that link to make it read them, or set them explicitly in the ide itself.

Okay, that looks right. The way environment variables work is that they are inherited by child processes when you spawn a new process (such as spawning the Appium server process).

Command line shells often have an additional feature for their variables: exporting. Shell variables that are not exported will NOT be passed onto child processes through inheritance. Shell variables that are exported will be inherited by child processes. Make sure that when you set your ANDROID_HOME variable in your .zshrc file that you’re also running the command export ANDROID_HOME after setting it.

For example, let us suppose you did not export the ANDROID_HOME variable. If you spawn your Appium server through your zsh command line, then Appium would not inherit the ANDROID_HOME variable, and thus Appium would not have an ANDROID_HOME variable to read, which leads to the aapt error.

What wreed is saying is that if you spawn Appium through IntelliJ (that is, the Appium process is a child of your Java test process), you need to make sure your tests’ launch configuration includes the ANDROID_HOME environment variable set. AFAIK, there is no need to worry about exporting or unexporting variables outside of command line shells.

i double check and reset my terminal and intellij

Now it works.
might have been a sync issue.
Sorry for the bother.

my env is ubuntu16.04, Appium desktop, configuration is {
“platformName”: “Android”,
“platformVersion”: “8.0”,
“deviceName”: “xiaomi”,
“appPackage”: “com.ansen.webview”,
“appactivity”: “com.ansen.webview.MainActivity”,
“autoGrantPermissions”: “True”,
“automationName”: “uiautomator2”

I still met this error, but I set ANDROID_HOME to env. How can I set ANDROID_HOME into my configuration?

Don’t forget to set the SDK path here as shown in the screenshot

1 Like

This helped me…Thanks :slight_smile: