I have created a new KMM project and I get red errors in all Gradle files
kdoctor:
[v] System
OS: macOS (12.5.1)
CPU: Apple M1 Pro
[v] Java
Java (openjdk version "17.0.4" 2022-07-19 LTS)
Location: /Library/Java/JavaVirtualMachines/openjdk17-corretto/Contents/Home/bin/java
JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk17-corretto/Contents/Home
* Note that, by default, Android Studio uses bundled JDK for Gradle tasks execution.
Gradle JDK can be configured in Android Studio Preferences under Build, Execution, Deployment -> Build Tools -> Gradle section
[v] Android Studio
Android Studio (2021.2)
Location: /Users/ahmedhnewa/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/212.5712.43.2112.8815526/Android Studio.app
Bundled Java: openjdk 11.0.12 2021-07-20
Kotlin Plugin: 212-1.7.10-release-333-AS5457.46
Kotlin Multiplatform Mobile Plugin: 0.3.3(212-1.7.0-RC-release-217-IJ)-104
[v] Xcode
Xcode (13.4.1)
Location: /Applications/Xcode.app
[x] Cocoapods
ruby (ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21])
* System ruby is currently used
CocoaPods is not compatible with system ruby installation on Apple M1 computers.
Please install ruby 2.7 via Homebrew, rvm, rbenv or other tool and make it default
ruby gems (3.0.3.1)
cocoapods (1.11.3)
* cocoapods-generate plugin not found
Get cocoapods-generate from https://github.com/square/cocoapods-generate#installation
Failures: 1
KDoctor has diagnosed one or more problems while checking your environment.
Please check the output for problem description and possible solutions.
I created a project with regular ios distribution framework.
I have even tried to install ruby 2.7 using homebrew and I add the path to env and the error is still the same so I revert all the changes back
settings.gradle.kts:
pluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
}
}
rootProject.name = "DemoKMM"
include(":androidApp")
include(":shared")
build.gradle.kts:
buildscript {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10")
classpath("com.android.tools.build:gradle:7.2.2")
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
I have tried too many solutions and I already read the documentation and nothing work.
3
Answers
I just update Android Studio to Electric Eel (2022.1.1) and KMM Plugin and it solved
I was facing the same issues on a Mac mini with M1. I think that the main problem is that you need to make sure that cocoapods are running with Ruby 2.6 or 2.7, but not 3.1.
I found that is you use home brew to install cocoapods it also installs Ruby 3.1, like in here:
What I did was uninstall Ruby 3.1 using home brew:
Install ruby 2.6 or 2.7
Install cocoapods using gem install:
And finally verify cocoapods environment:
That worked for me, and hope it works for you too.
The reason for this issue Kdoctor is taking default system ruby version, which doesn’t support for KMM, so install any ruby version Management like
brew install rbenv
and thenrbenv install 2.7.0
which will install ruby 2.7.0 and then add the pathvim ~/.zshrc
add the pathexport PATH="$HOME/.rbenv/versions/2.7.0/bin:$PATH"
Notes:
Make sure to add :$PATH to the last, If not system ruby will get preference over install path based on path order
If any doubts please comment it