|
| 1 | +# Android Studio support |
| 2 | + |
| 3 | +## Installing AS |
| 4 | + |
| 5 | +> Install latest AS <https://developer.android.com/studio/install> |
| 6 | +
|
| 7 | +### Installing Lombok plugin |
| 8 | + |
| 9 | +> Use the first advice from the following link |
| 10 | +> |
| 11 | +> <https://stackoverflow.com/questions/70900954/cannot-find-lombok-plugin-in-android-studio-2021-1-1-build-of-2022> |
| 12 | +
|
| 13 | +## Prerequisites |
| 14 | + |
| 15 | +> Install and setup gradle version 7.2+ (version 7.4 tested) |
| 16 | +> |
| 17 | +> Use JDK 8 for Gradle in\ |
| 18 | +> `File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JVM` |
| 19 | +
|
| 20 | +## Running in AS |
| 21 | + |
| 22 | +> For now, running Utbot is supported only for Kotlin libraries. You can |
| 23 | +> create one like this: |
| 24 | +> |
| 25 | +> <https://proandroiddev.com/create-an-android-library-aar-79d2338678ba> |
| 26 | +> |
| 27 | +## Debug Intellij code |
| 28 | + |
| 29 | +> At first, when entering Intellij code, you might be presented with |
| 30 | +> decompiled code. |
| 31 | +> |
| 32 | +> If you try to debug it, you might soon find out that it does not match |
| 33 | +> sources. |
| 34 | +> |
| 35 | +> (TO BE TESTED) |
| 36 | +> |
| 37 | +> To fix this, you are able to connect alternative Intellij sources |
| 38 | +> using jar-files from AS. |
| 39 | +> |
| 40 | +> File -> Project Structure -> Libraries -> + |
| 41 | +> |
| 42 | +> After that, you might want to enable "Choose sources switch": |
| 43 | +> |
| 44 | +> <https://intellij-support.jetbrains.com/hc/en-us/community/posts/206822215-what-does-Choose-Sources-do-and-how-can-I-undo-what-it-does-> |
| 45 | +
|
| 46 | +## Crucial differences from Intellij IDEA |
| 47 | + |
| 48 | +### Host Android SDK |
| 49 | + |
| 50 | +> Android Studio uses **host Android SDK** to build project, which is |
| 51 | +> basically **a stub(mock) version of real Android SDK**, that is |
| 52 | +> supposed to be found on a real device. |
| 53 | +> |
| 54 | +> It means that, for instance, the constructor of java.lang.Object in |
| 55 | +> that SDK throws Exception explicitly, saying "Stub!". |
| 56 | +> |
| 57 | +> The main idea is that user is not supposed to run anything on host |
| 58 | +> machine, they must use real device or emulator. |
| 59 | +> |
| 60 | +> That leads to the **inability to analyze Android SDK**, thus we have |
| 61 | +> to take real java from Gradle JDK, for example. |
| 62 | +
|
| 63 | +### KtClass tree in View-based modules |
| 64 | + |
| 65 | +> UtBot Plugin window won't even show up if you try to analyze code from |
| 66 | +> the visual components inside AS. That is because insead of PsiClass |
| 67 | +> tree we find KtClass tree. |
| 68 | +> |
| 69 | +> TODO: There is something to be done about this... |
| 70 | +
|
| 71 | +## Troubleshooting |
| 72 | + |
| 73 | +### Maven can't install some dependencies |
| 74 | +> 1. Proxy might have been installed automatically |
| 75 | + > Solution: remove gradle-wrapper file |
| 76 | +> 2. Mockito can't be found |
| 77 | + > Solution: specify version explicitly |
| 78 | +### No target device found |
| 79 | +> File -> Settings -> Build, Execution, Deployment -> Testing -> Run android tests with Gradle(or smth like that) |
| 80 | +
|
| 81 | +### Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8 |
| 82 | + |
| 83 | +> Solution: Use JUNIT (manually create run config for it), not Gradle! |
| 84 | +> |
| 85 | +> Also, turn off 'build before run' for tests, if you use Java 11 in your project. |
| 86 | +> |
| 87 | +> TODO: how to create config |
| 88 | +> |
| 89 | +> (!) In Generation Window, you have to set correct source root(src/test/java). |
| 90 | +
|
| 91 | +### Test events were not received |
| 92 | + |
| 93 | +> Solution: Use JUNIT (manually create run config for it), not Gradle! |
| 94 | +> |
| 95 | +> TODO: how to create config |
| 96 | +> |
| 97 | +> (!) In Generation Window, you have to set correct source root(src/test/java). |
| 98 | +
|
| 99 | +### Can't run tests because Android project complains about 'tools.jar' |
| 100 | + |
| 101 | +> The project is messed up, copy sources and make a clean one. |
| 102 | +> |
| 103 | +> TODO: a better solution? |
| 104 | +> |
| 105 | +### java: Cannot run program AppData/Local/Android/Sdk/bin/java |
| 106 | + |
| 107 | +> The project is messed up, copy sources and make a clean one. |
| 108 | +> |
| 109 | +> TODO: a better solution? |
| 110 | +
|
| 111 | +### \[possible\] org.jetbrains.android not found |
| 112 | + |
| 113 | +> Use latest Kotlin in UTBotJava/utbot-intellij/build.gradle: |
| 114 | +> |
| 115 | +> > intellij.plugins = [..., 'org.jetbrains.kotlin',...] |
0 commit comments