'Cannot resolve production code in tests after Android Studio Chipmunk automatically created modules
I'm currently using Android Studio to develop a multi-module project by test-driven-development methods. It went well until I updated my IDE to Android Studio Chipmunk from previous Bumblebee. When I opened the project after the update, it seemed that AS automatically generated some modules for me. As you can see in the pic, those new names such as [main] and [unitTest] appeared in the project view automatically. modules generated automatically
After this, I found that the classes and methods of my production code could not be resolved in my test code. AS told me after I pressed Alt+Enter that I should add dependency to the main module of my production code. And it added one line in the build.gradle file: "testImplementation project(path: ':app')". After syncing the gradle build, nothing had changed and it still could not resolve methods in my production code. I can still run the tests by executing gradle test tasks, but it is weird that I cannot use production code in my test code directly.
UPDATE:
For further information, I think this is a problem caused by the update from Intellij 2021.1 to 2021.2, since I re-installed AS Bumblebee and all seems worked fine. I also found this issue in JetBrains YouTrack that has an exactly same problem with me. Here is the link: https://youtrack.jetbrains.com/issue/IDEA-275566/Class-not-found-after-intellij-upgrade-2021-1-2-2021-2
This issue remains open and I've tried some other developers' reply in this issue to delete the .iml files, but the problem remains. I think Intellij 2021.1 and 2021.2 generate different .iml file in the .idea folder.
Solution 1:[1]
I was having the same issues in the first Android Studio Chipmunk release - all of my unit test source code was peppered with "Cannot resolve symbol" errors, but the code would still compile and run, and the tests would pass.
I found that I could temporarily workaround (i.e., "fix") the issue by adding a line to the build.gradle file like:
testImplementation project(path: ':shared:library:module')
But today I upgraded to the new Chipmunk release, with details:
Android Studio Chipmunk | 2021.2.1 Patch 1
Build #AI-212.5712.43.2112.8609683, built on May 18, 2022
Runtime version: 11.0.12+0-b1504.28-7817840 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
And the issue no longer occurs. I'm guessing the folks working on the IntelliJ platform found and patched the issue. ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HelloImKevo |
