I am facing some issue in setting KMM project. I h...
# getting-started
j
I am facing some issue in setting KMM project. I have added multiplatform dependencies inside commonMain of shared module gradle file. While trying to access it inside commonMain directory, it giving unresolved reference error. Android Studio version - Android Studio Dolphin | 2021.3.1 Patch 1
c
What do your build files look like? DId you reload the modules in the IDE?
j
No. After generating the project from android studio KMM template I added the dependencies in shared module gradle file.
c
Does it compile from the command line?
j
I haven’t tried. I am using Android studio.
j
What dependency are you adding? Did you get option to do gradle sync after adding dependency? It's also worth as was mentioned trying to compile/run program.
j
I am adding ktor and kotlin serialization dependencies. Yes, I am getting option to sync gradle after adding dependencies. Only in commonMain its giving unresolved reference error. In androidMain it’s working.
c
If you want us to help, you need to give us more information. Show us what you did. Does it work in the CLI?
j
Sure. But i have no experience with command line. I am new to development and started coding recently.
j
Might also be worth trying a sample and comparing
following for example uses those dependencies https://github.com/joreilly/BikeShare (and others out there as well)
👀 1
c
No problem, just ask if you don't understand what we ask. Bottom left of Android Studio you should have a "terminal" tab (the logo looks like >_). In it, type: Windows:
gradlew projects
Linux/MacOS:
./gradlew projects
This will give you the list of modules that exist in your project. You can then replace
projects
by
<name of the project>:tasks
(without the
<>
) to get a list of tasks, then
<name of the project>:<name of the task>
to execute that task. Here, we're interested in the
build
task of whatever the project name is. I think by default it's called
app
, but I'm not sure
So if the module you're working in is indeed called
app
, and you're on Linux, run
./gradlew app:build
j
OK. I will this command and check.
c
If it works, it means the problem is in Android Studio. If it doesn't work, it means the problem is in the Gradle configuration
j
I am getting this result
c
You're on a UNIX OS (Linux or MacOS), so you have to write
./gradlew <your thing>
every time, otherwise you'll get
Command not found
j
macos
ok
Now, its build successfully.
c
Then the problem is probably just Android Studio not syncing correctly. Open one of the
build.gradle.kts
files of your project, edit something randomly (e.g. add blank lines in the middle of the file), it should show a banner at the top saying "Sync Gradle files now" (or something similar), click that Sorry for this weird manipulation, Google decided to remove the button to do it easily
j
Ok. will try that.
Still same error.
I have also tried in Android studio electric eel version. In that also same issue.
I think there’s some issue in my laptop only.
It’s fixed now. I uninstalled android studio, jdk, gradle and cleared cache. Reinstalled everything. Now it’s working.
Thanks for the help 🙏 Much appreciated.
👍 1