gradle dsl method not found 'compile()' Error:(10,0) - android

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).

Related

Trying to add module to project. Gradle DSL method not found: 'versionName()'

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.

Cannot add Google Play Location Service as dependency to my Android Project

I tried to add the Google location Service to my Android Project by referencing the official link.
As the tutorial said I added the following line to the dependencies section in the Project Gradle file.
implementation "com.google.android.gms:play-services-location:11.8.0"
But when i resynced the project i got the following error
Error:(19, 0) Could not find method implementation() for arguments [com.google.android.gms:play-services-location:11.8.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Open File
I am using Android Studio 3.0.1 and Gradle Version 4.1.
How to overcome this error?
please try this
Add in Build.gradel at app lavel
dependencies {
Implementation 'com.google.android.gms:play-services:9.6.0'
}
apply plugin: 'com.google.gms.google-services
// 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'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they
belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I think you have forgot to add maven repository in your app gradle file. Try by doing these steps. Open the build.gradle file for your application. Make sure that the repositories section includes a maven section with the "https://maven.google.com" endpoint. For example: allprojects {repositories {jcenter()maven {url "https://maven.google.com"}}}
Avoid using + in your dependencies as it android studio will try to update dependencies every 24 hours. Also replace compile by implementation for low APK size.
Edit 1:
As you told maven repository did not worked.
Check your project settings by going to Android Studio.
Click on file
click on project structure
There will option of Project in sidebar. Tap on it.
Check for the gradle and andrpid plugin version.
Put these values
Gradle Version - 4.1
Android plugin version - 3.0.1
Android Plugin Repository - jcenter,google()
Default Library Repository - jcenter, 'https://maven.google.com'
Reply me if it works

Android Studio Gradle Project Sync Failed - I want to build a streaming app

So I'm new to App Development, and I'm struggling with the Gradle Sync:
Blockquote Error:(10, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'MyApplication' 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 'MyApplication' 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
That is the error message I get.
This is the code I am using
// 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:2.3.3'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
apply plugin: 'project-report'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Please help with a way to fix this,
thanks in advance
Regards
There are two build.gradle files in your Android Studio project. The one that you edited is in the project's root directory. That's not the file you should have put those lines in. The other build.gradle is in your module's directory (e.g., app/). Those four compile lines go in a dependencies closure in that build.gradle file.
This is even mentioned in the comment in the file:
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
This sample project (from this book) uses some of those same dependencies. My top-level build.gradle file does not have the compile statements:
// 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:2.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Instead, they are in the app/build.gradle file:
apply plugin: 'com.android.application'
dependencies {
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
}
}

android Error:(44, 13) Failed to resolve com.esri.arcgis.android:arcgis-android:10.2.7

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'

gradle DSL method not found: 'compile()' persisting error

This is what my gradle file looks like http://codeshare.io/RWMpl , its throwing a small error saying:
gradle DSL method not found: 'compile()' .
My gradle file :
// 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:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'org.ektorp:org.ektorp:1.4.2'
}
allprojects {
repositories {
jcenter()
}
}
I followed the advice on THIS thread(see the accepted answer) , but i still get the following error:
gradle DSL method not found: 'compile()'.
Why ?
Usually, there is a Project build.gradle and a Module build.gradle.
The screenshot that you shared was of your Module build.gradle.
This error seems to me as, you have an android block in your Project build.gradle file.
Remove android block from Project build.gradle and the app will compile fine..
You using a wrong gradle file. Check for build.gradle(Module:yourmodulename), this is where you have to update.

Categories

Resources