简体   繁体   中英

Error running xlsx and rJava on Mac with M1

I've recently started working on a MacBook with M1 Max. But now, in R , with xlsx I get this error:

library(xlsx)
Error: package or namespace load failed for ‘xlsx’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(jli, FALSE)
  error: unable to load shared object '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib':
  dlopen(/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib, 0x000A): tried: '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib' (no such file), '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

rJava seemed to be the problem, so I tried to install and run that:

install.packages("rJava")
library(rJava)
Error: package or namespace load failed for ‘rJava’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(jli, FALSE)
  error: unable to load shared object '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib':
  dlopen(/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib, 0x000A): tried: '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib' (no such file), '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

I read around and see others with M1 have similar problems:

How to install rJava package in Mac with M1 architecture

https://github.com/rstudio/rstudio/issues/11130

I've tried following the steps in these, but still can't get it working.

This is my R version - R version 4.2.2 (64-bit). This is my java version - 1.8.0_351 (64-bit).

I've tried R CMD javareconf in terminal, and restarted the machine, but no change.

I've read that I may need to install java JDK 17 aarch64 ( Unable to use package rJava on Macbook with Apple M1 Chip, Get the error below ), or downgrade java to version 8 ( https://github.com/rstudio/rstudio/issues/11130 ).

TBH I'm at the point I don't really understand the advice in these pages, and am worried about messing up my machine. Would very much appreciate some help!

I've managed to fix this issue. The answer is from this post here: https://stackoverflow.com/a/70456947/8201618

brew install openjdk
brew info openjdk

Then there is a command like

For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

I ran this, restarted the computer, and now rJava and xlsx are working!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM