如何解决此Implementation()错误?

时间:2018-01-18 19:53:00

标签: android android-studio gradle android-gradle build.gradle

每当我运行implementation()方法时,我都会收到错误。

我尝试导入此Insiteo' .aar'文件并设置它的依赖关系,但调用' implementation()'是一个问题。方法。帮助

Insiteo模块build.gradle:

configurations.maybeCreate("default")
artifacts.add("default", file('Insiteo-SDK-3.6.3g.aar'))


dependencies {
    implementation 'com.squareup.retrofit:retrofit:2.0.0-beta2'
    implementation 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2'
    implementation 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
}

这是错误

Error:(6, 0) Could not find method implementation() for arguments ['com.squareup.retrofit:retrofit:2.0.0-beta2']

App module build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    apply plugin: 'com.android.library'

    defaultConfig {
        applicationId "com.example.joey.projectgenesis"
        minSdkVersion 26
        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(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.google.android.gms:play-services-ads:11.8.0'
    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'
    implementation 'com.android.support:gridlayout-v7:26.1.0'
    implementation 'com.squareup.retrofit:retrofit:2.0.0-beta2'
    implementation 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2'
    implementation 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
    implementation project(':Insiteo')
}

Project build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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
}

我的Android插件版本是3.0.1,我的Gradle版本是4.4.1

我也尝试了compile()同样的错误。

其他build.gradle脚本没有任何问题,只有Insiteo模块脚本,而且只有implementation()方法。

3 个答案:

答案 0 :(得分:0)

AFAIK,您无法将相关性添加到aar模块中。您很可能需要应用应用程序或库插件才能执行此操作。

但是,将依赖项直接添加到项目中通常会更容易;没有进入库模块。例如:

Root /
    app/
    myAarLibrary/

不要在myAarLibrary中定义依赖关系,在app

中定义它们

答案 1 :(得分:0)

你的傻瓜有问题。您可以在gradle依赖项中使用compile代替implelentaion。默认情况下,所有gradle都支持此功能。

答案 2 :(得分:0)

  1. 确保您使用的是Android Studio 3.0或更高版本。
  2. 您的app级别build.gradle应如下所示:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    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
    }
    
  3. 确保您的gradle-wrapper.properties看起来像这样:

    #DATE
    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
    
  4. 使用

    implementation 'com.squareup.retrofit:retrofit:2.3.0'
    implementation 'com.squareup.retrofit:adapter-rxjava:2.3.0'
    implementation 'com.squareup.retrofit:converter-gson:2.3.0'
    

    而不是

    implementation 'com.squareup.retrofit:retrofit:2.0.0-beta2'
    implementation 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2'
    implementation 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
    
相关问题