I had a problem writing android projects,I have a build.grade file as follows. When I build the project, I pull the project dependencies in the order A->B->C->mavenLocal? Or mavenLocal -> C->B->A? Or any other search order? Is it that once a Maven pull is successful there is no further search?Please help me~
allprojects {
repositories {
maven { url A }
maven { url B }
maven { url C }
mavenLocal()
}
}
I want to add jitpack.io as a repository in my gradle file.
This is my gradle root file:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Since I DON'T have a "allrepositories" to put my dependency there (only works there), I've created and added this code after buildscript code:
allprojects {
repositories {
maven {url 'https://www.jitpack.io'}
}
}
But this is the error I get
Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'
Gradle 6.8 introduced central declaration of repositories, new way to define repositories. Latest documentation (7.4.2) can be found here.
Remove the dependencyResolutionManagement block from the setting.gradle file to have your project work the old way.
You can add jitpack.io as a repository inside dependencyResolutionManagement in settings.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
You need to update the settings in settings.gradle and change repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) to repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
and finally, add maven { url 'https://jitpack.io' } to the repositories block.
The complete settings.gradle file will look like this:
import org.gradle.api.initialization.resolve.RepositoriesMode
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url 'https://jitpack.io' }
}
}
rootProject.name = "appname"
include ':app'
Replace this line:
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
use this:
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
Before
After
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
Go To Settings.gradle and put it inside the repositories
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
In gradle version '7.1.0' just need to add maven { url 'https://jitpack.io' } in setting.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Solution:
You can add this url
in settings.gradle(Project Settings) file,
which you will find in Gradle Scripts,
Add your url inside dependencyResolutionManagement like this
dependencyResolutionManagement{
maven {
url 'https://jitpack.io'
}
}
#See below pic for complete reference,
Now sync it,
it will work,
Thank you!
:)
In my case, I just delete the dependencyResolutionManagement{...} statement that in the settings.gradle the new project is default added in settings.gradle
As the Android studio is upadated so you have to control your dependency form your setting.app
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url 'https://jitpack.io' }
}
} rootProject.name = "EmfDetector"
include ':app'
Kindly place this line the respiratory
maven { url 'https://jitpack.io' } //as i have done above
`
if you access repository secured by login/password - try this
here example based on GitHub repo
<settings.gradle file>
groovy
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/OWNER/REPOSITORY")
credentials {
username = "${usernameFromYourGradlePropertiesFile}"
password = "${passwordFromYourGradlePropertiesFile}"
}
}
}
}
kotlin
// ...
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/OWNER/REPOSITORY")
val userNamePropertyFromGradleProperties: String by settings
val passwordPropertyFromGradleProperties: String by settings
credentials {
username = userNamePropertyFromGradleProperties
password = passwordPropertyFromGradleProperties
}
}
Add this line in settings.gradle
See more information here
some old advices let you add maven { url "https://jitpack.io" }into root build.gradle, but as long as you are using latest version of as, you can simply put it into settings.gradle instead of build.gradle
In my case, I just add mavenLocal() in settings.gradle
You either could delete the
dependencyResolutionManagement{}
block in the
setting.gradle
file and then add the repositories in the
build.gradle
at Project Level as, for example
allprojects {
repositories {
google()
mavenCentral()
} }
or write a repository directly in the
dependencyResolutionManagement{}
block. Don't forget to Sync the Project by clicking top-right on
Sync now
add it to your settings.gradle inside dependency resolution management like this:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
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.
How can use this Project
I add this line on my build.gradle file in dependencies section:
compile 'com.otaliastudios:zoomlayout:1.0.3'
But didn't compile the project. I have this information:
Enter image description here
How can I fix this?
Regards
Marcin
You have to add Google Maven repository to your project build.gradle. On Android Studio 2+:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
On Android Studio 3+:
allprojects {
repositories {
jcenter()
google()
}
}
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()
}
}