Lỗi cant load native library boot image năm 2024

My version of Xcode was recently updated to 13.3. Now, I can not launch any simulator. I get an "Unable to Boot the Simulator" error from any iOS 15.4 device.

I have deleted all 15.4 devices, and am downloading 15.2 devices to test.

Some other sources are reporting this, too, but I saw nothing on the Developer Forums so thought I'd open a question here.

Hoping for speedy resolution so I don't have to use Android emulators :(. (I develop on Flutter, which is cross platform)

Accepted Reply

A reinstall did the trick for me. Back in business.

Replies

A reinstall did the trick for me. Back in business.

Same issue here, i was able to "solve it" by downloading the simulator for ios 15.2 instead of 15.4, then creating a new simulator using that version.

Now the simulator loads, but only on devices with 15.2 .

Just open xcode -> windows -> devices and simulators, click on the Simulators tab , click New, click on the OS Version dropdown and choose "Download more simulator runtimes", download 15.2 and create a new simulator with 15.2 as OS Version.

There seems to have been a problem with the simulator runtime for 15.4 in this xcode version

Same problem. I cannot launch device which os version is 15.4 or 15.5 (Only black screen or SpringBoard error). Older devices simulators (15.2/14.5 and other) launch normally. Mac OS Monterey 12.4/12.3 Xcode 13.4/13.3.1.

Changing simulator device help me fix this

So after looking in several threads I assume that there is a problem with older hardware (specially the gpu) and Monterey / newer Xcode versions. I don't know which gpu you are using but older ones have problems with OpenCL (which looks like Xcode is using). If you have a discrete and internal gpu try the following: -Open the Simulator or launch it -Under File/GPU Selection choose "Prefer integrated GPU" (this will only use the internal gpu of your Mac.) -Close Simulator and Xcode and try it again with newer Simulators like 13.4 or above. (But be aware that the performance is lower than with the external gpu)

No need to download a new ios version. All you need is to go to About this Mac > Storage > Manage > Delete XCode Cache. And, it works for me

Go to About this Mac > Storage > Manage > Delete XCode Cache and all old versions of iOS. Then run again. It works for me.

Thanks this worked for me on 12.4 as well!

Thanks this worked for me.

It's 2023, The latest MacOS is Ventura and the latest Xcode Version is 14.3.1. Here's how I solved this problem:

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.

I'm trying to use OpenCV with Spring boot. OpenCV jar and its native library are built from the source and placed inside my boot jar. I've extracted them from the jar and loaded successfully, but the error is thrown when using. Here's the summarization of my attempts

  • Using OpenCV package from openpnp. Worked fine, when I try to load the library again with System.loadLibrary(Core.NATIVE_LIBRARY_NAME), it throws UnsatisfiedLinkError: Native library is already loaded in another classloader. Removing the second load worked, but since they don't have the version I need, so I have to manually build OpenCV to use.
  • Test my OpenCV build (jar and native library) with a console project by manually add them to java.library.path, works fine.
  • Try to replicate the code from nu.pattern.OpenCV to load my build, modified accordingly. Library loaded without any error, try to load again with System.loadLibrary(Core.NATIVE_LIBRARY_NAME), no error. Try using any method of OpenCV, error is thrown.

Here's my code

OpenCVLoader.java

import org.opencv.core.Core;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.nio.file.AccessDeniedException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class OpenCVLoader {
    private static final Logger LOGGER = LoggerFactory.getLogger(OpenCVLoader.class);
    private static final String NATIVE_LIB_NAME = "libopencv_java3411.dylib";
    private static Path extractNativeBinary() {
        Path nativeLibTemporaryPath = null;
        try (InputStream nativeLibInputStream = new ClassPathResource(NATIVE_LIB_NAME).getInputStream()) {
            nativeLibTemporaryPath = new TemporaryDirectory().markDeleteOnExit().getPath().resolve("./" + NATIVE_LIB_NAME).normalize();
            Files.createDirectories(nativeLibTemporaryPath.getParent());
            Files.copy(nativeLibInputStream, nativeLibTemporaryPath);
            return nativeLibTemporaryPath;
        } catch (IOException ex) {
            LOGGER.error(ex.getMessage());
        }
        return nativeLibTemporaryPath;
    }
    private static class TemporaryDirectory {
        static final String OPENCV_PREFIX = "opencv";
        final Path path;
        public TemporaryDirectory() {
            try {
                path = Files.createTempDirectory(OPENCV_PREFIX);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        public Path getPath() {
            return path;
        }
        public TemporaryDirectory markDeleteOnExit() {
            Runtime.getRuntime().addShutdownHook(new Thread() {
                @Override
                public void run() {
                    delete();
                }
            });
            return this;
        }
        private void delete(Path path) {
            if (!Files.exists(path)) {
                return;
            }
            try {
                Files.walkFileTree(path, new SimpleFileVisitor() {
                    @Override
                    public FileVisitResult postVisitDirectory(final Path dir, final IOException e) throws IOException {
                        Files.deleteIfExists(dir);
                        return super.postVisitDirectory(dir, e);
                    }
                    @Override
                    public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
                            throws IOException {
                        Files.deleteIfExists(file);
                        return super.visitFile(file, attrs);
                    }
                });
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        public void delete() {
            delete(path);
        }
    }
    /**
  • Exactly once per {@link ClassLoader}, attempt to load the native library (via {@link System # loadLibrary(String)} with {@link Core # NATIVE_LIBRARY_NAME}). If the first attempt fails, the native binary will be extracted from the classpath to a temporary location (which gets cleaned up on shutdown), that location is added to the {@code java.library.path} system property and {@link ClassLoader # usr_paths}, and then another call to load the library is made. Note this method uses reflection to gain access to private memory in {@link ClassLoader} as there's no documented method to augment the library path at runtime. Spurious calls are safe. / public static void loadShared() { SharedLoader.getInstance(); } /*
  • @see Initialization-on-demand holder idiom / private static class SharedLoader { // Class loader error messages indicating OpenCV is not found on java.library.path private static final List errorMessages = Arrays.asList( String.format("no %s in java.library.path", Core.NATIVE_LIBRARY_NAME), String.format("%s (Not found in java.library.path)", Core.NATIVE_LIBRARY_NAME) ); private Path libraryPath; private SharedLoader() { try { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } catch (final UnsatisfiedLinkError ule) { / Only update the library path and load if the original error indicates it's missing from the library path. / if (ule == null || !openCVNotFoundInJavaLibraryPath(ule.getMessage())) { throw ule; } / Retain this path for cleaning up the library path later. / this.libraryPath = extractNativeBinary(); addLibraryPath(libraryPath.getParent()); System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } } /*
    • Check if any error fragment is contained in the errorMessage
    • @param errorMessage the message to check
    • @return true if any error fragment matches, false otherwise / private boolean openCVNotFoundInJavaLibraryPath(String errorMessage) { for (String errorFragment : errorMessages) { if (errorMessage.contains(errorFragment)) { return true; } } return false; } /*
    • Cleans up patches done to the environment. / @Override protected void finalize() throws Throwable { super.finalize(); if (null == libraryPath) { return; } removeLibraryPath(libraryPath.getParent()); } private static class Holder { private static final SharedLoader INSTANCE = new SharedLoader(); } public static SharedLoader getInstance() { return Holder.INSTANCE; } /*
    • Adds the provided {@link Path}, normalized, to the {@link ClassLoader # usr_paths} array, as well as to the {@code java.library.path} system property. Uses the reflection API to make the field accessible, and maybe unsafe in environments with a security policy. *
    • @see Adding new paths for native libraries at runtime in Java */ private static void addLibraryPath(final Path path) { final String normalizedPath = path.normalize().toString(); try { final Field field = ClassLoader.class.getDeclaredField("usr_paths"); field.setAccessible(true); final Set userPaths = new HashSet<>(Arrays.asList((String[]) field.get(null))); userPaths.add(normalizedPath); field.set(null, userPaths.toArray(new String[userPaths.size()])); System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + normalizedPath); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to get permissions to set library path"); } catch (NoSuchFieldException e) { throw new RuntimeException("Failed to get field handle to set library path"); } } } }

ObjectDetectionService.java

public class ObjectDetectionService {
    static {
        OpenCVLoader.loadShared(); // loaded fine,
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME); //try to load 1 more time, no exception is thrown
        Mat testMat = new Mat(); // UnsastifiedLinkError;
    }
}

stack trace

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-07-06 10:02:18,639 ERROR [restartedMain] --- [org.springframework.boot.SpringApplication][SpringApplication.java:837] Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectDetectionService' defined in file [/Users/minhtus/personal/ppr/build/classes/java/main/com/fptu/swp/ppr/detection/service/ObjectDetectionService.class]: Instantiation of bean failed; nested exception is java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat()J
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1320)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:895)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at com.fptu.swp.ppr.Application.main(Application.java:30)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat()J
    at org.opencv.core.Mat.n_Mat(Native Method)
    at org.opencv.core.Mat.(Mat.java:23)
    at com.fptu.swp.ppr.detection.service.ObjectDetectionService.(ObjectDetectionService.java:32)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:204)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1312)
    ... 23 common frames omitted