Hi! I'm going through Compose Multiplatform templa...
# compose-ios
n
Hi! I'm going through Compose Multiplatform template app (https://github.com/JetBrains/compose-multiplatform-ios-android-template/#readme). I'm able to compile and run on Android, however, when I try to compile for iOS, I get this:
Copy code
...

Welcome to Gradle 7.5.1!

...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'MyApplication'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:7.4.2.
     Required by:
         project : > com.android.application:com.android.application.gradle.plugin:7.4.2
         project : > com.android.library:com.android.library.gradle.plugin:7.4.2
      > No matching variant of com.android.tools.build:gradle:7.4.2 was found. ...
(Full compilation output) I didn't change anything in the template and am using fresh macOS (Ventura 13.3.1) and Android Studio (Flamingo 2022.2.1) versions. In gradle.properties
agp.version
is 7.4.2 Any idea why Gradle 7.5.1 was used? Alternatively, I'd appreciate any pointers to working tutorials.
k
Did you run it with
./gradlew ...
?
if you use
gradle ...
, it means that you use the system gradle
n
I chose iosApp in the configuration drop-down and clicked run (ctrl+R)
The only difference from the tutorial, is that in my case the configuration to run on iPhone 14 has already existed in Android Studio, I didn't have to create in manually as in the tutorial.
h
You need JVM 11
It is hidden in this line:
Copy code
- Variant 'apiElements' capability com.android.tools.build:gradle:7.4.2 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
Depending how you called the build, you might have Java 8 as default
n
Thank you! Let me try.
h
And regarding your question about AGP 7.4.2 and Gradle 7.5.1: The latter is the build system which supports plugins, like the Android Gradle Plugin (AGP). Both versions are (mostly) independent.
n
My project structure dialogue shows that Java 11 is already used, for Source Compatibility and Target Compatibility I guess it's the same as
build.gradle.kts
file, and it's already Java 11 in the template project source code
I don't understand where it got Java 8 from
h
I guess this is due to the cocoa pods build: You don't actually run Gradle, but cocoa pods, which runs gradle. And this run uses your Java home, which is JVM 8, and not JVM 11. I guess just passing
JAVA_HOME=path to your java 11 home
should be enough.
j
In general I recommend using Gradle 8.1+ with Java 17 for latest in CMP iOS. Also check gradle.properties or settings.gradle to update agp to 8.0.2 corresponding to Flamingo patch 2.
c
@Natasha Murashkina open Android studio preference -> Build, Execution... -> Build tool -> Gradle -> on Gradle JDK, choose Embedded JDK to use latest JDK (my version is 17.0.6)
n
Phillip's right, installing Java 17 solved my issue. It was using my system's java instead of the Android Studio's embedded JDK. Thank you, everyone, for contributing ideas!
j
For future reference, very easy install from homebrew like
brew install java17
and get automatic recommendation of symlinks if needed. Usually I think using systems Java better, as can use across other things than ANdroid Studio. Or using java toolchain from Gradle, let it on the fly install it for you. Maybe over kill not sure, but some ideas if want to try later on 🙂 Nice it solved for you! 🙂
n
Thank you! I'm always confused with package management, especially on macos, so appreciate the advice.
TL;DR Cannot run the iOS app of the basic multiplatform iOS/Android application, set up following the official tutorial on a new and empty Macbook Air M3, Sonoma 14.4.1. I've installed Android Studio, and XCode, and chose to use Cocoapods as a dependency manager, all following the official guide. I can run the Android application, but I cannot run the iOS one (output) with the error message
The operation couldn't be completed. Unable to locate a Java Runtime.
Note: I had the same issue 12 months ago, from my first attempt at doing the same on my old Air 2018. It resolved when I chose Android Studio's embedded Java. However, I checked, and I do use it now (see screenshot inside). Any ideas about which Java I should be using and how to set it up? I remember the last time the issue was something like Cococapods used different javas for Android and iOS, but I didn't understand the issue thoroughly enough.
✅ 2
Settings -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JDK dropdown
Oy, resolved by choosing Download JDK -> OpenJDK 22 in Settings -> Build, Execution, Deployment. Who could I ask to add this to the official tutorial?