Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NativeScript 8.5.3 Android build failing: Could not find method task() for arguments [replaceSettings, settings_9f0ihdbhsry4akdttkhpjzk68$_run_closure1@860396b] on settings 'proto' of type org.gradle.initialization.DefaultSettings. #1763

Closed
KevSeenan opened this issue Jun 1, 2023 · 6 comments

Comments

@KevSeenan
Copy link

KevSeenan commented Jun 1, 2023

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • NativeScript-Vue
  • CLI: 8.5.3
  • NativeScript: 8.5.3
  • Android Runtime: 8.5.0

Describe the bug

ns run android gets to Gradle build and fails. Below is the output form the terminal:

Gradle build...
         + applying user-defined configuration from /<path>/app/App_Resources/Android/settings.gradle

FAILURE: Build failed with an exception.

* Where:
Script '/<path>/app/App_Resources/Android/settings.gradle' line: 3

* What went wrong:
A problem occurred evaluating script.
> Could not find method task() for arguments [replaceSettings, settings_9f0ihdbhsry4akdttkhpjzk68$_run_closure1@860396b] on settings 'proto' of type org.gradle.initialization.DefaultSettings.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org/

BUILD FAILED in 510ms
Unable to apply changes on device: emulator-5554. Error is: Command ./gradlew failed with exit code 1.

Here is the settings.gradle file:

import groovy.json.JsonSlurper

task replaceSettings {
    description "Replaces configuration settings."
    def jsonSlurper = new JsonSlurper()
    def pathToSettingsJson

    if (project.hasProperty("appResourcesPath")) {
        pathToSettingsJson = "$project.appResourcesPath/Android/settings.json";
    } else {
        pathToSettingsJson = "$rootDir/../../app/App_Resources/Android/settings.json";
    }

    def settingsJsonFile = file(pathToSettingsJson);
    def settingsResolvedPath = settingsJsonFile.getAbsolutePath();

    if(settingsJsonFile.exists())
    {
        println "\t Applying settings from $settingsResolvedPath"
        String settingsGradleTemplate = """android {
            defaultConfig {
                applicationId = "__appId__"

                if (__minSdkVersion__) {
                    minSdkVersion = __minSdkVersion__
                }

                if (__targetSdkVersion__) {
                    targetSdkVersion = __targetSdkVersion__
                }
            }
        }"""

        def settingsJsonContent = settingsJsonFile.getText("UTF-8");
        def settingsMap = jsonSlurper.parseText(settingsJsonContent);

        for ( setting in settingsMap ) {
            def placeholder = "__${setting.key}__";
            def settingValue = setting.value;

            if (settingValue == null) {
                settingValue = false
            }

            settingsGradleTemplate = settingsGradleTemplate.replaceAll( placeholder, settingValue as String);
        }

        new File( "$rootDir/temp_setting.gradle" ).write( settingsGradleTemplate, 'UTF-8');
        apply from: "$rootDir/temp_setting.gradle";
    }
}

Here is the app.gradle file:

android {
  defaultConfig {
    minSdkVersion 27
    generatedDensities = []
    targetSdkVersion 33
  }
  aaptOptions {
    additionalParameters "--no-version-vectors"
  }
}

def settingsGradlePath

if(project.hasProperty("appResourcesPath")){
    settingsGradlePath = "$project.appResourcesPath/Android/settings.gradle";
} else {
    settingsGradlePath = "$rootDir/../../app/App_Resources/Android/settings.gradle";
}

def settingsGradleFile = new File(settingsGradlePath);

if(settingsGradleFile.exists())
{
    apply from: settingsGradleFile;
}

Here is my package.json -

  "dependencies": {
    "@nativescript-community/https": "4.1.0",
    "@nativescript-community/ui-material-tabs": "^7.0.37",
    "@nativescript/core": "8.5.3",
    "@nativescript/email": "^2.0.5",
    "@nativescript/firebase": "^11.1.3",
    "@nativescript/secure-storage": "^3.0.0",
    "@nstudio/nativescript-barcodescanner": "^5.0.1",
    "@nstudio/nativescript-filterable-listpicker": "^3.0.0",
    "@nstudio/root-detection": "^2.0.1",
    "@triniwiz/nativescript-socketio": "^5.0.1",
    "@triniwiz/nativescript-toasty": "^4.1.3",
    "@types/aes-js": "^3.1.1",
    "aes-js": "^3.1.2",
    "date-fns": "^2.15.0",
    "electron": "^25.0.0",
    "js-sha256": "^0.9.0",
    "nativescript-carousel": "^7.0.1",
    "nativescript-exit": "^1.0.1",
    "nativescript-fonticon": "^2.0.2",
    "nativescript-modal-datetimepicker": "^2.1.5",
    "nativescript-phone": "^3.0.2",
    "nativescript-picker": "^2.1.2",
    "nativescript-socketio": "^3.3.1",
    "nativescript-toasty": "3.0.0-alpha.2",
    "nativescript-videoplayer": "^5.0.1",
    "nativescript-vue": "^2.7.1",
    "nativescript-vue-shadow": "^0.1.0",
    "vuex": "^3.6.2"
  },
  "devDependencies": {
    "@babel/core": "^7.11.1",
    "@babel/preset-env": "^7.11.0",
    "@nativescript/android": "~8.5.0",
    "@nativescript/ios": "8.5.2",
    "@nativescript/types": "^8.0.1",
    "@nativescript/webpack": "~5.0.13",
    "@types/node": "20.2.5",
    "@typescript-eslint/eslint-plugin": "^5.51.0",
    "@typescript-eslint/parser": "^5.51.0",
    "babel-loader": "9.1.2",
    "eslint": "8.41.0",
    "eslint-config-prettier": "^8.2.0",
    "eslint-plugin-html": "7.1.0",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-vue": "9.14.1",
    "hard-source-webpack-plugin": "^0.13.1",
    "nativescript-vue-template-compiler": "^2.7.1",
    "sass": "1.62.1",
    "typescript": "^5.0.4",
    "vue": "^2.7.14",
    "vue-loader": "^17.1.2"
  }

I have tried upgrading to latest version of node (18.16.0), upgrading Android Studio (Flamingo), removing the gradle file from my home directory so it re-installs on ns run android but I'm still getting the error. Reverting to older versions of the run time / cli also doesn't help.

Any help with this would be greatly appreciated. Thanks.

@rigor789
Copy link
Member

rigor789 commented Jun 1, 2023

I believe you can just delete the settings.gradle that's an old artifact from a previous version that's no longer used in that form.

I recommend copying over the defaults from a fresh project:

@KevSeenan
Copy link
Author

KevSeenan commented Jun 1, 2023

Thanks @rigor789 for the quick reply.

I have tried what you advised and now get a different error:

Gradle build...
+ applying user-defined configuration from //app/App_Resources/Android/before-plugins.gradle
+ applying user-defined configuration from //app/App_Resources/Android/before-plugins.gradle
+ setting applicationId

Script '//node_modules/@nativescript/firebase/platforms/android/include.gradle' line: 96
A problem occurred evaluating script.
Plugin with id 'com.google.gms.google-services' not found.

Have you seen this before? Does this mean I need to change firebase plugin?

@rigor789
Copy link
Member

rigor789 commented Jun 1, 2023

I have seen that before, but I can't recall the solution (other than switching/migrating to the new firebase-core plugins). Perhaps there's a solution somewhere in the old firebase repo.

Actually, found this: EddyVerbruggen/nativescript-plugin-firebase#1882 (comment)

But note that the old firebase plugin is deprecated, so it's best to migrate to the new one instead.

@KevSeenan
Copy link
Author

Will look into the post and migrating.

Thanks again for the speedy response.

Have a good day!

@KevSeenan
Copy link
Author

Update

Migrating worked so closing the issue.

@nguyentrancong
Copy link

I followed him EddyVerbruggen/nativescript-plugin-firebase#1882 (comment)
and
It works with me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants