I am new to Android App Development. When I tried to create a new project,Android Project...the following message popped up..
Error:Execution failed for task \':app:
I have the same problem, in build.gradle (Module:app) add the following line of code inside dependencies:
dependencies
{
...
compile 'com.android.support:support-annotations:27.1.1'
}
It worked for me perfectly
Add this line under the dependencies in your gradle file
compile 'com.android.support:support-annotations:27.1.1'
If you using Android Studio 3.1.+ or above
just put this in your gradle depedencies:
implementation 'com.android.support:support-annotations:27.1.1'
Overall like this:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:support-annotations:27.1.1'
}
A better solution is explained in the official explanation. I left the answer I have given before under the horizontal line.
According to the solution there:
Use an external tag and write down the following code below in the top-level build.gradle file. You're going to change the version to a variable rather than a static version number.
ext {
compileSdkVersion = 26
supportLibVersion = "27.1.1"
}
Change the static version numbers in your app-level build.gradle file, the one has (Module: app)
near.
android {
compileSdkVersion rootProject.ext.compileSdkVersion // It was 26 for example
// the below lines will stay
}
// here there are some other stuff maybe
dependencies {
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
// the below lines will stay
}
Sync your project and you'll get no errors.
You don't need to add anything to Gradle scripts. Install the necessary SDKs and the problem will be solved.
In your case, install the libraries below from Preferences > Android SDK or Tools > Android > SDK Manager
Based on your screenshot i found two working solutions:
First solution: add to dependencies of your gradle module this line
compile 'com.android.support:support-annotations:27.1.1'
and sync your project
Note: if you are using Android studio 3+ change compile
to implementation
Second solution: Configure project-wide properties found in the documentation https://developer.android.com/studio/build/gradle-tips.html#configure-project-wide-properties
in project gradle add this line:
// This block encapsulates custom properties and makes them available to all
// modules in the project.
ext {
// The following are only a few examples of the types of properties you can define.
compileSdkVersion = 26
// You can also use this to specify versions for dependencies. Having consistent
// versions between modules can avoid behavior conflicts.
supportLibVersion = "27.1.1"
}
Then to access this section change compileSdkVersion
line to be
compileSdkVersion rootProject.ext.compileSdkVersion
and at dependencies
section change the imported library to be like this:
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
and sync your project
Note: if you are using Android studio 3+ change compile
to implementation
For the difference between compile
and implementation
look at this
What's the difference between implementation and compile in gradle
Adding this to build.gradle (Module app) worked for me:
compile 'com.android.support:support-annotations:27.1.1'