I have a library with a dependency that requires a custom repo
dependencies {
implementation 'com.chartboost:chartboost-sdk:8.1.0'
}
repositories {
mavenCentral()
maven { url "https://chartboostmobile.bintray.com/Chartboost" }
}
This works fine, but it forces me to add maven { url "https://chartboostmobile.bintray.com/Chartboost" } to every project that uses that library. I would like to know, is there a way to modify my own library so I wouldn't need to add the custom maven repo for that dependency? Something that would add all the repos in the library to the project. I tried switching implementation with api to no avail
You can put your repository into [USER_HOME]/gradle/init.gradle file:
allprojects {
repositories {
mavenCentral()
maven { url "https://chartboostmobile.bintray.com/Chartboost" }
}
}
then they are will be applied to all projects
Related
I am trying to use MPAndroidChart, but there is occuring build gradle problem.
I reference the github document below.
https://github.com/PhilJay/MPAndroidChart
I follow the 'Gradle Setup'
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
This is how I put the codes
and when I started to build it the error code is
Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'app\build.gradle'
Did I put the build code in the wrong way? or did I missed some important settings?
Probably, you need to append the entry, maven { ... } to the dependencyResolutionManagement.repositories clause in settings.gradle.
app/build.gradle
// repositories {
// maven { url 'https://jitpack.io' }
// }
settings.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
I know that this has been asked before, but despite adding maven in repositories cant resolve this error. please help.
Following is my module level gradle file:
Following is my top level gradle file:
Try this:
implementation 'com.github.barteksc:android-pdf-viewer:3.1.0-beta.1'
or if you want a more stable version:
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
and add jCenter in your repositories:
allprojects {
repositories {
jcenter()
………..
}
}
Change your module/build.gradle script.
repositories {
google()
jcenter()
}
dependencies {
//....
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
}
To use the implementation DSL you have to update the gradle plugin for android in the top level file:
buildscript {
repositories {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
//
}
}
The fact that JCenter is deprecated will not prevent you from using this library.
"JFrog will keep JCenter as a read-only repository indefinitely. Customers and the community can continue to rely on JCenter as a reliable mirror for Java packages".
You can add jcenter in your settings.gradle file:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
So there is nothing to worry about.
If you really want to sleep good at night, you can try to clone the library itself from Github and make your own local copy.
I will take some time and work but if you manage to do it, you will have an offline local version of the library.
Maybe I will try to do it myself in the future.
Anyway just wanted to give you all the options.
I personally still use JCenter.
I have an Android project with multiple modules.
Module A has a dependency on aar present in maven remote repository, which is specified in build.gradle as below
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile 'com.crashlytics.sdk.android:crashlytics:2.5.2#aar') {
transitive = true;
}
}
Module B has a dependency on another aar, which is specified in its own build.gradle
repositories {
maven { url 'http://maven.localytics.com/public' }
}
dependencies {
compile 'com.localytics.android:library:3.8+'
}
When I compile the project, I get the following error.
Could not resolve all dependencies for configuration ':-app:'.
> Could not find any matches for com.localytics.android:library:3.8+ as no versions of com.localytics.android:library are available.
Searched in the following locations:
https://maven.fabric.io/public/com/localytics/android/library/maven-metadata.xml
https://maven.fabric.io/public/com/localytics/android/library/
Looks like gradle picks up the url only from Module A.
If I specify the url in top level build.gradle, then it works properly. But I don't want to specify a module level dependency at the top level.
allprojects {
repositories {
jcenter()
maven { url 'http://maven.localytics.com/public' }
}
}
Is there a way to specify maven repositories in multiple modules ?
So our group has a private maven repository with a large number of libraries 'in-house'. So there only available on a vpn. bintray and jcenter is available on my vpn. What i want to do is have gradle check for a dependency first on the private maven repo, if not found then search bintray/jcenter for the library. How can i do this ? this is what i have tried:
In the top level build.gradle file i have:
buildscript {
repositories {
maven { url "https://myprivateRepo.com/libraries"
}
jcenter()
}
my assumption was that it would first check maven private repo and then check with jcenter afterwards but it seems to not be working, can anyone verify the set up ?
You're adding the repositories for your buildscripts (or plugins). You need to add it to your project / dependencies level.
Using it with buildscript will resolve plugins. You need that e.g. if you are using apt: apply plugin: 'com.neenbedankt.android-apt'
Remove the wrapping buildscript block:
repositories {
maven { url "https://myprivateRepo.com/libraries" }
mavenCentral()
jcenter()
}
dependencies {
compile "my:library:1.0.0"
// ...
}
Alternatively just set it on the project root build.gradle and apply to all projects like this
allprojects {
repositories {
maven { url "https://myprivateRepo.com/libraries" }
mavenCentral()
jcenter()
}
}
this is the way I added facebook repository in order to use FacebookSDK on an gradle-based android project
repositories {
mavenCentral()
mavenLocal()
maven {
url "http://mente.github.io/facebook-api-android-aar"
}
}
Now I have to add a new repository for the umano sliding menu (https://github.com/umano/AndroidSlidingUpPanel).
I've tried something like this (but it obviously doesn't work):
repositories {
mavenCentral()
mavenLocal()
maven {
url "http://mente.github.io/facebook-api-android-aar", "https://bitbucket.org/luciofm/m2repository/raw/master/"
}
}
You need to add it separately:
maven {
url "http://mente.github.io/facebook-api-android-aar"
}
maven {
url "https://bitbucket.org/luciofm/m2repository/raw/master/"
}