简体   繁体   中英

Android Studio Gradle Build : Import Eclipse Library Project : Issue

I have a Project in Android Studio and I have added library project in it as per below mentioned link.

How do I add a library project to Android Studio?

but I am facing this issue :

Gradle 'MyApplication2' project refresh failed: No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argument types: (org.gradle.api.internal.file.collections.DefaultConfigurableFileTree) values: [directory 'libs'] Possible solutions: module(java.lang.Object)

Can anyone please help/explain me Gradle build process.

application build.gradle :

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        classpath 'com.android.tools.build:gradle:0.8.+'
        compile project(":satellite-menu")
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

library build.gradle:

apply plugin: 'com.android.library'

dependencies {
    compile 'com.android.support:support-v4:21.0.3'
}

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
}

application settings.gradle

include ':app', ':satellite-menu'
project(':satellite-menu').projectDir = new File('libs/satellite-menu')

You've put your dependencies statements in the wrong dependencies block in the wrong build file. Dependencies in the buildscript block are for telling the build system where to find build system plugins, such as the Android Gradle plugin. For your module dependnecies, put them in the top-level dependencies block in the module's build file.

After it's done the top-level build file should look like this:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.8.+'
    }
}
...

and the module's should look like this:

apply plugin: 'com.android.library'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(":satellite-menu")
    compile 'com.android.support:support-v4:21.0.3'
}

android {
...

As for what the meaning is of the actual error message you're getting, it's a little difficult to understand, but essentially the compile directive isn't valid in the dependencies block under buildscript -- the build system doesn't understand it.

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