Failed to load native library 'libnative-platform.dylib' for Mac OS X x86_64

I am trying to run some gradle tasks on a old project. The project uses Java 8 and gradle 3.4.1. When I run a simple command using the gradle wrapper, for example ./gradlew clean I get the error Failed to load native library 'libnative-platform.dylib' for Mac OS X x86_64. There is no additional information provided when I run with the options --stacktrace, --info, or --debug.

The file is below

I then updated the distributionURL to https\://

Now when I run ./gradlew clean I get the error java.lang.IllegalArgumentException: Could not determine java version from '12.0.2'

I have both Java 8 and 12 installed on my mac.
The build.gradle file is set to
sourceCompatibility = 1.8
targetCompatibility = 1.8

IntelliJ is set to use Java 1.8 SDK

Tried running with
./gradlew clean but got the same error

How do I run gradlew with Java 8? Thanks.