I am working on Android Studio and my activities include ViewPagers. For that I had to install packages (Android Support Repository and Android Support Library). Now that I have already installed these, I opened gradle.build and this is what I see:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
My question:
What should I add and where should I add it in here?
Also, I cant locate SDK in my computer :/ . A little help would be really appreciated.
Android use multi project build setup. Your existing file is MAIN build.gradle file.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// this is where you need to put dependencies of your BUILD SCRIPT
}
}
allprojects {
repositories {
jcenter()
}
dependencies {
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.1'
// This is where you put dependencies EVERYONE of your modules need.
}
}
In the sub directories of your main build.gradle resides individual build.gradle files.
Module A
dependencies {
// This is where you put dependencies, your module need.
}
Module B
dependencies {
// This is where you put dependencies, your module need.
}
There are more than one gradle files. one of them is located in your project directory. Same name (build.gradle). find it and put your dependencies there.
To find your SDK path: File -> Project Structure -> SDK Location. (Android Studio v0.8.14)
Related
I'm trying to add a maven repository to my project by adding it to build.gradle
repositories {
maven {
url "https://XXX/"
}
}
It works fine when I build in the console. When I try to build it with Android Studio, the dependency that I use in that repository is not found.
When I add the repository to File > project structure > project > Default library Repository bam! it works.
What am I doing wrong? why do I have to duplicate the information? What is exactly the purpose of that configuration since it's already in build.gradle file?
Thank you
Aghilas, i am not sure if it is issue with https or http.
I am putting down what works for me. you can add 'maven()' in the block depending on that repo is required for buildscript functionality or for your app.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
Every time I build my android project it gives me this Error
android Error:(44, 13) Failed to resolve com.esri.arcgis.android:arcgis-android:10.2.7
Can anyone help me regarding this ?
The problem is solved like that
1.
add the following lines
// Add the following ArcGIS repository
maven {
url 'https://esri.bintray.com/arcgis'
}
in the build.gradle of the project module
to be like that
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
//**Added .. for ArcGIS
maven {
url 'https://esri.bintray.com/arcgis'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
// Add the following ArcGIS repository
maven {
url 'https://esri.bintray.com/arcgis'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Also , I edited the version of arcgis dependency in the app module build.gradle to be like that
compile 'com.esri.arcgis.android:arcgis-android:10.2.8'
May be needful.
In the app module build.gradle file, within the dependencies block, add a directive to include the ArcGIS Runtime SDK for Android dependency to your app.
App module build.gradle file
Fallow all the steps from here
dependencies {
// Add ArcGIS Runtime SDK for Android dependency
compile 'com.esri.arcgis.android:arcgis-android:10.2.7'
}
This may be due to version mis-match of Android Studio. So, try giving latest dependencies in app level build.gradle. In my case I changed it from 10.2.6 to 10.2.8
compile 'com.esri.arcgis.android:arcgis-android:10.2.8'
I have multiple modules and every module uses exact same dependency. Because it is annoying to maintain that dependency in all build.gradle files (version updates etc.) I'd like to have it in project build.gradle. Is that possible please?
I tried to:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
compile 'joda-time:joda-time:2.8.1'
}
}
allprojects {
repositories {
jcenter()
}
}
but that doesn't work as it seems that gradle is not able to find DSL for compile. Is there any other way please?
Thank you
It's called centralize the support libraries dependencies in gradle. Working with multi-modules project, it is very useful to centralize the dependencies, especially the support libraries.
http://gmariotti.blogspot.in/2015/07/how-to-centralize-support-libraries.html
Correct me if i'm wrong but what's inside buildscript are dependencies for build.
When I generate my project build.gradle there is note :
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
So no, you can't put dependencies for all your module here but maybe there is a plugin for that.
You cannot centralize the dependencies for all (sub-)projects, but is is very easy to centralize the version numbers. In build.gradle in the root add this:
ext {
jodaTimeVersion = '2.8.1'
}
And in build.gradle of the modules that need Joda-Time add this (pay attention to the double quotes):
dependencies {
compile "joda-time:joda-time:${jodaTimeVersion}"
}
I am trying to add google play services library in Android studio.I have added the google play services in build.gradle.
But it is now working for me.I have referred many SO Post regarding to this.But it doesn't solved my problem.
Below I am posted the build.gradle code where I have added the google play services.
build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
apply plugin : 'android'
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
}
allprojects {
repositories {
jcenter()
}
}
}
While adding the google play services in dependencies at gradle compile com.google.android.gms:play-services:4.0.30. I am getting an error:plugin with id not working.
Anyone can help me with this.Thank you.
The build.gradle you have posted seems to be the project configuration. The global project build.gradle has the buildscript tag and also the comment about not adding application dependencies as can be seen in your question.
There should be another build.gradle inside your app module where you should also find something similar to this depending on your version of Android Studio and Gradle,
apply plugin: 'com.android.application'
android {
...
}
dependencies {
...
}
Place your compile 'com.google.android.gms:play-services:4.0.30' inside the app module's build.gradle depedencies
Use latest version of play services:
compile 'com.google.android.gms:play-services:7.5.0'
Update:
Think you using wrong gradle file. You must add the above code in the gardle file under app folder.
Please add your library dependencies in the build.gradle file the resides inside your app module
apply plugin: 'com.android.application'
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
}
android {
...............
}
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
}
You should not add these dependencies inside build.gradle file for the root folder
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
Do not place your application dependencies inside the outer build.gradle file they belongin the individual module build.gradle files
I want to compile jar file in Android Studio. But it come out error say "Could not find property file on org.gradle.api;interna.
Here is the code:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
compile file 'libs/jtds-1.2.7.jar'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
You don't need to download the jars and add to libs, you can use the jcenter repo to add the dependency, replace compile file 'libs/jtds-1.2.7.jar' for
compile 'net.sourceforge.jtds:jtds:1.3.1'
If you want to search for other dependencies you can search here http://mvnrepository.com/artifact/net.sourceforge.jtds/jtds/1.3.1