Hello, I hope everyone is doing alright…I am quite...
# multiplatform
f
Hello, I hope everyone is doing alright…I am quite new to KMM and I am struggling with creating a fat-jar w/ Shadow plugin. I do not really know how to add the task and then run it. Even though I have already added it in shared gradle and Synced project, it does not appear in the right side bar in shared tasks. May anyone give me a bit of help? thank you all 🙂
l
FYI, fat jar for Android is not possible at the moment if that's what you're looking for
f
Hello @louiscad, why is that?
I have a KMM project where I have placed some logic and want to export a fat jar in order to import it to an existing android project. Isn’t that applicable to my case?
l
There are 2 alternatives: 1. Merge the projects so you just need to depend on the module 2. Publish the Android in mavenLocal, in another local repo, or a remote repo
f
Thank you for your answer @louiscad. Using .aar files is not useful as well right? Don't we have the option to create fat .aar?
l
No, fat aar files are not possible as I said. Note that aars don't specify the third party dependencies, so trying to make a fat aar would create issues anyway.
f
Ok got it now. Thank you very much for your time Louis ✌️
🙂 1
f
@Fanis Paschos here https://stackoverflow.com/questions/65039841/kotlin-native-compile-jar-and-framework/65043870#65043870 I’ve added two gradle tasks to create a fat jar that may help you.
l
@Fabio Bombardi This will cause issues as soon as another library uses the same dependencies. Also, since it's a fat jar, it'll not support android libraries that have resources, assets, or specific stuff that only aar supports.
f
@louiscad That's true, but for code only libs and the right dependency resolution strategy (if needed - it happens sometimes even with maven published ones) you can use it if you want the jar.
l
I'd not recommend because of these issues, but there's a way to hack it, yes. I should have been more clear about it: It's possible, but not in an officially supported way, and there's drawbacks that make it not great in practice.
f
Of course. Yup
f
Well…many thanks for the guidance!! I was not aware about the fat jar capabilities so far
I will try to implement your post’s snipper @Fabio Bombardi, thanks a lot for writing that down
f
@Fanis Paschos good! Be aware to understand how it works and customize it to your needs! (it put the two tasks in a
library
named group if you search for them in the right gradle pane). Make a wise use of it ;)
f
Yes, of course!! I will take into consideration all the conflicts that might occur first of all
Even though I put it in my gradle file and in a first glance it seems ok, it does not find jar.get() in the last line
f
you must include the java plugin.
id("java")
but you can do this only in a pure jvm kotlin multiplatform library. This to say that you cannot have
id("com.android.library")
and
id("java")
at the same time
f
Well, now I understand…because when I imported it, it notified me that the ‘java’ plugin has already been applied
f
it's made for the arrowed one, not the crossed one library template.
f
I see
so, should I remove the android.library one?
in the top tier decleration?
f
It depends. If your are using the
android()
target you cannot. But if you only need the
jvm()
target yes.
f
Got it…unfortunately I am using the android target as well 😕
f
So still no joy 😉
f
and I guess, that there is no workaround from here
yes, that is too bad
I hope that they have in mind any fat jar for android implementations within the upcoming KMM releases
nevertheless, thank you so much for your help
f
Actually I don't know. This is thought for a pure
jvm
lib. I need to find a way to know how to use o replace
jar
in this scenario. But I need time 😉
f
I see
if you find anything any time soon, please share it with us 🙂
f
You can always try to file an issue requesting this feature if there's not already one filed.
f
I guess that there is one, but I will search now in the discussion forums
f
f
So, to recap…
there is no way for someone to create a kmm library and distribute it accross his/her android applications as a jar, is that correct?
Thanks for the link 🙂
f
Actually not for what I know
But what I know... is a grain of sand in a beach 😉
I like to think that way
f
Ok. I will try to publish it in maven or something, as Louis mentioned above
haha, imagine myself how I feel
💪 1
f
I think that this is the best choice for your scenario
f
Yeap, I think that as well
I have to start reading how to create a private maven repo to upload it there
👍 1
l
It can be a local repo, where the destination is a dir in the consumer project. You can then track the files of that dir in git.
🙂 1
Regarding sub-modules bundling, which is often one of the reasons people want a fat aar or a fat jar, you can take a look at this comment by a Googler in the corresponding issue where they say it's something which solution needs to be designed in Gradle first as it affects the whole JVM ecosystem: https://issuetracker.google.com/issues/62121508#comment134
f
That is great, thank you!! I am really thankful for both of your help!! I think that in current situation, I might go with the repo as it seems safer and wait until gradle will be able to produce that kind of output
👍 3
@louiscad @Fabio Bombardi fyi https://youtrack.jetbrains.com/issue/KT-43800 I opened an issue here, which has just been routed from a mod. If you want, just watch the issue for future implementations 🙂
👍 2
f
Well done! 💪😎
✌️ 1