Skip to content

Error while getting gradle data for android runtime from view command: SyntaxError: Unexpected end of JSON input #9814

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

Closed
3 tasks done
lambourn opened this issue Mar 8, 2022 · 13 comments

Comments

@lambourn
Copy link

lambourn commented Mar 8, 2022

Issue Description

NS CLI 8.1.4 is installed, now our Android builds after @nativescript/android@8.2.0 was introduced.

Obviously the gradle node is not existing in the published package.json but the ns build process does an npm view @nativescript/android@8.2.0 gradle --json which yields an empty string/JSON

Reproduction

  • install NS CLI 8.1.4 (Android Runtime android@8.1.1)
  • create the most simplistic ns project
  • build for Android
ns --version
8.1.4
ℹ New version of NativeScript CLI is available (8.1.5), run 'npm i -g nativescript' to update.

...
ns build android --log trace
...

Got gradle versions null from runtime v8.1.1
Exec npm view @nativescript/android  dist-tags --json 
 stdout: {
  "rc": "8.2.0-rc.0",
  "latest": "8.2.0",
  "alpha": "8.2.0-alpha.11"
}
 
 stderr: 
Exec npm view @nativescript/android@8.2.0  gradle --json 
 stdout:  
 stderr: 
Error while getting gradle data for android runtime from view command: SyntaxError: Unexpected end of JSON input
Exec npm config get registry 

or most specifically:

npm view @nativescript/android@8.2.0  gradle --json 
// no output!
npm view @nativescript/android@8.1.1  gradle --json 
{
  "version": "6.4",
  "android": "3.6.4"
}

Relevant log output (if applicable)

No response

Environment

No response

Please accept these terms

@lambourn lambourn added the bug-pending-triage Reported bug, pending triage to confirm. label Mar 8, 2022
@lambourn
Copy link
Author

lambourn commented Mar 8, 2022

@rigor789
Copy link
Member

rigor789 commented Mar 8, 2022

Please install nativescript@next (it's due to be published later today)

npm i -g nativescript@next

@lambourn
Copy link
Author

lambourn commented Mar 8, 2022

we just found that there is a merged PR for nativescript-cli NativeScript/nativescript-cli#5614 which fixes this, but no 8.2.0 CLI release which includes this PR.

@rigor789 rigor789 removed the bug-pending-triage Reported bug, pending triage to confirm. label Mar 8, 2022
@rigor789 rigor789 changed the title Breaking: @nativescript/android@8.2.0 gradle node is empty causing build issues with CLI 8.1.4 Error while getting gradle data for android runtime from view command: SyntaxError: Unexpected end of JSON input Mar 8, 2022
@rigor789 rigor789 pinned this issue Mar 8, 2022
@lambourn
Copy link
Author

lambourn commented Mar 8, 2022

@rigor789 thanks. This impacts our CI builds so we'll need to create new images which takes some time. I'm thinking of building a patched version just for the sake of getting our builds stable.

@rigor789
Copy link
Member

rigor789 commented Mar 8, 2022

@lambourn you could pin @nativescript/android version to 8.1.5 I guess - and bump to 8.2.0 once you have your CI setup updated?

@lambourn
Copy link
Author

lambourn commented Mar 8, 2022

@rigor789 I would - but there is no published @nativescript/android version 8.1.5

@rigor789
Copy link
Member

rigor789 commented Mar 8, 2022

Sorry, I meant 8.1.1 - the previous stable version

@lambourn
Copy link
Author

lambourn commented Mar 8, 2022

@rigor789 well, this is what we actually use as a pinned version, @nativescript/android@8.1.1

I just locally patched the nativescript/lib/services/android-plugin-build-service.js of the 8.1.4 CLI and added the missing bit and am able to build now.

// this was missing after line 433 in https://github.com/NativeScript/nativescript-cli/blob/1fc3893e5bff66816d195d28aeafa01f2649ba5d/lib/services/android-plugin-build-service.ts
runtimeGradleVersions = await this.getGradleVersions(projectRuntimeVersion);

@rigor789
Copy link
Member

rigor789 commented Mar 8, 2022

I re-tagged 8.1.1 as latest on npm - that should probably solve the issue... We might need to add back that gradle key for backwards compatibility - and phase it out later.

@rigor789
Copy link
Member

rigor789 commented Mar 8, 2022

Added the gradle key back in 8.2.1 - It's not actually being used as far as I can tell - but we'll need to look around and phase it out in a future release.

NativeScript/android@af925d5

@rigor789 rigor789 closed this as completed Mar 8, 2022
@lambourn
Copy link
Author

lambourn commented Mar 9, 2022

@rigor789 thanks for the prompt resolution. I gave it a try: at least for us this does not resolve the issue.

The 8.1.4 CLI now gets the values from the android 8.2.1 package.json which is expected Iif I got you right:

Got gradle versions null from runtime v8.1.1
Exec npm view @nativescript/android  dist-tags --json 
 stdout: {
  "rc": "8.2.0-rc.0",
  "latest": "8.2.1",
  "alpha": "8.2.0-alpha.11"
}
 
 stderr: 
Exec npm view @nativescript/android@8.2.1  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.1

and as a result the CLI downloads G7 which in the end leads to build failures as some of our custom code and 3rd party plugins is not yet G7 compatible.

In the end this boils down to the missing line in android-plugin-build-service.ts which does not prefer the Gradle version of the locally used @nativescript/android version I posted above.

We'll have to stay with {N} 8.1.4/5 for now, so local patching of the CLI is the only option for us.

@rigor789
Copy link
Member

rigor789 commented Mar 9, 2022

Just looked a bit more into this - cli 8.2 should definitely fix this for older projects too (it's backwards compatible, so should be safe to upgrade the CLI whenever you can). I also just prepared a PR that changes the behavior slightly - to always try reading from the local runtime package.json before going to npm view - this should be hit 99.9% of the time (I guess?) and save some time by not going out to the npm registry. NativeScript/nativescript-cli#5646

@lambourn
Copy link
Author

lambourn commented Mar 9, 2022

Hey @rigor789 - nice, sounds great 🤘

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

No branches or pull requests

2 participants