mikewax
mikewax

Reputation: 25

Could not find method implementation() for arguments [...] on object...DefaultDependencyHandler

i see this is a common error: "Could not find method implementation() for arguments [com.github.mik3y:usb-serial-for-android:3.3.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler"

but none of the normal solutions have worked for me.

build.gradle:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.2'
        implementation 'com.github.mik3y:usb-serial-for-android:3.3.0'
    }
}

allprojects {
    repositories {
        jcenter()
        google()
        maven { url 'https://jitpack.io' }
    }
}

app.gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 29
    buildToolsVersion '29.0.3'

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 29
        consumerProguardFiles 'proguard-rules.pro'
        
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        testInstrumentationRunnerArguments = [                    // Raspi   Windows   LinuxVM   ...
                'rfc2217_server_host': '192.168.0.100',
                'rfc2217_server_nonstandard_baudrates': 'true',   // true    false     false
        ]
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation "androidx.annotation:annotation:1.1.0"
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'commons-net:commons-net:3.6'
    androidTestImplementation 'org.apache.commons:commons-lang3:3.11'
//    implementation 'com.github.mik3y:usb-serial-for-android:3.3.0'
}

gradle-wraper.properties:

#Tue Oct 13 21:20:09 CEST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip

the usual solution is to get newer gradle and newer gradle plugin. But i have the latest version. so is there a new solution to this problem that i don't know about?

thanx, mike

Upvotes: 1

Views: 1775

Answers (1)

Thomas K.
Thomas K.

Reputation: 6770

Dependencies defined in a buildscript block support the classpath configuration only, hence implementation is rejected with the error message you provided. Classpath dependencies are available only to the build script itself. Usually, they provide additional functionality, for example by adding additional plugins. Read more about it here: External dependencies for the build script.

That being said, usb-serial-for-android needs to be defined outside of the buildscript block to work.

dependencies {
    implementation 'com.github.mik3y:usb-serial-for-android:3.3.0'
}

This is what you commented out in app.gradle.

Upvotes: 1

Related Questions