'Android-studio goes endless loop when trying to compile MLKIT-sample code

I'm trying to compile and run Google's MLKit sample https://github.com/googlesamples/mlkit. Code uses kotlin and there is one compiling issue, where I had to add '.toString()', when 'String' was expected, but got 'String?'. After that manual code correction gradle process tries to compile the project, but task ':app:mergeDexDebug' newer ends. Tried hours. I use Ubuntu 20.04, downloaded official Android-Srudio, unzipped to my home directory's subdirectory and let it to upgrade itself as it wanted.

Android-Studio wan't to upgrade MLKit project to use newer gradle and gradle-wrapper and tried both let upgrade to be done and not to upgrade, but there was no difference. Grdle-process continues until it goes to task ':app:mergeDexDebug', which newer ends.

I have downloaded latest java and set my set it in other projects's settings to be used and kit works fine with those project. Anothed option is use Android Studios internal java and it seems, that MLKit sample project uses that, because, when you open new project in Android-Studio, it start co compile MLKit sample projectit automatically and you don't have time to configure it by hand before to compile. Or yes, I have some time to comfigure foreground, because gradle works in background, until gradle is in the task ':app:mergeDexDebug', but it is hard to test result of that kind configuration, because you can't exit from Andpoid-Studio normally, but it warns you that gradle processes are still running and when you exit, java-processes will still keep running and if your kill them, but gradle cache will not be in normal state and there will be lockfiles etc and you can't use grade until you have removed gradle cache. So it is hard to study what goes wrong. Any idea?



Solution 1:[1]

Seems that problem was with gradle settings, too low memory setting. Because I could not compile original MLKit example projects, I started to build another project based on MLKit example projects code. With that process I had error in compilation also and adjusted gradle memory setting from original 256MB to 1024MB and continued. After some hours and some Android Studio restarts I checked original MLKit example project, and noticed that it had been compiled in background. I could install it in to my phone. By the way, this example project introduces bar code scanning and object detecting. Object detecting does not do anything reasonable, because it can maybe show objects in camera view or picture, but can not name them, but barcode scanning works fine.

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 Reijo Korhonen