hide one library in another library for application in kotlin - kotlin

I have a kotlin .aar library A is depency on another library B for extention functions, and my application require to only use library A as dependency. Any suggestion to achieve that the application just add library A as dependency and library B is totally hidden to application.
I was looking at fat aar plugin, but looks like it's not maintained and no longer available.
Right now from my experiment, if library B is not added to application dependency, the application will get exception complain the class in library B is not found.

Related

What does "common" mean in kotlin documentation?

In kotlin standard library documentation i can see the following filters:
As far as i can gather, JVM means that internals of a package can be compiled into byte code, JS into javaScript and Native into binaries. But what does "Common" mean ?
Common means available for all platforms. It is an API that you can use directly in platform independent code in Kotlin Multiplatform projects.
Kotlin Multiplatform allows you to write common Kotlin code for multiple different platforms. For example, you could have a project with an Android app (using Kotlin/JVM for native Android applications) and a web interface (using Kotlin/JS). Then, you could share code between both subprojects.
As you have guessed correctly, JVM means it is available using Kotlin/JVM (compiling to Java bytecode).
If it is marked with JS, it is available for Kotlin/JS which transpiles the Kotlin code to JavaScript.
Finally, Native means it is available when using Kotlin/Native. This is different from compiling with native-image, which compiles JVM bytecode to native executables. For that, you would still use Kotlin/JVM.
If you write code in "common", then it can be compiled into any of the other targets, so you can share Kotlin code amongst the different platforms you are targeting. You can read more in the documentation.

Kotlin multiplatform library exporting dependencies for JVM

I’m creating a multiplatform for jvm and iOS on kotlin using Gradle.
For the jvm, even if I define my dependencies as implementation, they are included in the library generated .pom and with runtime scope.
By using implementation, I was expecting that these dependencies are not passed to the library consumer.
But, when I use this library on my other jvm project, Gradle is importing the library-specific version. Not the one that I set in my application dependencies.
in this case, I'm doing a downgrade. The library is using the dependency version 1.4.1, and on the application I want to use version 1.4.0.1.
By using implementation, I was expecting that these dependencies are not passed to the library consumer.
If you expect the consumers to provide those transitive dependencies themselves, you should use compileOnly instead of implementation.
The difference between api and implementation is that transitive dependencies declared with api will be visible and usable by the application by just depending on your library (seen at compile time AND runtime). With implementation, the transitive dependency will still be here at runtime but will not be visible on the compile classpath of the consuming application, so you cannot use the transitive dependency's declarations in the application's code.
Have a look at the table here:
https://docs.gradle.org/current/userguide/java_library_plugin.html
If you stick with implementation, you can still force a version for the transitive dependency in Gradle by using strictly or by excluding it and redeclaring it yourself. See the doc:
https://docs.gradle.org/current/userguide/dependency_downgrade_and_exclude.html

How Do Transitive Dependencies in KMM and iOS work?

Lets say I have a package, Shared Package that is shared with two KMM projects: KMM Project A and KMM Project B.
So we have Shared Package -> KMM Project A and Shared Package -> KMM Project B.
Now I want to use both KMM Project A and KMM Project B in my iOS app. How does that work? Is Shared Package bundled with both frameworks (i.e. I am including the same dependency twice?). Furthermore, does the Shared Package need to be a KMM Project to allow KMM Project A and B to generate the relevant iOS frameworks? Or can it be a pure Kotlin project?
Here is a diagram that might give more explanation of the situation I am trying to understand.
You need a wrapper "unbrella" module that depends on KMM Project A and KMM Project B, and have that generate your Xcode Framework.
You can technically generate 2 frameworks, one for each of the KMM Project A and B, but they will both have a copy of "Shared Package", along with relevant portions of the Kotlin standard lib, and most importantly, those 2 frameworks will be distinct on a binary level, so they can't communicate.
By that I mean, if "Shared Package" has a data class Foo, and you get that as a result from a call to "KMM Project A", say fun makeAFoo():Foo, and you have a function in "KMM Project B" that's defined as fun takeAFoo(foo:Foo), the Foo instance you get from makeAFoo() cannot be passed into takeAFoo(foo:Foo).
So, the short answer is you need a wrapper module that pulls in both of the "Shared Package" modules. You'll also need to export them through the umbrella.
See: https://touchlab.co/multiple-kotlin-frameworks-in-application/ and https://kotlinlang.org/docs/mpp-build-native-binaries.html#export-dependencies-to-binaries

Why does IntelliJ IDEA 13 require both lib project and lib itself (google-play-service) to be added as a dependency?

Reading Google instructions, I found that I have to import and reference the Play Service library into the project.
So I created a project, copied google-play-service_lib project, imported it as a library project, went to the main project and added this library as a Module dependency. However, I still have an error that IntelliJ IDEA does not recognize package com.amazon.device.ads.*.
So I had to add a library dependency as well, although this library already exists in the /lib directory of Play Service library project.
Am I doing something wrong or we're actually requested to add both dependencies in IntelliJ IDEA? If yes, is this maybe a bug in IntelliJ IDEA 13? I can't remember of having to do the same in earlier versions of IntelliJ IDEA (I have been using it for three years).
This is how it looks in the end and it works only this way! Check the last two dependencies.

Libraries, projects, modules and packages in Intellij Idea

I'm a beginner programmer and I'm learning how to work with Intellij IDEA. A project in IntelliJ IDEA has some different structures like libraries, modules and packages.
Can someone explain what the difference is between those structures and when to use a particular structure? e.g. I can't choose my package name (of a class) arbitrarily when it's already part of a module. What is the connection between those? I'm primarily having difficulties understanding the difference between a package and a module. (characters)
A project in intellij consists of modules. Modules can be java modules, or android modules or whatever. Modules contain your java code and all that stuff. A Module can reference a library which can be a project library or a global library. Global libraries have to be defined only once. Project library in every project you need them.
Packages are a java concept and are IDE independent.
Lets say I wanna do a little game. I would create a intellij Project called "mySuperGame". Then I would create two java modules from intellij, called "logic" and "ui". In the module settings of "ui" I would specify a project library to use opengl and a dep. to "logic". The package name of my logic classes would be "com.mysupergame.logic.XXX".
See http://confluence.jetbrains.com/display/IDEADEV/Structure+of+IntelliJ+IDEA+Project for more information.
IntelliJ IDEA supports everything eclipse has. But vise versa might not be true. Please check this table for the differences. IntelliJ support intelligent perspective and has many windows.
Read the documentation from IntelliJ idea.
Below comparison between Visual Studio (.NET) and IntelliJ (Java), which might be helpful for .NET developers migrating to Java: