Search code examples
androidnativescriptaws-sdktns

Could not find method compile() for arguments ... nativescript and nativescript-aws


I am rather new to nativescript and cannot wrap my head around what I am doing wrong, I come across this error message when trying to build an app using tns run android. This is the full error message:

Could not find method compile() for arguments [com.amazonaws:aws-android-sdk-core:2.6.16] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

After spending hours researching the reason for that error, I found that most answers were recommending to change compile to implementation. this isn't something I can do as the build.gradle file is created only when running the command tns run android.

I am running nativescript 8.0.4

My version of tns-android in my package.json is 6.5.3 and nativescript-aws-sdk is 0.0.4, the of version tns-anandroid seems to be using gradle pluggin version 5.4.1, as per the gradle-wrapper.properties inside the tns-android's node_modules folder. see bellow:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

When running the tns run android two folders are created inside the platforms folder as expected

platforms
|__android
|__tempPlugin
   |__nativescript_aws_sdk

The version is fine in platforms/android with the following gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

I The error originates from platforms/tempPlugin/nativescript_aws_sdk/build.gradle upon checking the gradle-wrapper.properties the version shows gradle pluggin version 5.4.1:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip

I am aware that compile has been removed from gradle from v7.

Things I've tried this far:

  • changed versions of nativescript
  • change versions of tns-android
  • remove tns-android and replace with @nativescript/android

What is the walk around this problem?


Solution

  • The nativescript-aws-sdk plugin(https://github.com/triniwiz/nativescript-aws-sdk) uses old deprecated compile gradle keyword in its include.gradle (as of now https://github.com/triniwiz/nativescript-aws-sdk/commit/9901b611ebd620c166bfabebb9f136e8fa07597d)

    In node_modules/nativescript-aws-sdk/platforms/android/include.gradle replace:

    dependencies {
        compile 'com.amazonaws:aws-android-sdk-core:2.6.16'
        compile 'com.amazonaws:aws-android-sdk-s3:2.6.16'
        compile 'com.amazonaws:aws-android-sdk-cognito:2.6.16'
    }
    

    with

    dependencies {
        implementation 'com.amazonaws:aws-android-sdk-core:2.6.16'
        implementation 'com.amazonaws:aws-android-sdk-s3:2.6.16'
        implementation 'com.amazonaws:aws-android-sdk-cognito:2.6.16'
    }