NativeScript / nativescript-cli

Command-line interface for building NativeScript apps
https://www.npmjs.com/package/nativescript
Apache License 2.0
1.04k stars 196 forks source link

Wrong gradle version used for building plugins for android with NS7. #5650

Closed NCenerar closed 2 years ago

NCenerar commented 2 years ago

Issue Description

When running tns build android, I get an error:

A problem occurred evaluating root project 'gesturehandler'.
> Could not find method compile() for arguments [{name=widgets-release, ext=aar}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Reproduction

Create a project with dependency on "@nativescript/android": "7.0.1" and "@nativescript-community/gesturehandler": "0.1.41". Build the project.

Relevant log output (if applicable)

Got gradle versions null from runtime v7.0.1
Exec npm view @nativescript/android  dist-tags --json 
 stdout: {
  "rc": "8.2.0-rc.0",
  "latest": "8.2.2",
  "alpha": "8.2.0-alpha.11"
}

 stderr: 
Exec npm view @nativescript/android@8.2.2  gradle --json 
 stdout: {
  "version": "7.4",
  "android": "7.1.2"
}

 stderr: 
Got gradle versions {"gradleVersion":"7.4","gradleAndroidPluginVersion":"7.1.2"} from the latest runtime v8.2.2

Environment

OS: macOS 12.2.1
CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
Shell: /bin/zsh
node: 17.5.0
npm: 8.4.1
nativescript: 8.1.5

# android
java: 11.0.11
ndk: 22.1.7171670
apis: Not Found
build_tools: Not Found
system_images: Not Found

# ios
xcode: 13.2.1/13C100
cocoapods: 1.11.2
python: 2.7.18
python3: 3.9.10
ruby: 2.7.5
platforms: 
  - DriverKit 21.2
  - iOS 15.2
  - macOS 12.1
  - tvOS 15.2
  - watchOS 8.3

Dependencies

"dependencies": {
  "@akylas/nativescript": "7.3.1",
  "@akylas/nativescript-sqlite": "3.3.11",
  "@mdi/font": "4.9.95",
  "@nativescript-community/appurl": "1.4.2",
  "@nativescript-community/ble": "3.0.16",
  "@nativescript-community/extendedinfo": "1.2.0",
  "@nativescript-community/gesturehandler": "0.1.41",
  "@nativescript-community/gps": "2.1.7",
  "@nativescript-community/l": "4.2.19",
  "@nativescript-community/perms": "2.1.6",
  "@nativescript-community/sensors": "1.2.1",
  "@nativescript-community/sentry": "2.1.0",
  "@nativescript-community/systemui": "1.1.7",
  "@nativescript-community/text": "1.4.9",
  "@nativescript-community/tween": "0.0.14",
  "@nativescript-community/typeorm": "0.2.2-5.1",
  "@nativescript-community/ui-blurview": "1.2.2",
  "@nativescript-community/ui-canvas": "4.0.49",
  "@nativescript-community/ui-canvaslabel": "1.0.56",
  "@nativescript-community/ui-carto": "1.4.11",
  "@nativescript-community/ui-chart": "1.1.30",
  "@nativescript-community/ui-collectionview": "4.0.29",
  "@nativescript-community/ui-document-picker": "1.1.3",
  "@nativescript-community/ui-label": "1.1.10",
  "@nativescript-community/ui-material-activityindicator": "5.2.11",
  "@nativescript-community/ui-material-bottom-navigation": "5.2.11",
  "@nativescript-community/ui-material-bottomsheet": "5.2.11",
  "@nativescript-community/ui-material-button": "5.2.11",
  "@nativescript-community/ui-material-cardview": "5.2.11",
  "@nativescript-community/ui-material-dialogs": "5.2.11",
  "@nativescript-community/ui-material-progress": "5.2.11",
  "@nativescript-community/ui-material-slider": "5.2.11",
  "@nativescript-community/ui-material-snackbar": "5.2.11",
  "@nativescript-community/ui-material-textfield": "5.2.11",
  "@nativescript-community/ui-pager": "13.0.17",
  "@nativescript-community/ui-share-file": "1.2.2",
  "@nativescript-community/ui-svg": "^0.0.8",
  "@nativescript/email": "2.0.4",
  "dayjs": "1.10.4",
  "downsample": "^1.4.0",
  "duration": "0.2.2",
  "filesize": "6.1.0",
  "geomagnetism": "0.1.1",
  "google-palette": "^1.1.0",
  "gpx-parser-builder": "^1.0.2",
  "helpful-decorators": "2.1.0",
  "kalmanjs": "^1.1.0",
  "make-error": "1.3.6",
  "nativescript-inappbrowser": "^3.1.2",
  "nativescript-vibrate": "^4.0.1",
  "nativescript-vue": "2.8.4",
  "p-queue": "6.6.2",
  "timers": "0.1.1",
  "vue-string-filter": "2.1.0",
  "xml2js": "0.4.23"
},
"devDependencies": {
  "@babel/core": "7.13.8",
  "@commitlint/cli": "^12.0.1",
  "@commitlint/config-conventional": "^12.0.1",
  "@nativescript/android": "7.0.1",
  "@nativescript/core": "~7.3.0",
  "@nativescript/types-android": "7.3.0",
  "@nativescript/types-ios": "7.3.0",
  "@nativescript/webpack": "~4.1.0",
  "@sentry/webpack-plugin": "^1.14.2",
  "@types/chai": "4.2.15",
  "@types/mocha": "8.2.1",
  "@typescript-eslint/eslint-plugin": "4.17.0",
  "@typescript-eslint/parser": "4.17.0",
  "@vue/eslint-config-typescript": "^7.0.0",
  "babel-loader": "^8.2.2",
  "chai": "4.3.4",
  "copy-webpack-plugin": "~4.6.0",
  "cross-var": "1.1.0",
  "eslint": "7.21.0",
  "eslint-config-prettier": "^8.1.0",
  "eslint-plugin-prettier": "^3.3.1",
  "eslint-plugin-vue": "^7.7.0",
  "fontmin": "^0.9.8",
  "mocha": "^8.3.2",
  "mochawesome": "6.2.2",
  "nativescript-dev-appium": "6.1.3",
  "nativescript-set-version": "0.2.1",
  "nativescript-vue-template-compiler": "^2.8.4",
  "prettier": "^2.2.1",
  "rimraf": "3.0.2",
  "sass": "~1.32.8",
  "sass-loader": "~10.1.1",
  "scss-symbols-parser": "^2.0.1",
  "string-replace-loader": "~2.3.0",
  "tns-ios": "6.5.4",
  "typescript": "3.9.7",
  "vue": "2.6.12",
  "vue-i18n": "8.22.4",
  "vue-loader": "15.9.6",
  "vue-property-decorator": "^8.5.1",
  "webpack": "^4.46.0",
  "webpack-cli": "^3.3.12"
}

Please accept these terms

NCenerar commented 2 years ago

After digging into the source code, I found the bug and patched it on my local installation. L257 of lib/services/android-plugin-build-service.js:

    getRuntimeGradleVersions(projectDir) {
        return __awaiter(this, void 0, void 0, function* () {
            let runtimeGradleVersions = null;
            if (projectDir) {
                const projectData = this.$projectDataService.getProjectData(projectDir);
                const platformData = this.$platformsDataService.getPlatformData(this.$devicePlatformsConstants.Android, projectData);
                const projectRuntimeVersion = platformData.platformProjectService.getFrameworkVersion(projectData);
                /* runtimeGradleVersions = yield this.getGradleVersions(projectRuntimeVersion); */ // <-- THIS LINE WAS MISSING
                this.$logger.trace(`Got gradle versions ${JSON.stringify(runtimeGradleVersions)} from runtime v${projectRuntimeVersion}`);
            }
            if (!runtimeGradleVersions) {
                const latestRuntimeVersion = yield this.getLatestRuntimeVersion();
                runtimeGradleVersions = yield this.getGradleVersions(latestRuntimeVersion);
                this.$logger.trace(`Got gradle versions ${JSON.stringify(runtimeGradleVersions)} from the latest runtime v${latestRuntimeVersion}`);
            }
            return runtimeGradleVersions || {};
        });
    }

I will try to fix it in this repo and create a pull request.

NCenerar commented 2 years ago

I created a fork and a branch for fixing this:https://github.com/NCenerar/nativescript-cli/tree/fix/issue-5650 I cannot create a pull request for patching NS 7.2.1 since there is no branch for NS 7.2 (apparently). I can still create a pull request for master since this bug seems to be still present.

Thank you.

rigor789 commented 2 years ago

@NCenerar this has been fixed in the 8.2 CLI, so please update your CLI and try with that. It should be backwards compatible with older projects, so just npm i -g nativescriptthen ns clean and build again - it should work.

NCenerar commented 2 years ago

@rigor789 Unfortunately, our project does not work with NativeScript 8. The migration tool didn't work out of the box and until now, we judged too risky to take the leap. Any chance to see a new version of NS7, like 7.2.2 😅

rigor789 commented 2 years ago

@NCenerar you do not need to update to NativeScript 8, just the CLI - which should be backwards compatible down to NS 6.x