I've got to integrate a 3rd party library in to My Android Studio project and that works great without any issue.
It asks to add following configuration to the project's build.gradle (sample configuration as follows)
allprojects {
repositories {
jcenter()
maven {
url "http://link/location"
}
}
}
And then to add dependencies to the app.gradle as follows
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:support-v4:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'xxx.xx:xxx:1.11.0:#aar'
}
But my requirement here is to create a library module (with in the project) that wraps this 3rd party library integration with in that.
Idea is to distrubute my library that contains few public methods (that use this 3rd party library methods in that) to others to integrate with in their apps.
As I mentioned earlier to use this 3rd party library I need to use their own Maven Repository and asks to place setting in Projects build.gradle. But as I want to warp all within My Library Module I just tested adding repository bit in to Library Module's build.gradle. But this provides compile errors.
repositories {
jcenter()
maven {
url "http://link/location"
}
}
My Question is can I achieve what I am trying to do? If so what I am missing here. Thanks
EDITS
Briefly what I am trying to do.
This 3rd party library is not available in standard jcenter or mavenCentral repositories. Instead it resides on their own Maven Repository Server. That's why when need to integrate it asks to specify server location in root level (project) build.gradle as follows. Then I can add dependencies...
allprojects {
repositories {
jcenter()
maven {
url "http://link/location"
}
}
}
But as I want to wrap up this integration within Library Module tried to add above repository location in to gradle.build with in My Library Module.
So I can Access those classes but Main Application that compile MY Library project saying can't resolve libraries in 3rd party Library location. Actually Main Application should NOT want to know as long as My Library Module knows it...
Actually Main Application should NOT want to know as long as My Library Module knows it
If the third-party module is open source, fork it, put your wrapper code in the fork, and ship the fork by your own means.
If the third-party module is not open source, discuss with the vendor what your options are for distributing this code by some other means (e.g., your own internal repository, alongside your own library).
Related
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'm using Android Studio 3.0.1 and I'm trying to add an online dependency and while Gradle initially syncs without a problem it doesn't show my dependency in External Libraries and my code that references the dependency doesn't work.
Here's a snippet of what my build.gradle file looks like:
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/groups/public/' }
}
dependencies {
compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT'
}
I'm pretty new to android development (took over an existing project from a dev who quit without leaving any documentation) so I'm not sure if this is a mistake with how to add a project dependency or if there is a problem with the dependency that I'm trying to add. Any help would be greatly appreciated!
I was able to get this to work by changing the dependency declaration to:
compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT', classifier: 'jar-with-dependencies'
The library artifacts up on the repository include an apklib and a JAR with a special classifier. The apklib format is not supported by Android Studio, and unfortunately the classifier on the JAR means that it's not accessible simply using the group-name-version format when declaring dependencies.
Your build.gradle file seems fine. If you want to keep the library specified as an external library, you can try and define the dependency using the alternative notation, replace:
compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT'
with:
compile 'com.fortysevendeg.android:swipelistview:1.0-SNAPSHOT'
The alternative approach is to download the jar file yourself and use it as a local dependency. If you navigate to the maven repository you can inspect the package which is included as a dependency and download the jar directly. Place the jar file in the libs folder of your project and add the following to your build.gradle file:
compile fileTree(dir: 'libs', include: ['*.jar'])
For further details on how to configure the dependencies of your gradle project, check out the Android Studio documentation here.
Based on the information you have provided, this should fix your issues. If this does not solve the error then there may be other issues with the project.
Your dependencies should not placed in the top-level build.gradle file where the repositories are defined. There is even a comment in that file that says so, by default.
You app dependencies should be the module's build.gradle along with the others like android-support
Additionally, that library is very old, and is a SNAPSHOT build, meaning it isn't meant to be generally used in a release environment. You should find an alternative... And there are plenty of other ListView swiping ones
I want to create the library and have access to it through the Internet.
In Android Studio (via Gradle) dependency may be added in this way:
In build.gradle (Module app):
dependencies {
...
compile 'com.android.support:design:23.1.0'
compile 'com.squareup:otto:1.3.8'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
...
}
How can I add my own library in this way from github?
To achieve it you have some ways:
publish your library (artifact) in central maven or jcenter.
use a github repo and the jitpack plugin
use a private maven
The point 2. is very simple.
Just push your codein github and modify the gradle script in the project where you want to use it.
Just add this repo tp your build.gradle
repositories {
// ...
maven { url "https://jitpack.io" }
}
and the dependency:
dependencies {
compile 'com.github.User:Repo:Tag'
}
To publish a library in Central Maven or JCenter, it is very long to explain in an answer. Hovewer you can read these posts:
Publish on JCenter
Publish on Central Maven. Another blog for Central Maven
Refer Jitpack is best to import your project or libs from Github to gradle
For more information refer Gabriele Mariotti answer
For a quick solution, as the others have said JitPack is probably the way to go. However, if you want to make your library available to a wider audience you should probably add it to jcenter since this is set up by default in Android Studio now. (Previously it was Maven Central.)
This post gives a detailed walkthrough of how to do it. The following is a summary:
Create the Android library
Test to make sure the library is usable locally
Publish the library on Bintray
Add the library to Jcenter
Then all people will have to do to use your library is add a one liner to their build.gradle dependencies.
I'm using Square's Wire library for my Android app, using Android Studio with Gradle.
I originally added the wire-runtime-1.2.0.jar into a libs folder in my module, and added the dependency to Gradle like this in my build.gradle file:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
That worked fine.
I'm new to Gradle and Android Studio, but based on the way I'm depending on the Google Support and Play Services libraries, I thought I might be able to remove the wire-runtime-1.2.0.jar library from my repository and just declare a dependency like this (the line is from the Maven repository):
dependencies {
compile 'com.squareup.wire:wire:1.0.0'
}
But if I do that then I hit this error:
Gradle: package com.squareup.wire does not exist
Is there a way to set up this dependency without importing the JAR file directly? Or does that only work for libraries that you can install through the SDK Manager?
Some packages, like com.squareup.wire, have multiple artifacts in Maven Central. You need to choose the right one for your needs. In this case, the equivalent of wire-runtime-1.2.0.jar is the wire-runtime artifact, not the wire artifact.
Here's what your dependencies section should look like:
dependencies {
compile 'com.squareup.wire:wire-runtime:1.2.0'
}
my problem is simple:
in the web there are numerous ways and tutorials on how to include jars in an android application through eclipse, android studio etc.
I want to do it manually; so, I want to know which files do I have to edit to bind my app
with the specific jars.
in the web there are numerous ways and tutorials on how to include jars in an android application through eclipse, android studio
That is because the use of third-party libraries is tied to the build system being used to build the app.
I want to do it manually
It is unclear what "manually" means in this context.
If you mean that you are using Ant, just put the JAR(s) in your project's libs/ directory, and you are done. Note that this will work with Eclipse as well.
If you mean that you are using Gradle, you will need something like this in your build.gradle file:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
Or, if the JARs can be found in a Maven or Ivy repository, you can reference those as well, by defining the repository in the repositories block and then simply specifying the artifact in the compile directive:
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:11.0.2'
}