I'm trying to add an external library. I've created in a/libs folder under project folder and have the following code in my gradle.build file. But it doesn't sync at all.
// 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()
flatDir {
dirs 'libs'
}
}
}
dependencies {
compile 'com.radiusnetworks:AndroidIBeaconLibrary:0.7.1#aar'
}
The error I'm getting is:
Gradle 'BLE_Client' project refresh failed:
Build script error, unsupported Gradle DSL method found: 'compile()'!
Possible causes could be:
- you are using Gradle version where the method is absent
- you didn't apply Gradle plugin which provides the method
- or there is a mistake in a build script
You shouldn't add this dependency to the root-level build.gradle file. Add it to your module's build.gradle file instead. The top-level build file is for things that are common to all modules in your project, but it's highly unlikely that you'd want all modules to have the same dependencies, or even to share this one.
Related
I am trying to add a epub reader library to a project I have already created. The library I am trying to add to my project as a moduel is the Folio Reader Library (https://github.com/FolioReader/FolioReader-Android). I have downloaded this library on my computer and have tried adding it through File -> New -> Import Module. However, during the process I received countless errors. My current one is this:
Gradle DSL method not found: 'versionName()'
Possible causes:
The project 'FolioReader-Android-master' may be using a version of the
Android Gradle plug-in that does not contain the method (e.g.
'testCompile' was added in 1.1.0).
Upgrade plugin to version 3.4.1 and sync project
The project 'FolioReader-Android-master' may be using a version of Gradle
that does not contain the method.
Open Gradle wrapper file
The build file may be missing a Gradle plugin.
Apply Gradle plugin
This file is the file where the dependencies are declared for the Library.
FolioReader-Android-master:
build.gradle file:
// Top-level build file where you can add configuration options common to
all sub-projects/modules.
buildscript {
apply from: 'versions.gradle'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
//moj
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.11"
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
}
allprojects {
configurations.all {
resolutionStrategy {
cacheChangingModulesFor 0, 'seconds'
}
}
repositories {
mavenLocal()
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The error itself states that the problem arises because the project is using a version of the Gradle plug-in may not contain the method. I have updated the version to the newest one, however I still receive this error. Any suggestions on how I can solve this problem?
Problem solved by replacing
versionName 1
with
versionName "1.1"
in the Module level build.gradle file.
Here's build.gradle:
C:\Users\billb\StudioProjects\ShoppingList03>type build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath "/com.android.tools.build.gradle:3.3/"
compile "com.android.support:support-core-utils:26.1.0"
}
}
allprojects {
repositories {
jcenter()
}
}
Error is on the compile: cannot find DefaultDependencyHandler.
I've reloaded Android SDK Platform-Tools and SDK Tools, both 26.0.1
Where is this DefaultDependencyHandler? Why is it required?
There's something in my android java code that requires this, evidently.
Any ideas out there? I've spent way too much time trying to track this down.
Add compile "com.android.support:support-core-utils:26.1.0" line in your app level build.gradle file instead of project level build.gradle file.
I want to use Gson and Retrofit to interact with an API. According to the documentations, I add theses lines into the build.gradle of my project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral() //this line
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
compile 'com.google.code.gson:gson:2.7' //this line
compile 'com.squareup.retrofit:retrofit:1.9.0' //this line
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral() //and this line
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
but I have these errors :
Error:(10, 0) Gradle DSL method not found: 'compile()' Possible
causes:The project 'TempoEDF' may be using a version of the
Android Gradle plug-in that does not contain the method (e.g.
'testCompile' was added in 1.1.0). Upgrade
plugin to version 2.3.3 and sync projectThe project
'TempoEDF' 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
So I used the Gradle plugin like my IDE wants to:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
apply plugin: 'gradle'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.retrofit:retrofit:1.9.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
but I have this error :
Error:(10, 0) Plugin with id 'gradle' not found. Open
File
What did I do wrong?
so according to the documentations i add theses lines into the build.gradle of my project
Please note the comments in that file:
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
I do not know what "documentations" that you read that told you to put these things in the project-level build.gradle file. Please consider providing links, so that we can get that material fixed.
To get past this problem, remove the changes that you made to this file. Then, add those dependencies to the module's build.gradle file (e.g., app/build.gradle in a typical Android Studio project).
I'm following the instructions for integrating Flurry Analytics using the official tutorial
I run into the problem that has been widely reported:
Error:(4, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'My_Project' 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
Here's the gradle file for the FlurryAnalytics-5.5.0 module autogenerated by Studio:
configurations.create("default")
artifacts.add("default", file('FlurryAnalytics-5.5.0.jar'))
dependencies {
compile files('FlurryAnalytics-5.5.0.jar')
}
I'm aware that a common solution prescribed in such questions as this one is to avoid putting the 'dependencies' closure in the top level build file. However, I don't have any non-gradle dependencies in that file, as is shown below.
build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
The compile option is a part of the Android Gradle Plugin.
You need to apply that plugin to your module's build.gradle file if the module is an Android module.
apply plugin: 'com.android.application' // Android Gradle Pllugin
android {
// Your Android configuration
}
With Jar:
dependencies {
compile files('FlurryAnalytics-5.5.0.jar') // Your Jar
}
or Maven Dependency:
dependencies {
compile 'com.flurry.android:analytics:6.2.0' // Latest Jcenter release
}
Recently I have migrated my android project from Eclipse to Android Studio.
Currently my project has the following Gradle script structure:
Top-level gradle build file
Main module (my app) gradle build file
module A (my app) gradle build file
module B (my app) gradle build file
module C (my app) gradle build file
The Content of my main gradle build file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.1'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
}
}
I would like to make sure crashlytics would be present for the whole project.
I initially tried to add
apply plugin: 'crashlytics'
to the main project gradle file, but I encountered the following error:
Error:(2, 0) Crashlytics was applied to a project without an Android plugin. Please make sure the Crashlytics plugin is applied after the appropriate Android plugin for your project.
I then moved the apply plugin: 'crashlytics' to the main module (my app) gradle build file and the build was successful.
Since I am new to Gradle & Android Studio, I was not sure if I need to it also to the submodules A, B, C to allow crashlytics to capture exceptions generating from those modules. Also I wonder why can't I (or how can I) add the " apply plugin: 'crashlytics' " to the main project gradle file.
Could anyone clarify it for me?