Android studio build script error,unsupported gradle DSL method found : android()! - android-studio

I upgraded the Android Studio to AS 0.6 then imported the project developed in AS 0.3
I am getting errors like:
Build script error,unsupported Gradle DSL method found : android()'!,
Possible causes could be:
- you are using Gradle version where the method is absent
("open_gradle_settings">Fix Gradle settings</a>)
- you didn't apply Gradle plugin which provides the method
(Apply Gradle plugin)
or there is a mistake in a build script (Goto source)
I changed my dependencies path in build.gradle to:
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 14
}
What might the problem?
Is there any guide which tells how to upgrade the project?

Actually it stated in the error message. So just add
apply plugin: 'com.android.application'
between dependencies section and android section

Think of “Gradle DSL method” as a Java method. So in Gradle, methods can be distinguished by either {} or “.”. So
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
is the same as
dependencies.compile fileTree(dir: 'libs', include: ['*.jar'])
where both “dependencies” and “compile” are methods.
So you are including a method somewhere in your build.gradle file that is not supported by your program. For example, make your dependencies this:
dependencies {
nothing 'this.does.nothing.build:gradle:0.7.+'
}
Which is the same as writing:
dependencies.nothing 'this.does.nothing.build:gradle:0.7.+'
And you will see an error saying “unsupported Gradle DSL method found: ‘nothing()’!”
Obviously "nothing" is not a real method. I just made it up.
So one of your "android" methods is wrong.

Related

Android Studio 3.0.1 (Windows 10 64-bit) stuck at "Executing tasks: [:app:assembleDebug]" when building project

The process gets stuck if I am trying to run the app (even when I start from a fresh new project) both on an emulator (Android 5.0 or 6.0) or on my phone (Android 7.1). Following some results I found online, I tried to run gradle offline but it did not work. I did also try the solutions suggested on this link, with no success. On Ubuntu, this seems to be caused because of a library issue concerning 32-bit software running from a 64-bit system, which can be solved installing the appropriate library, but I could not find any guidance when running Android Studio on Windows.
The build.gradle file (Module: app) says:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.denny.zuzuplayer"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
The build.gradle (Project) says:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// 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
}
Thanks!
I noticed that Android Studio has a tab called Gradle Console, which lists every gradle process that is currently running, in detail. That is how I got the message that the "aapt" instance was not fine the old rascal, due probably to the antivirus software. This is what the console told me:
> Exception in thread "queued-resource-processor_16"
> java.lang.RuntimeException: Timed out while waiting for slave aapt
> process, make sure the aapt execute at
> C:\Users\Denny\AppData\Local\Android\Sdk\build-tools\26.0.2\aapt2.exe
> can run successfully (some anti-virus may block it) or try setting
> environment variable SLAVE_AAPT_TIMEOUT to a value bigger than 5
> seconds
I have no idea how to "set environment variable SLAVE_AAPT_TIMEOUT to a value bigger than 5 seconds". I Googled the issue for a few minutes when I wondered, why not try the other possible solution first?
I added the SDK folder to my antivirus exceptions (aapt is an instance of SDK, for that matter), and voilà, the project is finally building. Hurray!
I just got this error and was able to resolve it by ensuring that the two Glide libraries I'm using refer to the same version.
This caused the error:
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
And this fixed it:
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
I was able to determine that the error was related to the Glide libraries, at least my configuration of them in the module's build.gradle file, by using Denny's suggestion to examine the Gradle tasks. Opening the Gradle Tool Window shows a list of tasks. The Event Log indicated that the error was related to the "assembleDebug" task. So, I double-clicked on that task in the Gradle Tool Window to execute it, and some useful information appeared in a tab on the Run console.

Gradle dependency for MPAndroidChart not working in Android Studio

Trying to install MPAndroidChart, I tried to follow the instructions in the Readme for adding the library as a gradle dependency.
EDIT:
I didn't edit the top-level build.grade file, only the build.gradle file in my app directory. The latter looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.gmail.konstantin.schubert.workload"
minSdkVersion 16
targetSdkVersion 23
versionCode 7
versionName "1.1.5"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.guava:guava:17.0'
compile 'joda-time:joda-time:2.8.2'
compile 'com.android.support:design:23.0.0'
compile 'com.github.PhilJay:MPAndroidChart:v2.2.3'
}
As you can see, I have added the maven repository and the compile instruction in the dependencies.
However, Android Studio gives me an error:
Error:(32, 13) Failed to resolve: com.github.PhilJay:MPAndroidChart:v2.2.3
EDIT: Here are the instructions as given by JitPack: https://jitpack.io/
I believe I followed them to the letter.
What am I doing wrong? What am I forgetting?
EDIT: The question is really following the wrong lead. Looking at my gradle log, I discovered the following error:
* What went wrong:
A problem occurred configuring project ':app'.
Could not resolve all dependencies for configuration ':app:_debugCompile'.
Could not resolve com.github.PhilJay:MPAndroidChart:v2.2.3.
Required by:
workload:app:unspecified
Could not GET 'https://jitpack.io/com/github/PhilJay/MPAndroidChart/v2.2.3/MPAndroidChart-v2.2.3.pom'.
> peer not authenticated
This is a much better lead to follow and can easily be googled.
please edit your top level gradle file like this:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
other thing.. take a look at gradle console in the bottom right of android studio, and show me the log.
It is a problem with java/gradle on linux not recognizing the ssl certificate. The easiest solution is to use java 8, see https://www.jitpack.io/docs/FAQ/.
I am on Debian 8.5 Jessie and using openjdk 8 (instead of the stock 7 version) from jessie/backports solved the issue (building gnucash-android) on my system.

Adding dependency to Google Play Services inside Android library

I am developing an Android library that depends on Google Play Services.
The instructions provided by Google on how to setup Google Play Services only specify the steps to follow when adding it to an application project and not a library.
I tried following the same steps for my library and ended up with the following build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
classpath 'com.google.gms:google-services:2.0.0-alpha3'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-annotations:+'
provided 'com.google.android.gms:play-services-auth:8.4.0'
}
apply plugin: 'com.google.gms.google-services'
The problem with this is that when building the project, I get the following exception:
* What went wrong:
Execution failed for task ':processDebugGoogleServices'.
> File google-services.json is missing from module root folder. The Google Services Plugin cannot function without it.
I understand this because, as stated in the Google Play Services documentation (https://developers.google.com/android/guides/setup) , it depends on a json file for configuration. However, since I am building this as a library, I wanted the google-services.json file to be added in the project that will use my library instead of putting it in the library itself.
So how can I do this? How can I compile my library that depends on classes defined in Google Play Services but not really configure Google Play Services inside the library and let it be done by the application that consumes my library?
Thank you!
It was simpler than I thought.
All I had to do was remove the lines classpath 'com.google.gms:google-services:2.0.0-alpha3' and apply plugin: 'com.google.gms.google-services' from the library's build.gradle file and then add them only to the gradle file in my application project that depends on this custom library.
You can generate and add the google-services.json using instruction on this page
It has a step by step set of instructions for generation of the file.

Cannot Resolve R after Update Android Studio to v13

I've got problem when executing gradle after my android studio updated to version 1.3
So this is the error message
Error:Execution failed for task ':app:processDebugResources'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Otniel\AppData\Local\Android\sdk\build-tools\22.0.1\aapt.exe'' finished with non-zero exit value 1
I don't know what was happened, but this is my approach to fix my error (which is not produce any working solution)
change my build tools from project structure settings :
compile sdk version : API 22: Android 5.1
build tools version 22.0.1
(sync gradle and error still the same with the above message)
Then I continue the first setting (point 1) and add this 2nd setting
2. change gradle 1.2.3 to classpath 'com.android.tools.build:gradle:1.3.0'
(1.2.3 produce the same error as the message above)
(with 1.3.0 still produce the same error)
try to revert back the build tools to v 21 and android lolipop v 5
with combination of gradle : com.android.tools.build:gradle:1.3.0, and com.android.tools.build:gradle:1.2.3
When I revert to 1.1.3 or 1.0.0 (for the gradle plugin) I still got the same error.
When I change the gradle to 1.1.3, the console returns a message to use the gradle plugin version that match with build tools sdk (v 24)
But every combination that I use is still return an error message (still the same, like the message above)
Also I've tried to delete impl and .idea folder, and reimport the project, still have the same error.
And my android studio cannot resolve R symbol as the effect.
So what should I do to fix this?
[EDITED]
This is my gradle code :
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.vanwellis.vinnomobile"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:support-v4:21'
compile 'com.daimajia.easing:library:1.0.0#aar'
compile 'com.daimajia.swipelayout:library:1.2.0#aar'
compile 'commons-io:commons-io:2.4'
compile 'com.daimajia.androidanimations:library:1.1.2#aar'
compile 'com.nineoldandroids:library:2.4.0'
compile 'jp.wasabeef:recyclerview-animators:1.0.3#aar'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.google.code.gson:gson:2.3.1'
}
I got these 2 errors, after seeing it carefully :
D:\Projects\Android\MyProj\app\build\intermediates\res\merged\debug\drawable-hdpi-v4\ic_launcher.png: error: Duplicate file.
D:\Projects\Android\MyProj\app\build\intermediates\res\merged\debug\drawable-hdpi\ic_launcher.png: Original is here. The version qualifier may be implied.
Maybe my additional information are usefull
After updating Android Studio recently, I also had this problem. What worked for me was to expand res, then go through every child folder in res and expand them (you can close them right after.)
Close all classes you have open and in the system bar select Build > Make Project.

How to create a project in Android Studio without the support library?

I'm sorry if this is a stupid question but I'm new to Android development and for my first app, I don't have any plans to support devices running API 17 and lower so I wish to not use the support library. However, when I create a new project in Android Studio (even with no activity) I can still see
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
in my Gradle file.
How can I create a project without the support library? Thanks.
You can remove the support library , removing the dependency from your build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//compile 'com.android.support:appcompat-v7:21.0.3'
}
To set minSdk=17 you can use:
android {
defaultConfig {
minSdkVersion 17
targetSdkVersion 22
}
}

Resources