简体   繁体   中英

Add AppCompat dependency to Gradle in Android Studio

Verdant newbie here. I'm making a fairly simple project that needs to be compatible with Android versions older than Lollipop, but still want to have the app look nicer by using AppCompat .

Unfortunately, I do not know how to work (or even find) the gradle - I tried to run a gradle task: compile "com.android.support:appcompat-v7:21.0.+"

But it returned an error saying that " Task 'compile' is ambiguous.... " in my project.

Could anyone tell me how to add this? I've searched all over Google, but everything goes way over my head.

Thanks!

Have you been able to locate Gradle file?

Edit your gradle like this :

  apply plugin: 'com.android.application'


android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "com.xyz.xyz"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.00.00"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

  dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:support-v4:23.3.0'
}

Update your question and post full Gradle code.

你可以在这里找到Gradle文件

Add the appcomapt library(com.android.support:appcompat-v7:21.0.+") in dependancy section of the build.gradle file

在此输入图像描述

Or second way to add library is by searching on maven repo.this can be done by traversing file->project structure->app>dependancy->click (+) ->add Library dependancy

Task 'compile' is ambiguous.

This issue is not the Compile Issue. but this was an issue on the task itself.

if you are not using a command like "gradle compileDebug" then one of the android configurations are executing the task and it is not working well with your build.gradle.

Here is a link that seems to relate specifically to your issue. Click Here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM