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 gradle-wrapper.properties file is below
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-bin.zip

I then updated the distributionURL to https\://services.gradle.org/distributions/gradle-3.5-bin.zip

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 -Dorg.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/ but got the same error

How do I run gradlew with Java 8? Thanks.