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
Related
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 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'
}
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
My objective is to compile a library that depends on other libraries (from HoloEverywhere), which are present in a remote maven repository, using Gradle and Android Studio (0.4.4).
If I set apply plugin: to android in the library's build.gradle, the remote maven dependencies are found, otherwise they are not (apply plugin: 'android-library').
Here is my build.gradle with the android object omitted to save in space:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
maven {url 'http://192.241.191.41/repo'}
}
android {...}
dependencies {
compile 'org.holoeverywhere:library:2.1.0#aar'
compile 'org.holoeverywhere:addon-preferences:2.1.0#aar'
compile fileTree(dir: 'libs', include: '*.jar')
}
The error I get when I press "Sync Project with Gradle Files" in Android Studio is:
7:30:48 PM Failed to refresh Gradle project 'MyTopProject'
Could not find org.holoeverywhere:library:2.1.0.
Required by:
MyTopProject:MyActualApp:unspecified > MyTopProject:MyMessedUpLib:unspecified
Search in build.gradle files
What am I doing wrong? Is this behaviour expected? Should I do it in another way?
Thank you very much.
I have a build.gradle file in my library project, the content of it looks like below:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
.......
when I do gradle build, it gives error:
Could not find com.actionbarsherlock:actionbarsherlock:4.4.0.
If I change the line "apply plugin" from 'android-library' to 'android', it can compile fine.
So is it a bug with the gradle android plugin? that it cannot find actionbarsherlock correctly in maven repository if it's from a library project?
Make sure you select from Project Settings -> Gradle, "Use local gradle distribution" pointing to you local Gradle copy. Mine is 1.9 and I managed to make it work.