CreateProcess error=206, The filename or extension is too long Android Studio 4.0

1.1k Views Asked by At

I just started to get this error this morning. I cant build any of my projects since then. Any solutions how to fix this? Tried Clean Project and Invalidate Caches and Restart multiple times. It worked until today.

Found some question about exact same problem that it can be caused by Windows filepath length. All my projects are located in D:\AndroidProjects folder. It is not long path.

This error is sometimes replaced by Error running 'app': Default Activity not found

UPDATE: Error is still appearing more frequently now. I just have to try and build the project 20 times in a row and out of nowhere it is working 21nd time. This is some bug in recent Android Studio update. Other coworkers having same problem on Windows and macOS.

Its something with java path:

java.io.IOException: Cannot run program "C:\Program Files\Android\Android Studio\jre\jre\bin\java": CreateProcess error=206, The filename or extension is too long
2

There are 2 best solutions below

0
On

Below is the only solution worked for me.

  1. Close Android Studio
  2. Kill all "java" processes in task manager (You may skip this step if you assume that all "java" processes were closed)
  3. Manually delete your project's "build" folder. (Usually the path is "YourProjectFolder\app\build")

I know this is temporary, but this is reliable, so saves our time.

[Note: I noticed that it happens if we don't restart our computer for long time. I usually hibernate/resume. That may be the root cause. It happens even if we restart daily. :( ]

2
On

You should have at least one activity that looks something like this:

<activity
        android:name="com.your.package.name.YourActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

if this not working for you then apply File -> Invalidate Caches / Restart once again