Hi, I am pretty new in Mobile App Development and trying to test the Kotlin KMM "Hello World" app. D...
r
Hi, I am pretty new in Mobile App Development and trying to test the Kotlin KMM "Hello World" app. During iOS build, I am getting this error:
Copy code
No matching variant of com.android.tools.build:gradle:7.4.1 was found
I am using
Android Studio Electric Eel | 2022.1.1 Patch 1
on
MacOS Ventura 13.2.1
j
Can you share your build.gradle and settings.gradle? It looks like the Android Gradle plugin isn't found. You might be missing the
google()
plugin repository.
r
I followed these steps: https://kotlinlang.org/docs/multiplatform-mobile-create-first-app.html#update-your-application
build.gradle.kts
at project root dir:
Copy code
plugins {
    //trick: for the same plugin versions in all sub-modules
    id("com.android.application").version("7.4.1").apply(false)
    id("com.android.library").version("7.4.1").apply(false)
    kotlin("android").version("1.8.0").apply(false)
    kotlin("multiplatform").version("1.8.0").apply(false)
}

tasks.register("clean", Delete::class) {
    delete(rootProject.buildDir)
}
j
Does your settings.gradle.kts include:
Copy code
pluginManagement {
    repositories {
        google()
        gradlePluginPortal()
        mavenCentral()
    }
}
r
settings.gradle.kts
:
Copy code
pluginManagement {
    repositories {
        google()
        gradlePluginPortal()
        mavenCentral()
    }
}

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.name = "mykmmv4"
include(":androidApp")
include(":shared")
j
That all looks correct. What Gradle version are you using in gradle-wrapper.properties?
r
Output of kdoctor:
Copy code
[✓] Operation System                                 
[✓] Java
[✓] Android Studio
[✓] Xcode
[✓] Cocoapods

Conclusion:
  ✓ Your system is ready for Kotlin Multiplatform Mobile Development!
j
Android Gradle Plugin compatibility info can be found here.
r
gradle-wrapper.properties
Copy code
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
j
Gradle 7.5 is the minimum version for AGP 7.4. So that's correct as well. You're only getting this error when building in Xcode? The Android build works as expected?
r
Yes. Android build is working.
Detail error:
Copy code
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'mykmmv4'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:7.4.1.
     Required by:
         project : > com.android.application:com.android.application.gradle.plugin:7.4.1
         project : > com.android.library:com.android.library.gradle.plugin:7.4.1
      > No matching variant of com.android.tools.build:gradle:7.4.1 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.5' but:
          - Variant 'apiElements' capability com.android.tools.build:gradle:7.4.1 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'javadocElements' capability com.android.tools.build:gradle:7.4.1 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'runtimeElements' capability com.android.tools.build:gradle:7.4.1 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'sourcesElements' capability com.android.tools.build:gradle:7.4.1 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at <https://help.gradle.org>

BUILD FAILED in 995ms
** BUILD FAILED **
j
Try installing JDK 11. It looks like you've got JDK 8, which isn't compatible.
r
ok thanks.
It’s working. I had to upgrade xcode.
Thanks for quick response and guide me.
j
Good to hear
606 Views