I have an app and an android library in my application, in development env i would like to provide a project level dependency i.e. dependency in the
(Project:XXX) build.gradle file.
This is how my project level build.gradle looks (partial view)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
compile 'io.reactivex:rxandroid:1.1.0'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
compile 'io.reactivex:rxjava:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
I get an error Gradle DSL method not found : compile().
Is there a way in android to provide common project level dependency.
You can't add dependencies to any other scope except of classpath in the buildscript block.
Here's how you declare a project dependency (in another project, not in buildscript):
dependencies {
compile project(':shared')
}
You are using the dependencies block inside the buildscript. It is wrong.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
dependencies {
compile 'io.reactivex:rxandroid:1.1.0'
compile 'io.reactivex:rxjava:1.1.0'
}
Related
After updating android studio 3.1.2 my existing project gives error at
dataBinding.enabled = true
error is as follows-
Failed to resolve: com.android.databinding:library:3.1.2
Failed to resolve: com.android.databinding:adapters:3.1.2
my gradle dependency are as follows-
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:25.1.0'
implementation 'com.android.support:recyclerview-v7:25.1.0'
implementation 'com.android.support:preference-v7:25.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.0-beta3'
implementation 'com.firebase:firebase-jobdispatcher:0.5.0'
// Instrumentation dependencies use androidTestCompile
// (as opposed to testCompile for local unit tests run in the JVM)
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support:support-annotations:25.1.0'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test:rules:0.5'
}
I also tried
android.databinding.enableV2=true
but its also not working
When I tried to update build tool version to 4.4 then I found this error. I f I do not update the build tool version then its working fine.
check it this below code in your project level gradle file ..
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
According to the Android Team answer you had to add
google()
too all repositories
and priority is important. so other repositories must be added after google()
Downgrade to 3.1.0 in project level build.gradle file, then rebuild the project.
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
I hope this helps
I also has the same issue I ensured that I added google() to all repositories and also I downgraded gradle to 3.1.0 from 3.1.4 and my project was successfully build.
Another TIP: We can also add the below code to our build.gradle(project) which takes cares of libraries conflicts with new dependencies
configurations.all {
resolutionStrategy {
force"com.android.support:supportannotations:$androidSupportVersion"
force "com.android.support:support-v4:$androidSupportVersion"
force "com.android.support:appcompat-v7:$androidSupportVersion"
force "com.android.support:design:$androidSupportVersion"
force "com.android.support:recyclerview-v7:$androidSupportVersion"
}
}
And you can keep your libraries in a separate file such as libraries.gradle and include them in build.gradle(project)
buildscript
{
apply from: "./libraries.gradle"
}
I added Data-Binding to my project and the next time I build project, I faced the same issue, more specifically logcat displayed this message:
Failed to resolve: com.android.databinding:library:3.1.2
Failed to resolve: com.android.databinding:adapters:3.1.2
As per accepted answer, I checked my Project Level Gradle File to see whether it was missing google() in its repositories, but it was already there.
Build multiple times, but all in vain.
Then I did what my Android Master once told me to do, just in case when everything fails.
File -> Invalidate Caches/Restart.
Next time the project opened it build successfully.
I am building a project in android studio 3.0 with android plugin 'com.android.tools.build:gradle:3.0.0-alpha1' and gradle version gradle-4.0-milestone-1-all.zip.
Used maven repo as well:
maven {
url 'https://maven.google.com'
}
Also, Using android Room persistence and lifecycle in my project. Already declared below dependencies in my app gradle file:
compile "android.arch.lifecycle:extensions:1.0.0-alpha1"
compile "android.arch.persistence.room:runtime:1.0.0-alpha1"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
When Sync and build the project it's showing below error:
Failed to resolve: android.arch.lifecycle:extensions:1.0.0-alpha1
Am I missing something or any other solution for this issue.
I have fixed the issue by updating my app build.gradle file like below:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Actually had to remove the maven repository from buildscript repositories and added to allprojects repositories as shown above. Also you can keep the maven repository at both places but must include in allprojects repositories to fix the issue.
Add in app/gradle file
compile "android.arch.lifecycle:extensions:1.0.0-alpha4"
compile "android.arch.persistence.room:runtime:1.0.0-alpha4"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha4"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha4"
add maven to project based gradle
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
it will compile easily
am find solution work with me Room
Dependencies for Room, including testing Room migrations and Room RxJava
dependencies {
def room_version = "1.1.1"
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version" // use kapt for Kotlin
// optional - RxJava support for Room
implementation "android.arch.persistence.room:rxjava2:$room_version"
// optional - Guava support for Room, including Optional and ListenableFuture
implementation "android.arch.persistence.room:guava:$room_version"
// Test helpers
testImplementation "android.arch.persistence.room:testing:$room_version"
}
as the document says: https://developer.android.com/topic/libraries/architecture/adding-components
you can change "https://maven.google.com" to "https://dl.google.com/dl/android/maven2/" to solve the problem.
You require latest gradle version 'com.android.tools.build:gradle:3.0.0-alpha2' and Studio Version 3.0+ to use Room
Just add maven { url 'https://maven.google.com' } to your project gradle
open preference for mac or you can open setting for windows then search proxy setting inside the open window then unchecked proxy authentication it will work
I am facing this issue once I put the dependency of GCM.
Error:(50, 0) Gradle DSL method not found: 'comiple()'
Possible causes:The project 'everybill-codebase' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
This is the build.gradle file of line no 50,
comiple 'com.google.android.gms:play-services-gcm:8.4.0'
I am using these services also from play-service
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
this is the build.gradle file in project
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha6'
classpath 'com.google.gms:google-services:2.0.0-alpha6'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
It would be great to know any solution related with this. Thanks in advance.
Eventually someone is going to close this question, but as the other guys pointed out it's just a typo, use compile() instead of comiple().
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've tried to included cards library in my project using the below code in my build.gradle file.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
dependencies {
//Core card library
compile 'com.github.gabrielemariotti.cards:cardslib-core:2.0.1'
//Optional for built-in cards
compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.0.1'
//Optional for RecyclerView
compile 'com.github.gabrielemariotti.cards:cardslib-recyclerview:2.0.1'
//Optional for staggered grid view support
compile 'com.github.gabrielemariotti.cards:cardslib-extra-staggeredgrid:2.0.1'
//Optional for drag and drop support
compile 'com.github.gabrielemariotti.cards:cardslib-extra-dragdrop:2.0.1'
//Optional for twowayview support (coming soon)
//compile 'com.github.gabrielemariotti.cards:cardslib-extra-twoway:2.0.1'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
But when compiling, android studio is throwing up errors as below.
Error:(23, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'cardslib_1' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
I'm guessing the reason to be gradle version, which is lower in libraries I'm including.
How to know the gradle version my dependencies are using and how to adjust them to my project.
When I thought to add the libraries, maven has repositories in aar file which I don't think will let you know the gradle version.
Thanks for any help in this regards.
You're adding the dependencies in the wrong place. They should be outside of the buildscript section and in the modules/applications build.gradle.
Parent build.gradle. This should be in the root directory of your project
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
Module build.gradle. This should be in the folder of the module you're trying to add the dependencies to.
apply plugin: 'com.android.application'
android {
// Android related settings go here
}
dependencies {
compile 'com.github.gabrielemariotti.cards:cardslib-core:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-recyclerview:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-extra-staggeredgrid:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-extra-dragdrop:2.0.1'
}
This assumes that the structure of your project is something like
Project
|___build.gradle
|___Module
|____build.gradle