If I need to use some library in multiple modules and add the line
compile 'example.path_to_library'
to both modules build.gradle,
will it create only one instance of the library classes and point to that or each module will have 2 separate libraries of the same stuff?
it will create only one instance of the library classes and point to that.
The library will be downloaded in your External Libraries folder and both the modules will access the same library.
if it solves your problem..do check this answer as correct..thank you, have a good day :)
Related
I'm setting up a Kotlin multiplatform project so I can reuse common code in multiple platforms for a single app. While building the common code for the app, I've extracted some base classes that I'd like to be able to reuse as a library in multiple multiplatform projects. I'm trying to add the library as a dependency in commonMain. There are a couple of things I don't understand.
First of all: is this currently possible?
If yes:
The default stdlib-common is a jar file, correct? How come a jar can be referenced as a dependency in commonMain if no Java can be used there? Or is it okay to use a jar compiled from pure Kotlin, as long as it only has Kotlin dependencies?
How do I compile a pure Kotlin jar that can be used in commonMain the same way as stdlib-common is used? Are there any sample build.gradle projects or guides for how this should be packaged?
If no:
What options do I otherwise have to reuse code over multiple multiplatform projects, if I want to avoid duplication? Do I actually need to keep all source within the actual commonMain source folder? Can it be linked from another folder if so? I tried adding additional content roots but it didn't seem to work since Gradle controls the configuration and I'm not sure how to add additional content roots in commonMain through Gradle.
Thanks in advance.
I got it working, mainly from looking through this thread and looking at this example. Although some of it might be dated by now, it helped me understand the following:
MPP1 can have another MPP2 as a dependency. Here is a list of MPP libraries for reference.
MPP2 needs to generate artifacts for the same set of platforms as it is used in by MPP1.
MPP2 generates platform artifacts along with a module file where they are described. MPP1 can then use the below configuration. Thanks to the module file, it's not required to explicitly add each platform's corresponding dependency, the dependency only needs to be declared in commonMain.
commonMain {
dependencies {
implementation kotlin('stdlib-common')
implementation 'com.company:mpp2:1.0'
}
}
if you have 2 modules that has dependency on support v14
do you put the same dependency in both modules or you put it in one? I mean does it make the apk include the code twice and hit the 65 k limit
Thanks
Put the dependency in every module that needs it. Doing so makes the modules more independent. You can reuse a module in another project without having to worry about the dependencies.
It will be included in the APK only once.
I have to create 5 Android Application with some common modules. As I have think, I have to create one project with all the optimization and then copy paste for other projects but in that scenario we have to change all the resources. All the other things will be same.
As Android Studio is best IDE, Is it providers any functionality to make that type of functionality with easiest way. Something like Common Modules or Libraries.
Any Help, It would be appreciated. Thanks.
create repository in maven central and add your library there,then you can add your library by gradle
here is link for publishing your library to repository
I'm working on an Android library. This library use other local libraries/modules. But these sub-modules are not published in anyway to a public repository. I'm searching ways to embed these proprietary submodule in the main library.
I've already found some ways, like building a fat aar but this is not a good practice at all. I was wondering if someone know a good way to do this.
EDIT:
I've made a simple script that before the build of the main library, assemble the sub modules and copy the output aar to a new modules which is the one generated by Android Studio. The script works but Android didn't add this empty modules aar in the main library when creating the aar.
I have to add a 3rd party library to my project.
Let's say the library is called XLib and it is made by vendor A.
I already have in my project a library with same name (XLib) but it is made by vendor B and they are 2 different things, I need them both.
how do I handle this scenario in Android Studio?
Thanks,
how are you importing these libraries? are they library modules or gradle dependencies?
if they are library modules, and you have the source, i would recommend renaming the modules XLib-VendorA and XLib-VendorB. Assuming they don't also have overlapping package structures, that may be all you need.
if they are gradle dependencies, then they should originate from different group names, so you would only be concerned about package collisions at that point.