vscode-dev-containers icon indicating copy to clipboard operation
vscode-dev-containers copied to clipboard

gradle fails with `Failed to load native library 'libnative-platform.so' for Linux amd64`

Open baywet opened this issue 3 years ago • 5 comments

  • VSCode Version: 1.71.1
  • Local OS Version: windows-11 21H2 22000.856
  • Local chip architecture: <x86, arm64, Apple Silicon> x64
  • Reproduces in: <Codespaces | Remote - Containers | Both> Remote container
  • Name of Dev Container Definition with Issue: 1?

Steps to Reproduce:

  1. Configure the dev container for java variant 17 or 17-bullseye, node lts, install maven false install gradle true. features github cli latest, powershell latest
  2. Build and start the container (reopen in dev container)
  3. type "gradle -v" in the shell

The following error happens

Failed to load native library 'libnative-platform.so' for Linux amd64

Full configuration:

{
	"name": "Java",
	"build": {
		"dockerfile": "Dockerfile",
		"args": {
			// Update the VARIANT arg to pick a Java version: 11, 17
			// Append -bullseye or -buster to pin to an OS version.
			// Use the -bullseye variants on local arm64/Apple Silicon.
			"VARIANT": "17",
			// Options
			"INSTALL_MAVEN": "false",
			"INSTALL_GRADLE": "true",
			"NODE_VERSION": "lts/*"
		}
	},

	// Configure tool-specific properties.
	"customizations": {
		// Configure properties specific to VS Code.
		"vscode": {
			// Set *default* container specific settings.json values on container create.
			"settings": { 
			},
			
			// Add the IDs of extensions you want installed when the container is created.
			"extensions": [
				"editorconfig.editorconfig",
				"github.copilot",
				"github.vscode-pull-request-github",
				"donjayamanne.githistory",
				"waderyan.gitblame",
				"streetsidesoftware.code-spell-checker",
				"ms-vsliveshare.vsliveshare",
				"esbenp.prettier-vscode",
				"shengchen.vscode-checkstyle",
				"vscjava.vscode-java-pack",
				"vscjava.vscode-gradle",
				"DavidAnson.vscode-markdownlint"
			]
		}
	},

	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [],

	// Use 'postCreateCommand' to run commands after the container is created.
	// "postCreateCommand": "java -version",

	// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
	"remoteUser": "vscode",
	"features": {
		"github-cli": "latest",
		"powershell": "latest"
	}
}
# [Choice] Java version (use -bullseye variants on local arm64/Apple Silicon): 11, 17, 11-bullseye, 17-bullseye, 11-buster, 17-buster
ARG VARIANT=11-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/java:${VARIANT}

# [Option] Install Maven
ARG INSTALL_MAVEN="false"
ARG MAVEN_VERSION=""
# [Option] Install Gradle
ARG INSTALL_GRADLE="false"
ARG GRADLE_VERSION=""
RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
    && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
#     && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1

baywet avatar Sep 14 '22 13:09 baywet

Adding the following lines to devcontainer.json fixed it for me.

 "containerEnv": {
    "GRADLE_USER_HOME": "/home/vscode/.gradle"
}

ChriFo avatar Sep 16 '22 17:09 ChriFo

confirmed! Thanks for sharing this! Do you want to send out the PR or shall I? https://github.com/microsoft/vscode-dev-containers/tree/main/containers/java

baywet avatar Sep 16 '22 18:09 baywet

(although after running gradle build, it created a $HOME directory at the root of the repo)

baywet avatar Sep 16 '22 18:09 baywet

@baywet sorry, I adjusted my answer before your anwsers to a fully-qualified path because of the issue you described.

Feel free to open PR.

ChriFo avatar Sep 16 '22 19:09 ChriFo

authored #1632. The bug was subtle between user changed in the script and variables being interpreted too early thus yielding no value.

baywet avatar Sep 18 '22 20:09 baywet

It took me a while to revert to this but now (1.73.1) if you go through the creation of the container experience again with the same arguments it'll give you this instead.

{
	"name": "Java",
	"image": "mcr.microsoft.com/devcontainers/java:17",
	"features": {
		"ghcr.io/devcontainers/features/java:1": {
			"version": "none",
			"installMaven": "true",
			"installGradle": "true"
		},
		"ghcr.io/devcontainers/features/node:1": {
			"version": "lts"
		},
		"ghcr.io/devcontainers/features/github-cli:1": {},
		"ghcr.io/devcontainers/features/powershell:1": {}
	}

	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [],

	// Use 'postCreateCommand' to run commands after the container is created.
	// "postCreateCommand": "java -version",

	// Configure tool-specific properties.
	// "customizations": {},

	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
	// "remoteUser": "root"
}

(without a dockerfile) While it takes significantly longer to build, it also works from the get-go. Which means no changes are required to the base dockerfile anymore. Closing.

baywet avatar Nov 17 '22 19:11 baywet