https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
f

Fanis Paschos

12/05/2020, 12:12 AM
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

louiscad

12/05/2020, 12:21 AM
FYI, fat jar for Android is not possible at the moment if that's what you're looking for
f

Fanis Paschos

12/05/2020, 12:25 AM
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

louiscad

12/05/2020, 1:19 AM
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

Fanis Paschos

12/05/2020, 11:46 AM
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

louiscad

12/05/2020, 11:50 AM
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

Fanis Paschos

12/05/2020, 11:51 AM
Ok got it now. Thank you very much for your time Louis ✌️
🙂 1
f

Fabio Bombardi

12/05/2020, 3:36 PM
@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

louiscad

12/05/2020, 4:17 PM
@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

Fabio Bombardi

12/05/2020, 4:19 PM
@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

louiscad

12/05/2020, 4:22 PM
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

Fabio Bombardi

12/05/2020, 4:23 PM
Of course. Yup
f

Fanis Paschos

12/05/2020, 8:35 PM
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

Fabio Bombardi

12/05/2020, 8:39 PM
@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

Fanis Paschos

12/05/2020, 8:40 PM
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

Fabio Bombardi

12/05/2020, 8:52 PM
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

Fanis Paschos

12/05/2020, 8:53 PM
Well, now I understand…because when I imported it, it notified me that the ‘java’ plugin has already been applied
f

Fabio Bombardi

12/05/2020, 8:53 PM
it's made for the arrowed one, not the crossed one library template.
f

Fanis Paschos

12/05/2020, 8:53 PM
I see
so, should I remove the android.library one?
in the top tier decleration?
f

Fabio Bombardi

12/05/2020, 8:54 PM
It depends. If your are using the
android()
target you cannot. But if you only need the
jvm()
target yes.
f

Fanis Paschos

12/05/2020, 8:55 PM
Got it…unfortunately I am using the android target as well 😕
f

Fabio Bombardi

12/05/2020, 8:56 PM
So still no joy 😉
f

Fanis Paschos

12/05/2020, 8:56 PM
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

Fabio Bombardi

12/05/2020, 8:57 PM
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

Fanis Paschos

12/05/2020, 8:57 PM
I see
if you find anything any time soon, please share it with us 🙂
f

Fabio Bombardi

12/05/2020, 8:58 PM
You can always try to file an issue requesting this feature if there's not already one filed.
f

Fanis Paschos

12/05/2020, 8:58 PM
I guess that there is one, but I will search now in the discussion forums
f

Fabio Bombardi

12/05/2020, 8:58 PM
f

Fanis Paschos

12/05/2020, 8:58 PM
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

Fabio Bombardi

12/05/2020, 9:00 PM
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

Fanis Paschos

12/05/2020, 9:01 PM
Ok. I will try to publish it in maven or something, as Louis mentioned above
haha, imagine myself how I feel
💪 1
f

Fabio Bombardi

12/05/2020, 9:02 PM
I think that this is the best choice for your scenario
f

Fanis Paschos

12/05/2020, 9:02 PM
Yeap, I think that as well
I have to start reading how to create a private maven repo to upload it there
👍 1
l

louiscad

12/05/2020, 10:04 PM
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

Fanis Paschos

12/05/2020, 10:13 PM
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

Fabio Bombardi

12/08/2020, 11:28 AM
Well done! 💪😎
✌️ 1