I am confused why same repositories tags are required in multiple places in an Android project. Why don't we have all repositories under one tag, and the compiler searches everything from there.
My particular case is:
I created a library module and added it in a project. In my library gradle file, I have:
implementation 'com.github.jkwiecien:EasyImage:1.3.1'
for which I added maven { url "https://jitpack.io" } in repositories tag in the library's gradle file. I want EasyImage in the library only, not in the project. But it wont compile until I added this same jetpack.io in Project's app/build.gradle file. Why do we need to do this?
I want to distrubute my library and I don't want the users to add things that are already added in my library and are not required by their project.
Edit:
If you put jitpack repository url in your Project level build.gradle instead of app level build.gradle it will work for both. When you upload your library to JitPack, it automatically 'builds' your library for you but in your case your library is being built locally so it needs the repository url in each build file to build them separately. However you should keep the repository url in your library because eventually you will be distributing it and JitPack won't be able to build your library module if you have the url in your project build.gradle file instead of repository.
Previous Answer:
From what I understand:
You are using EasyImage in your library, and when you add the ibrary to your project, you want to use the same EasyImage library that you loaded in your library instead of adding it to your project.
if you load your library using 'implementation' like this:
implementation 'com.github.you:yourlibrary'
you will not be able to access dependencies that 'yourlibrary' uses. But if you load it using 'api'
api 'com.github.you:yourlibrary'
Now you can access EasyImage from this library instead of adding it again.
This was added in Gradle 3.0 and it works the same way as 'compile' keyword used to work(which is deprecated now). You should checkout this article for detailed explanation.
Why this behavior?:
By using imepentation,
if any implementation in EasyImage is changed, Gradle just needs to recompile EasyImage and Your library as any other class which does not import your library directly cannot use any implementation of it.
But if you use api to load library, If any change is implemented inside EasyImage, gradle needs to recompile EasyImage, Your library and all other modules which import your library as any other module might use implementation of EasyImage (like your app).
Related
I know the way using 'flatDir'.
But android studio warn do not use flatDir.
My project is android library.
I add jniLib in sourcet and use implementation files.
Then, I could add direct aar dependency to my lib and app which use my lib.
But I can't add dependency to androidTest in my android library project.
I want to use androidTestImplementation but my project is multi flavor build and there is no API flavor[Debug|Release]AndroidTestImplementation with files arguments.
I tried to search the way, but failed.
Now, I use flatDir and ignore warning.
How can I solve this problem?
It would be easier for me to show you but the long story short.
Main Application
Created a Library lets call it SECOND
Created a Shopping List Library call it THIRD
When I add my THIRD dependency to my SECOND library when using implementation in the gradle file, I am not able to implement interfaces for some reason. When using api it works just fine.
Also, we are adding this by importing the aar and pom file manually.
Project Level Gradle For SECOND
allprojects {
repositories {
google()
jcenter()
maven { url "$projectDir/../THIRD" }
}
}
Only way to actually allow access to the interfaces is to use API
api('com.THIRD.#aar')
This is quite as expected: declarations from implementation dependencies of a library are not visible during compilation of the library usages and are only available at runtime.
On contrary, api dependencies are visible during compilation of the library usages, too.
You should only use the implementation configuration if you don't want the library users to see the declaration from a dependency, which is certainly not the case if you expect the user to implement an interface from the dependency.
See: Gradle dependency configuration: implementation vs api vs runtimeonly vs compileonly
I have a utility library that I have pushed to a JFrog artifactory.
Now I am able to include that library in another project through gradle implementation (Not including it as a submodule, but getting it from local maven repo).
My question is the utility library uses some other libraries which my main project also requires.
Now, in my understanding using "api" with internal dependencies of my utility library, should have allowed those dependencies to be available to my main project, but it's not happening.
I wanted some clarification on this as to how I can allow my library internal dependencies to be available to my main project. Because, otherwise I will just be importing them again in my main project, which I do not want to do.
I have an Android application using an Android library. The library is a pretty big open-source project on GitHub, and its authors publish the artifacts to Bintray. I can specify the dependency with the usual syntax dependencies { implementation 'group:artifact:version' } in the app's build.gradle.
Now I want to change some code in the library. I git clone it on my machine, I make my changes, then I build the library. But how can I tell my app to use the library I built locally, instead of the one in Bintray?
I don't want to follow the approach in Gradle Local Project Dependency, because that means that the library code is now part of the application project, but I really want to keep things separated.
I think the solution involves publishing to a local Maven repository. I followed the guide at https://proandroiddev.com/tip-work-with-third-party-projects-locally-with-gradle-961d6c9efb02 but the app's Gradle is still picking the original library from Bintray.
Bintray-based projects have the install task. That's the one to be used instead of publishToMavenLocal.
When using install, the artifact version is automatically set to X.X.X before publishing to the local repository. Therefore, in order for the app to pick up the local library, you have to edit the implementation row to group:artifact:X.X.X.
As the guide https://proandroiddev.com/tip-work-with-third-party-projects-locally-with-gradle-961d6c9efb02 suggests, you also need to add mavenLocal() as the first entry in the repositories section in the top-level build.gradle of the application.
What are dependencies ?
Why do we add dependencies ?
I searched a lot but could not find the answers to above questions.
In Android Studio, dependencies allows us to include external library or local jar files or other library modules in our Android project.
For example: Suppose I want to show some images in ImageView. But I'm using Glide Library to enhance the smoothness of application. So I have to add a dependency in the build.gradle(Module App) as:
compile 'com.github.bumptech.glide:glide:3.7.0'
So Now I can use Glide library :) and show my images.
Note: Glide library is the bumptech's library but still I can use it in my project from 1 line of code of dependency.
Whenever you add a dependency to your gradle file, it will download the added libraries, and add them to your project so that is available in your project. It makes it easy to manage external libraries in your project.
To study more , visit : https://developer.android.com/studio/build/dependencies.html
if you want to use external libraries or modules in your android
project you have to add the dependancies so that you may be given the
authority to use that particular library otherwise that will not be accessible to you inside the project.
so, its concluded that:
The Gradle build system in Android Studio makes it easy to include external binaries or other library modules to your build as dependencies. The dependencies can be located on your machine or in a remote repository, and any transitive dependencies they declare are automatically included as well
for further you can visit this link:
https://developer.android.com/studio/build/dependencies