today jump into such problem when launching test class using roboelectric and junit:
Information:Gradle: Executing tasks: [:app:assembleDebug, :app:assembleDebugUnitTest]
Error:Gradle: failed to create directory 'E:\AndroidKotlin\FooApp\app\build\generated\source\r\debug\com\example\foo\fooapp'
Error:Gradle: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.AaptException: AAPT2 link failed:
Error:Gradle: com.android.builder.internal.aapt.AaptException: AAPT2 link failed:
Error:Gradle: Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
Maybe someone has meet such nasty thing earlier and would be so nice to help me ;) ? If u don't have any idea, please let me know how can I try finding it on my own. I already did clean project and rebuild :)
I've met this error with Android Studio 3.0RC.
How to solve:
open (ctrl+shift+N): gradle.properties
add line: android.enableAapt2=false
You may find something useful here: https://developer.android.com/studio/build/gradle-plugin-3-0-0.html
Finally managed to get rid of all unwanted stuff with AS option:
File -> Invalidate caches / Restart
Found such a dependency, if the project and the environment (SDK, Android Studio) is on different disks (volumes), then there will be an error. This error occurs when the test starts.
Solution, move the project to the root of the disk on which the SDK and Android Studio is located, it's helped me.
Android Studio 3.0.1, compileSdkVersion 27, Windows 10
来源:https://stackoverflow.com/questions/46512990/gradle-error-failed-to-create-directory