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 ?
Related
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
I am new to Android development. I have created a new project with Android Studio and need to import jetbrains exposed library into my existing project. When I tried to follow the exposed Getting Started guide to add the following into the build.grade file:
repositories {
maven {
url "https://dl.bintray.com/kotlin/exposed"
}
}
dependencies {
compile 'org.jetbrains.exposed:exposed:0.10.2'
}
I get the following error:
Could not find method compile() for arguments [org.jetbrains.exposed:exposed:0.10.2] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I have been searching the internet for a couple of days now but still could not find out what's the problem.
This is the build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.40'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
repositories {
maven {
url "https://dl.bintray.com/kotlin/exposed"
}
}
dependencies {
compile 'org.jetbrains.exposed:exposed:0.10.2'
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Hopefully someone could help me.
Thanking in advance.
You should put this dependency in the module level build.gradle file - by default, this is in the app folder, as opposed to the project level build.gradle file, which is in the root of your project.
Also, you should use implementation instead of compile, since you're using a newer than 3.0 version of the Android Gradle plugin:
repositories {
maven {
url "https://dl.bintray.com/kotlin/exposed"
}
}
dependencies {
implementation 'org.jetbrains.exposed:exposed:0.10.2'
}
Yesterday, I updated Android Studio to 3.1 and I'm getting this error :
Could not find org.jetbrains.trove4j:trove4j:20160824.
Searched in the following locations:
https://repo.maven.apache.org/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
https://repo.maven.apache.org/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.jar
https://dl.google.com/dl/android/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
https://dl.google.com/dl/android/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.jar
Required by:
project :library > com.android.tools.build:gradle:3.0.1 > com.android.tools.build:gradle-core:3.0.1 > com.android.tools.lint:lint:26.0.1 > com.android.tools.lint:lint-checks:26.0.1 > com.android.tools.lint:lint-api:26.0.1 > com.android.tools.external.com-intellij:intellij-core:26.0.1
This is my project's gradle file :
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// classpath 'com.google.gms:google-services:1.5.0-beta2'
classpath 'com.google.gms:google-services:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
maven {
url 'https://maven.google.com/'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is my gradle-wrapper-properties's distdistributionUrl:
distdistributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip
Try to replace all occurences of mavenCentral() with jcenter() in your gradle builds
Because jCenter will close in May, you should replace it with Maven. Thanks to giorgos.nl now we can add Trove4j:20160824. Thanks to Xavier Rubio Jansana we can replace maven { url 'https://plugins.gradle.org/m2/' } with gradlePluginPortal().
In root build.gradle write:
buildscript {
repositories {
google()
gradlePluginPortal()
}
}
allprojects {
repositories {
google()
mavenCentral()
// org.jetbrains.trove4j:trove4j:20160824.
gradlePluginPortal()
}
}
To add libraries that have not still been moved to mavenCentral, use this method.
Root build.gradle:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Then you should search GitHub repositories of not resolved libraries. App's build.gradle example with two libraries:
dependencies {
// When a library has tags.
implementation 'com.github.RedMadRobot:input-mask-android:6.0.0'
// When a library doesn't have tags.
implementation 'com.github.savvisingh:DateRangePicker:master'
}
Now we can launch an application and build apk without errors.
I had the same mistake ... and for me the following worked:
Add jcenter() to repositories {} of allprojects
And add compile 'org.jetbrains.trove4j: trove4j: 20160824' in the build.gradle app module
I had this same error. I also had jcentre() at the appropriate place. But still it was not working.
One thing you can do which worked for me is clear the caches:
1. Close Android Studio.
2. Clear caches in here:
C:\Users"username"\.android\caches
C:\Users"username"\.gradle\caches
3. Open Android Studio.
Also make sure you have the version of the gradle which is newer than the minimum required.
I had an issue with gradle thinking I wanted multidex 1.0.2 so I setup the repository in the top level build file and moved it out of the buildscript (as per: Android Studio 3.0 Beta 1: Failed to resolve: com.android.support:multidex:1.0.2):
allprojects {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
}
However, Fabric seems to dislike this. In the buildscript sections of my project (and library) I have:
buildscript {
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
And now I get:
Error:Could not find any matches for io.fabric.tools:gradle:1.+ as no versions of io.fabric.tools:gradle are available.
Searched in the following locations:
file:/Applications/Android Studio 3.0 Preview.app/Contents/gradle/m2repository/io/fabric/tools/gradle/maven-metadata.xml
file:/Applications/Android Studio 3.0 Preview.app/Contents/gradle/m2repository/io/fabric/tools/gradle/
https://jcenter.bintray.com/io/fabric/tools/gradle/maven-metadata.xml
https://jcenter.bintray.com/io/fabric/tools/gradle/
Required by:
project :
How can I resolve this conflict? How to I specify to fabric, if not in all projects, where to get its own dependencies?
Error:Could not find any matches for io.fabric.tools:gradle:1.+ as no versions of io.fabric.tools:gradle are available.
It happens since gradle is looking for the plugin only in the jcenter repo.
To setup fabric you have to use it:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
It is required by the gradle plugin.
Then you have to add:
repositories {
maven { url 'https://maven.fabric.io/public' }
}
It is used by the dependencies added in the projects.
A colleague managed to resolve it with the following declaration in the app's build.gradle file:
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://maven.google.com' }
}
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()
}
}