6

A simple test...

import org.junit.Test

class KotlinUnitTest {

    @Test
    fun test() {
        assert(true)
    }
}

... results in the following...

Information:Gradle: Executing tasks: [:app:assembleDebug, :app:assembleDebugUnitTest]
Information:Kotlin: Kotlin JPS plugin is disabled
Information:Module "app" was fully rebuilt due to project configuration/dependencies changes
Information:06/12/2017 5:08 PM - Compilation completed with 3 errors and 0 warnings in 19s 962ms
Error:Gradle: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Gradle: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Gradle: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details

Adding android.enableAapt2=false to gradle.properties (or also gradle-wrapper.properties) made Android Studio halt indefinitely every time I ran the test.

This is weird because I'm able to...

  • Run my production app (filled with Kotlin files)
  • Unit test in Java

But, for whatever reason, I can't test in Kotlin

1
  • show gradle dependencies please Commented Dec 7, 2017 at 11:57

2 Answers 2

4

I've had similar problems with meaningless AAPT2 errors while running kotlin tests. The source of the problem is in Android Studio generating wrong Run Configuration for tests in Kotlin. I'm not sure what causes this bug because it looks it's not happening to everyone.

Running unit tests via command line worked without problems.

Creating test configuration by hand resolved the issue: create configuration manually

But still if I try to run the test by clicking the side note button I got the compilation error. run test button

BTW: If you try to edit the generated configuration you are out of luck because that configuration isn't listed in the configurations list at all.

Sign up to request clarification or add additional context in comments.

Comments

2

I got same problem. for a simple test:

@RunWith(RobolectricTestRunner::class)
@Config(constants = BuildConfig::class)
class MainActivityTest {
    private lateinit var activityController: ActivityController<MainActivity>

    @Before
    @Throws(Exception::class)
    fun setUp() {
        activityController = Robolectric.buildActivity(MainActivity::class.java)

        activityController.create().start().resume()

    }

    @Test
    @Throws(Exception::class)
    fun testNotBeNull() {
        assertNotNull(activityController.get())
    }

}

Update to latest Kotlin version to 1.1.60 and Gradle to 3.0.1 solve it.

8 Comments

But latest version of Kotlin is 1.2.0
@OsipXD Interesting, Android Studio told me to change to 1.1.60.
may be because you've not updated Kotlin plugin in AS?
That make sense, thanks for the tip. Anyway, 1.1.60 works for me.
Error:Gradle: failed to create directory 'D:\...'. Error:Gradle: failed processing manifest. Error:Gradle: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Error:Gradle: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Error:Gradle: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Error:Gradle: Execution failed for task ':app:processInstallStagingDebugResources'. > Failed to execute aapt
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.