Kotlin Multiplatform Mobile library structure - intellij-idea

Some time ago I've created a KMM library from IntelliJ IDEA, using the "Mobile Application" project template. The structure was (with one root build.gradle.kts file):
libraryProject
- build.gradle.kts
- src
- androidMain
- commonMain
- iosMain
Now, that template is missing from the list. There is just a "Library", which creates a jvm/js/common/native structure.
In Android Studio, the KMM plugin generates (for KMM library template):
libraryProject
- build.gradle.kts
- settings.gradle.kts
- libraryShared (this can be renamed)
- build.gradle.kts
- src
- androidMain
- commonMain
- iosMain
This is just a KMM application without the actual iOS and Android platform modules.
And, it comes with two build.gradle.kts files (root and shared).
I'm just curious if I missed anything or do I have to configure it manually, somehow.
All IDEs and plugins are up-to-date.

When creating new project in Android Studio, one should be able to choose between two KMM projects(KMM Plugin is required to be installed):
KMM Library which contains only the shared module defined, and is intended to be used when one wants to add this library into existing iOS and Android apps.
KMM Application which creates a complete project with shared multiplatforn library, iOS app with ready integration, and the Android app.
Probably, in this case these two were confused. If you had only one option in the Wizard, please let me know which IDE and Plugin versions were used.Note: Mobile library and Mobile Application were removed from IDEA by design,please see https://youtrack.jetbrains.com/issue/KTIJ-19232.

Related

add third party library to kotlin multiplatform mobile shared module

Am writing a KMM mobile app that will be calling an AppSync API, my intention was to implement all the API calls in the shared module so that I don't have to write that code twice (i.e for iOS and Android separately)
Secondly, I want to use the Amplify libraries in the shared module to implement the API calls, am hoping this would allow me to take advantage of lots of features such as offline storage.
What I am noticing however is that even though I have successfully added the amplify libraries in the commonMain sourceSet, the libraries are not visible on the classpath so i can not import any class from the libraries
Here is my commonMain sourceSet dependencies in the build.gradle
val commonMain by getting {
dependencies {
implementation("com.amplifyframework:core:1.35.2")
implementation("com.amplifyframework:aws-api:1.35.2")
}
}
This builds successfully and installs the dependencies but i can't import anything
My question here is,
Does this mean that I can not add any third party that is not a kotlin multiplatform library at all?
I feel like the only option this leaves me is to implement the API calls twice in a platform-specific way which kind of defeats the purpose of using KMM completely, is there an alternative solution that could allow me to use these libraries and write the API calls as shared code that is imported to both iOS and Android apps?
Thank you
I have decided to use https://www.apollographql.com/docs/kotlin/v2/essentials/get-started-multiplatform.
This seems to work well with the KMM, I can build the API calls once and re-use for both platforms.

Required plugin com.intellij.modules.androidstudio to be installed

I want to set up Kotlin Multiplatform Mobile on Intellij IDEA
I downloaded the Kotlin Multiplatform Mobile plugin and installed it but got a warning Require plugin 'com.intelliji.modules.androidstudio' to be installed
How can I resolved it
I install KMM plugin because I can't see any options for create KMM project on IDEA

How to add ViewModel implementation in build.gradle.kts for IntelliJ IDEA project?

Android Studio as default has access to ViewModel class import androidx.lifecycle.ViewModel.
How can I use this ViewModel into IntelliJ IDEA Kotlin desktop project (compose for desktop).
developer.android.com provide guide how to add the dependices just for Android Studio project.
That class is android specific so can't be used for Compose for Desktop.

Worklight v6.2 - Android Cordova Plug-in

Has anyone tried the "Android - Adding native functionality to Hybrid Application using Apache Cordova plug-in" feature in v6.2 ?
I'm trying to use a 3rd party library on the client side and wanted to understand where to put the plug-in java class in the project. The documentation shows a java package (src) structure whereas the best I can find is normal folders in the android native folder.
Thanks.
The reason you see these as "regular" folders is likely because you are look at the Worklight project rather than the generated Android project.
Worklight project\apps\your_app\android\native\ ... will look as folders because they are indeed just folders.
Once you build your Worklight application (containing an Android environment), an Android project will be generated. In it, you will see the folders as packages, etc.
A Worklight project and application structure is explained in earlier training modules:
Creating your first Hybrid Worklight application
Previewing your application on Android
So, you should place your Java Class file in Worklight project\apps\your_app\android\native\src\com\package_name\ ...
Note about Cordova plug-ins in Worklight: depending on the plug-in this may not be possible to use as some plug-ins require using the Cordova plugman, which is not yet supported in Worklight.

Can't change Module SDK for libGDX project

I get "cannot resolve symbol Bundle" for a newly created libGDX project in IntelliJ. When comparing this project to one that works, I notice that in the android module, the Module SDK is set to Project SDK instead of Android API.
If I try to change this I get:
Module "android" must not contain source root "...".
The root already belongs to the module "android".
How can I can't change this and what does the message mean?
Not sure what exactly you mean by last part, as I didn't do any changes to any of the modules. Anyways I had the same problem - "cannot resolve symbol android/Bundle etc", basically android SDK wasn't included. What I did is simply opened Project Structure > SDKs > Add new Android SDK with correct version e.g. 4.4.2, then pressed ok, and afterwards opened gradle plugin and clicked "Refresh All Gradle Projects". Intellijs rebuilt gradle project and indexed everything. Then android SDK problem was resolved.
Unfortunately this step is not mentioned in the tutorial.