Skip to content
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

Add support for Apple Silicon (macOS M1) #244

Open
ioExpander opened this issue Sep 8, 2021 · 20 comments
Open

Add support for Apple Silicon (macOS M1) #244

ioExpander opened this issue Sep 8, 2021 · 20 comments

Comments

@ioExpander
Copy link

ioExpander commented Sep 8, 2021

Describe the bug
I'm failing to run studio 0.3.0 on my M1 Mac. There seems to be an issue with missing libusb4java binaries
Caused by: org.usb4java.LoaderException: Native library not found in classpath: /org/usb4java/darwin-aarch64/libusb4java.dylib
It seems that libusb4java recently added support for aarch64 but the darwin-aarch64 jar is missing in the lib folder of studio.

Thank you.

To Reproduce
Steps to reproduce the behavior:

  1. Install openjdk using homebrew (install aarch64 version) :
    brew install openjdk
  2. Run : studio-macos.sh

Logs

java.lang.ExceptionInInitializerError
	at studio.driver.LibUsbDetectionHelper.initializeLibUsb(LibUsbDetectionHelper.java:50)
	at studio.driver.raw.RawStoryTellerAsyncDriver.<init>(RawStoryTellerAsyncDriver.java:45)
	at studio.webui.service.StoryTellerService.<init>(StoryTellerService.java:54)
	at studio.webui.MainVerticle.start(MainVerticle.java:60)
	at io.vertx.core.AbstractVerticle.start(AbstractVerticle.java:106)
	at io.vertx.core.Verticle.start(Verticle.java:66)
	at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$9(DeploymentManager.java:556)
	at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:369)
	at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.usb4java.LoaderException: Native library not found in classpath: /org/usb4java/darwin-aarch64/libusb4java.dylib
	at org.usb4java.Loader.extractLibrary(Loader.java:246)
	at org.usb4java.Loader.load(Loader.java:323)
	at org.usb4java.LibUsb.<clinit>(LibUsb.java:690)
	... 16 more

Desktop and environment

  • OS: macOS Big Sur 11
  • Browser safari
  • Java version: OpenJDK 64-Bit Server VM Homebrew (build 17+0, mixed mode)
  • Maven version: N/A
  • STUdio application version 0.3.0
@ioExpander
Copy link
Author

ioExpander commented Sep 13, 2021

Hi. I've managed to compile and package a darwin-aarch64 version of the libusb master branch. There were a few minor changes required in the makefile see here : usb4java/libusb4java#12
Once copied to the lib folder of Studio, I can confirm that version 0.3.1 works with my Lunii on Macbook air M1 !

Note that this only works with Lunii v2.x firmwares. I had previously tried with a Lunii running v1.1 firmwares but studio did not work as there is no driver for the 1.1 firmware available for M1. Make sure you update your Lunii first !

I can share the aarch64 jar if needed, however i would recommend people to build it.

@Djailla
Copy link

Djailla commented Oct 24, 2021

I would love that you share the build package or the procedure to build the lib because I have the same issue

@ioExpander
Copy link
Author

Hi. The instruction to build the jar are in the message above. I recommend building the jar from sources using that link : usb4java/libusb4java#12

This is not recommended : if you still want to run a random file downloaded from the internet (just remove the .zip extension)
libusb4java-1.3.0-darwin-aarch64.jar.zip

@ghost
Copy link

ghost commented Feb 2, 2022

Hi, thank you for the aarch64 jar file. However, I still have a library error when I launch the sh file (also on M1).

Can't load library: /var/folders/jw/p7z6_jzn7wngh64rdnv_yt900000gn/T/usb4java18146965738665781312.tmp/libusb4java.dylib

Can you help please? Thank you very much...

@yageek
Copy link

yageek commented May 26, 2022

Thanks to @ioExpander, I was able to compile and run a version on one M1 laptop.

Install the openjdk

Using brew:

brew install openjdk

Build libusb4java

First, download the libusb source code from https://github.com/usb4java/libusb4java.

You will need to install the autotools and cmake elements to build the code.
I used brew:

brew install autoconf automake libtool cmake

I updated the CMakeLists.txt as following:

cmake_minimum_required(VERSION 2.8)

project(usb4java C)
set(PROJECT_VERSION 1.3.1)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/.cmake/Modules/")


set(JAVA_INCLUDE_PATH2 /opt/homebrew/opt/openjdk/include)
set(JAVA_INCLUDE_PATH /opt/homebrew/opt/openjdk/include)
set(JAVA_AWT_INCLUDE_PATH NotNeeded)

find_package(JNI REQUIRED)
find_package(LibUsb REQUIRED)

include_directories(${JNI_INCLUDE_DIRS})
include_directories(${LibUsb_INCLUDE_DIRS})

if(CMAKE_COMPILER_IS_GNUCC)
    add_definitions(-Wall -Werror -std=c99)
endif()


add_subdirectory(src)

Then we build the library from the root directory of libusb:

mvn clean install
cd dists/darwin
chmod +x build
./build

This will create one file named libusb4java-darwin.jar inside the target directory

Build studio

Install maven if you do not have it:

brew install maven

With the current version, I needed to update the version of one dependencies inside the pom.xml:

// Old version
 <frontend-maven-plugin.version>1.7.6</frontend-maven-plugin.version>

// Working version
<frontend-maven-plugin.version>1.12.1</frontend-maven-plugin.version>

Now you can build the studio:

mvn clean install

Copy the libusb4java jar inside the libs directory

Now move the generated jar to the web-ui/target/lib file and start the program using studio-mac.sh

@renoproc
Copy link

Hi,
I've just migrated my old Mac on a M1 Pro Monterey and encountered the issue described. I followed all the steps given by @yageek and with the ./build command I've reached a fatal error: 'jni.h' file not found....
(by the way, why a man clean install command in the first build step ?)

Tried to find how to get out of this, but the only thing I'be found is this Unable to compile under MacOS Big Sur #45 and it seems they didn't succeed...

Has anyone found a solution for this jni.h not found?
Many txs !!

@Djailla
Copy link

Djailla commented May 31, 2022

I guess it is mvn clean install instead of man clean install

@yageek
Copy link

yageek commented May 31, 2022

Completely right 😅

I updated the comment!

@renoproc
Copy link

Ok, I was guessing right, the man command seemed weird.
But do not solve the fatal error: 'jni.h' file not found ...

Do you have any idea ?

@olup
Copy link

olup commented Jul 18, 2022

Hey, just FIY I created a golang app that can install STUdio packs on your lunii: https://github.com/olup/lunii-admin

The macos version is built for intel but works fine on M1 (I am developing on m1, and can provide m1 builds if really needed)

@charafsalmi
Copy link

Hi,
Is there any news on this matter? Could anybody make a build for m1 chips, please?
Best regards.

@tomtomtls
Copy link

I would also love to have this problem solved since I am facing an error while building the lib:

`24 warnings generated.

CCLD libusb-1.0.la

.././install-sh -c -d '/tmp/libusb4java/target/build/darwin-x86_64/root/lib'

/bin/sh ../libtool --mode=install /usr/bin/install -c -s libusb-1.0.la '/tmp/libusb4java/target/build/darwin-x86_64/root/lib'

libtool: install: /usr/bin/install -c .libs/libusb-1.0.lai /tmp/libusb4java/target/build/darwin-x86_64/root/lib/libusb-1.0.la

libtool: install: /usr/bin/install -c .libs/libusb-1.0.a /tmp/libusb4java/target/build/darwin-x86_64/root/lib/libusb-1.0.a

libtool: install: chmod 644 /tmp/libusb4java/target/build/darwin-x86_64/root/lib/libusb-1.0.a

libtool: install: ranlib /tmp/libusb4java/target/build/darwin-x86_64/root/lib/libusb-1.0.a

.././install-sh -c -d '/tmp/libusb4java/target/build/darwin-x86_64/root/include/libusb-1.0'

/usr/bin/install -c -m 644 libusb.h '/tmp/libusb4java/target/build/darwin-x86_64/root/include/libusb-1.0'

make[3]: Nothing to be done for `install-exec-am'.

./install-sh -c -d '/tmp/libusb4java/target/build/darwin-x86_64/root/lib/pkgconfig'

/usr/bin/install -c -m 644 libusb-1.0.pc '/tmp/libusb4java/target/build/darwin-x86_64/root/lib/pkgconfig'

CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):

Compatibility with CMake < 2.8.12 will be removed from a future version of

CMake.

Update the VERSION argument value or use a ... suffix to tell

CMake that the project does not need compatibility with older versions.

...

-- The C compiler identification is AppleClang 13.1.6.13160021

-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - done

-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped

-- Detecting C compile features

-- Detecting C compile features - done

-- Found JNI: /Library/Java/JavaVirtualMachines/jdk-11.0.14.1+1/Contents/Home/include found components: AWT JVM

CMake Error at .cmake/Modules/FindLibUsb.cmake:103 (message):

libusb NOT FOUND! Try defining LibUsb_LIBRARIES manually

Call Stack (most recent call first):

CMakeLists.txt:13 (find_package)`

@yageek
Copy link

yageek commented Sep 22, 2022

You are missing the libusb library. I think some versions can be found in homebrew.

To install it:

brew install libusb

Then, you could give a new try

@tomtomtls
Copy link

Thank you @yageek I already did that. Changing the JDK leads to another error :
`ld: warning: ignoring file /opt/homebrew/lib/libusb-1.0.a, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

Undefined symbols for architecture x86_64:

"_libusb_alloc_streams", referenced from:

  _Java_org_usb4java_LibUsb_allocStreams in LibUsb.c.o

"_libusb_alloc_transfer", referenced from:

  _Java_org_usb4java_LibUsb_allocTransfer in LibUsb.c.o

...

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make[2]: *** [src/libusb4java.dylib] Error 1

make[1]: *** [src/CMakeFiles/usb4java.dir/all] Error 2

make: *** [all] Error 2`

@tomtomtls
Copy link

Did anyone face this error in the past and/or could help me to get Studio running on my Mac M1 please?

@mahesh-msk
Copy link

target

Need help, I'm able to build and got libusb4java.dylib, How to generate jar from dylib

libusb4java.dylib

@tplet
Copy link

tplet commented Jul 6, 2023

Thank you @yageek I already did that. Changing the JDK leads to another error : `ld: warning: ignoring file /opt/homebrew/lib/libusb-1.0.a, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

Undefined symbols for architecture x86_64:

"_libusb_alloc_streams", referenced from:

  _Java_org_usb4java_LibUsb_allocStreams in LibUsb.c.o

"_libusb_alloc_transfer", referenced from:

  _Java_org_usb4java_LibUsb_allocTransfer in LibUsb.c.o

...

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make[2]: *** [src/libusb4java.dylib] Error 1

make[1]: *** [src/CMakeFiles/usb4java.dir/all] Error 2

make: *** [all] Error 2`

I face to the same problem sadly.
Any news ?

@tplet
Copy link

tplet commented Jul 6, 2023

Hi. The instruction to build the jar are in the message above. I recommend building the jar from sources using that link : usb4java/libusb4java#12

This is not recommended : if you still want to run a random file downloaded from the internet (just remove the .zip extension) libusb4java-1.3.0-darwin-aarch64.jar.zip

I use your .jar file and its work (copying to lib/ directory to studio directory). Thanks !

@molusk
Copy link

molusk commented Aug 13, 2023

Hi,
I was able to compile the dylib file that was missing along with the jar file shared by @ioExpander
I don’t know how to generate the jar file itself...
Anyway, I put the jar and dylib files in the studio/lib directory and it worked well :)
I share the dylib file, in case someone needs it here (me in the future for example), just rename it without the .txt extension.
libusb4java.dylib.txt

@giomasce
Copy link

I also have an Apple Silicon laptop, and I managed to have the program working by using the x86 OpenJDK installed via Brew. These steps might be useful:

  1. Install Rosetta:
softwareupdate --install-rosetta
  1. Install Homebrew for x86:
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  1. Install OpenJDK:
/usr/local/bin/brew install openjdk
  1. Set the PATH to use Java from the OpenJDK you just installed:
export PATH=/usr/local/opt/openjdk/bin:$PATH
  1. Now you can run Studio, in the unzipped directory:
./studio-macos.sh

This might be easier than recompiling libusb. It might also be slower and require more disk space, because of emulated CPU and the additional libraries required.

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

No branches or pull requests