When Android Studio creates a project, the top-level build file has two repositories definitions, one inside buildscript and another inside allprojects.
// Top-level build file where you can add configuration options common to all sub- projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Where must I add another repository and why?
I think that repository inside buildscript is here to add the gradle plugin dependency, but I'm not sure...
Someone could clarify me, please.
Thank you!
Popular public repositories include Maven Central and the Google Android repository. Gradle provides built-in shorthand notations for these widely-used repositories. Under the covers Gradle resolves dependencies from the respective URL of the public repository defined by the shorthand notation.
Open the project where you want to use your cloned library, then select 'File > New > Import Module' from the Android Studio toolbar. Click the three-dotted button and navigate to your cloned repository. Select this repository, then click 'OK. '
Gradle declares dependencies on JAR files inside your project's module_name /libs/ directory (because Gradle reads paths relative to the build.gradle file). This declares a dependency on version 12.3 of the "app-magic" library, inside the "com.example.android" namespace group.
The buildscript
is for dependencies of your build files. You want to add a repository there if, for example, a task in your build.gradle
needs a plugin that is not found in the standard Gradle distribution, like a gwt wrapper.
The allprojects
is for dependencies needed by your application, like log4j, Guice, Guava and so on.
Also, be warned that using mavenCentral
for retrieving dependencies is a bit discouraged, because if the network is down or if the project is removed from their repositories, you won't be able to build your project anymore
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With