gluonhq / gluonfx-maven-plugin

Plugin that simplifies creating native images for Java/JavaFX maven projects
BSD 3-Clause "New" or "Revised" License
189 stars 39 forks source link

java.lang.UnsatisfiedLinkError: Can't load library: /path/aplicacion/sqlite-3.39.3.0-8779dbb7-71dd-4bb6-b74c-03a4d2abb73a-libsqlitejdbc.so #444

Closed Hitzui closed 1 year ago

Hitzui commented 2 years ago

Dear, it presents the following error when executing the application, being more specific, when loading the sqlite data, when generating the APK, it does not generate any error, in fact the application runs fine, the error occurs when making the connection to the base of data.

D/GraalCompiled: Sep 18, 2022 8:07:43 PM com.dysconcsa.sondeo.dao.DataConnection readDB
D/GraalCompiled: INFO: Path of url: jdbc:sqlite:/storage/emulated/0/Documents/sondeo.db
D/GraalCompiled: Failed to load native library:sqlite-3.39.3.0-8779dbb7-71dd-4bb6-b74c-03a4d2abb73a-libsqlitejdbc.so. osinfo: Linux/aarch64
D/GraalCompiled: java.lang.UnsatisfiedLinkError: Can't load library: /data/data/com.dysconcsa.sondeo.sondeo2/sqlite-3.39.3.0-8779dbb7-71dd-4bb6-b74c-03a4d2abb73a-libsqlitejdbc.so
D/GraalCompiled:     at com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibraryAbsolute(NativeLibrarySupport.java:104)
D/GraalCompiled:     at java.lang.ClassLoader.loadLibrary(ClassLoader.java:54)
D/GraalCompiled:     at java.lang.Runtime.load0(Runtime.java:755)
D/GraalCompiled:     at java.lang.System.load(System.java:1953)
D/GraalCompiled:     at org.sqlite.SQLiteJDBCLoader.loadNativeLibrary(SQLiteJDBCLoader.java:280)
D/GraalCompiled:     at org.sqlite.SQLiteJDBCLoader.extractAndLoadLibraryFile(SQLiteJDBCLoader.java:237)
D/GraalCompiled:     at org.sqlite.SQLiteJDBCLoader.loadSQLiteNativeLibrary(SQLiteJDBCLoader.java:350)
D/GraalCompiled:     at org.sqlite.SQLiteJDBCLoader.initialize(SQLiteJDBCLoader.java:68)
D/GraalCompiled:     at org.sqlite.core.NativeDB.load(NativeDB.java:63)
D/GraalCompiled:     at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:278)
D/GraalCompiled:     at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:65)
D/GraalCompiled:     at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:28)
D/GraalCompiled:     at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:19)
D/GraalCompiled:     at org.sqlite.JDBC.createConnection(JDBC.java:104)
D/GraalCompiled:     at org.sqlite.JDBC.connect(JDBC.java:77)
D/GraalCompiled:     at java.sql.DriverManager.getConnection(DriverManager.java:681)
D/GraalCompiled:     at java.sql.DriverManager.getConnection(DriverManager.java:252)
D/GraalCompiled:     at com.dysconcsa.sondeo.dao.DataConnection.getConnection(DataConnection.java:22)
D/GraalCompiled:     at com.dysconcsa.sondeo.dao.DaoSuelos.<init>(DaoSuelos.java:27)
D/GraalCompiled:     at com.dysconcsa.sondeo.SondeoApplication.postInit(SondeoApplication.java:37)
D/GraalCompiled:     at com.gluonhq.charm.glisten.application.AppManager.continueInit(AppManager.java:328)
D/GraalCompiled:     at com.gluonhq.charm.glisten.application.AppManager.start(AppManager.java:288)
D/GraalCompiled:     at com.dysconcsa.sondeo.SondeoApplication.start(SondeoApplication.java:31)
D/GraalCompiled:     at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
D/GraalCompiled:     at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
D/GraalCompiled:     at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
D/GraalCompiled:     at java.security.AccessController.executePrivileged(AccessController.java:169)
D/GraalCompiled:     at java.security.AccessController.doPrivileged(AccessController.java:399)
D/GraalCompiled:     at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
D/GraalCompiled:     at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
D/GraalCompiled:     at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:51)
D/GraalCompiled:     at java.lang.Thread.run(Thread.java:833)
D/GraalCompiled:     at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704)
D/GraalCompiled:     at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
D/GraalCompiled: Sep 18, 2022 8:07:44 PM com.dysconcsa.sondeo.dao.DataConnection getConnection
D/GraalCompiled: WARNING: Error: Error opening connection
D/GraalCompiled: java.sql.SQLException: Error opening connection
D/GraalCompiled:     at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:281)
D/GraalCompiled:     at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:65)
D/GraalCompiled:     at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:28)
D/GraalCompiled:     at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:19)
D/GraalCompiled:     at org.sqlite.JDBC.createConnection(JDBC.java:104)
D/GraalCompiled:     at org.sqlite.JDBC.connect(JDBC.java:77)
D/GraalCompiled:     at java.sql.DriverManager.getConnection(DriverManager.java:681)
D/GraalCompiled:     at java.sql.DriverManager.getConnection(DriverManager.java:252)
D/GraalCompiled:     at com.dysconcsa.sondeo.dao.DataConnection.getConnection(DataConnection.java:22)
D/GraalCompiled:     at com.dysconcsa.sondeo.dao.DaoSuelos.<init>(DaoSuelos.java:27)
D/GraalCompiled:     at com.dysconcsa.sondeo.SondeoApplication.postInit(SondeoApplication.java:37)
D/GraalCompiled:     at com.gluonhq.charm.glisten.application.AppManager.continueInit(AppManager.java:328)
D/GraalCompiled:     at com.gluonhq.charm.glisten.application.AppManager.start(AppManager.java:288)
D/GraalCompiled:     at com.dysconcsa.sondeo.SondeoApplication.start(SondeoApplication.java:31)
D/GraalCompiled:     at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
D/GraalCompiled:     at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
D/GraalCompiled:     at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
D/GraalCompiled:     at java.security.AccessController.executePrivileged(AccessController.java:169)
D/GraalCompiled:     at java.security.AccessController.doPrivileged(AccessController.java:399)
D/GraalCompiled:     at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
D/GraalCompiled:     at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
D/GraalCompiled:     at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:51)
D/GraalCompiled:     at java.lang.Thread.run(Thread.java:833)
D/GraalCompiled:     at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704)
D/GraalCompiled:     at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
D/GraalCompiled: Caused by: java.lang.Exception: No native library found for os.name=Linux, os.arch=aarch64, paths=[/org/sqlite/native/Linux/aarch64:/usr/lib64:/lib64:/lib:/usr/lib]
D/GraalCompiled:     at org.sqlite.SQLiteJDBCLoader.loadSQLiteNativeLibrary(SQLiteJDBCLoader.java:375)
D/GraalCompiled:     at org.sqlite.SQLiteJDBCLoader.initialize(SQLiteJDBCLoader.java:68)
D/GraalCompiled:     at org.sqlite.core.NativeDB.load(NativeDB.java:63)
D/GraalCompiled:     at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:278)
D/GraalCompiled:    ... 24 more
D/GraalCompiled: java.lang.NullPointerException
D/GraalCompiled:     at com.dysconcsa.sondeo.dao.DaoSuelos.<init>(DaoSuelos.java:29)
D/GraalCompiled:     at com.dysconcsa.sondeo.SondeoApplication.postInit(SondeoApplication.java:37)
D/GraalCompiled:     at com.gluonhq.charm.glisten.application.AppManager.continueInit(AppManager.java:328)
D/GraalCompiled:     at com.gluonhq.charm.glisten.application.AppManager.start(AppManager.java:288)
D/GraalCompiled:     at com.dysconcsa.sondeo.SondeoApplication.start(SondeoApplication.java:31)
D/GraalCompiled:     at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
D/GraalCompiled:     at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
D/GraalCompiled:     at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
D/GraalCompiled:     at java.security.AccessController.executePrivileged(AccessController.java:169)
D/GraalCompiled:     at java.security.AccessController.doPrivileged(AccessController.java:399)
D/GraalCompiled:     at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
D/GraalCompiled:     at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
D/GraalCompiled:     at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:51)
D/GraalCompiled:     at java.lang.Thread.run(Thread.java:833)
D/GraalCompiled:     at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704)
D/GraalCompiled:     at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
Hitzui commented 2 years ago

Class of connection:

public class DataConnection {
    Connection connection;
    private final static String DB_NAME = "sondeo.db";
    Logger logger = Logger.getLogger(getClass().getName());
    public Connection getConnection() {
        try {
            connection = DriverManager.getConnection(readDB());
            connection.setReadOnly(false);
        } catch (SQLException e) {
            logger.warning("Error: " + e.getMessage());
            e.printStackTrace();
        }
        return this.connection;
    }

    private String readDB() throws SQLException {
        logger.info("Reading an existing Database with SQLite");
        String dbUrl = "jdbc:sqlite:";
        if (Platform.isDesktop()) {
            //dbUrl = dbUrl + ":resource:" + Objects.requireNonNull(SondeoApplication.class.getResource("/databases/" + DB_NAME)).toExternalForm();
            dbUrl = dbUrl + DB_NAME;
        } else {
            try {
                var resource = getClass().getClassLoader().getResource("databases/sondeo.db");
                DriverManager.registerDriver(new SQLDroidDriver());
                var privateStorage = Services.get(StorageService.class)
                        .flatMap(StorageService::getPrivateStorage)
                        .orElseThrow(() -> new IOException("Error: PrivateStorage not available"));
                var publicStorage = Services.get(StorageService.class)
                        .flatMap(storageService -> storageService.getPublicStorage("Documents"))
                        .orElseThrow(() -> new IOException("error al leer la carpeta publica de Documents"));
                File db = new File(publicStorage, DB_NAME);
                /*if (resource != null) {
                    var file = new File(resource.getFile());
                    logger.info("Copying database " + DB_NAME + " to private storage");
                    logger.info("Resource: " + file.getAbsolutePath());
                    DBUtils.copyDatabase(file.getParent() + "/", publicStorage.getAbsolutePath(), DB_NAME);
                    DBUtils.copyDatabase(publicStorage.getAbsolutePath(), privateStorage.getAbsolutePath(), DB_NAME);
                }*/
                dbUrl = dbUrl + db.getAbsolutePath();
            } catch (IOException ex) {
                logger.warning("IO error " + ex.getMessage());
                ex.printStackTrace();
            }
        }
        logger.info("Path of url: " + dbUrl);
        return dbUrl;
    }

    public DataConnection() {
        try {
            Class<?> c = null;
            if (Platform.isAndroid()) {
                c = Class.forName("org.sqldroid.SQLDroidDriver");
            } else if (Platform.isIOS()) {
                c = Class.forName("SQLite.JDBCDriver");
            } else if (Platform.isDesktop()) {
                c = Class.forName("org.sqlite.JDBC");
            } else if (System.getProperty("os.arch").toUpperCase().contains("ARM")) {
                c = Class.forName("org.sqldroid.SQLDroidDriver");
            }
        } catch (ClassNotFoundException e) {
            System.out.println("Error class not found " + e);
        }
    }
}
mipastgt commented 2 years ago

Just a few remarks from my side because I also never got that working:

ianopolous commented 2 years ago

I've made a little more progress here: https://github.com/gluonhq/gluonfx-maven-plugin/issues/447 Note the extra system property to set. But still not quite working.

mipastgt commented 2 years ago

So what is still not working? Did you use the native-image agent to collect all the classes which are loaded via reflection and other dependencies?

ianopolous commented 2 years ago

It was a spurious error. It's all working now with what's described in that other issue.

Hitzui commented 1 year ago

dear, I have tried to follow your instructions, and in my case, it continues to present the same error, if it is possible to help with an example code, I will greatly appreciate it, greetings.

Hitzui commented 1 year ago

Dear, now I get the following error, can you guide me how to do so that I can read the database file from the folder? I will appreciate it a lot.

D/GraalCompiled: Oct 25, 2022 9:52:05 AM com.dysconcsa.sondeo.dao.DataConnection readDB
D/GraalCompiled: INFO: Reading an existing Database with SQLite
D/GraalCompiled: Oct 25, 2022 9:52:05 AM com.dysconcsa.sondeo.dao.DataConnection readDB
D/GraalCompiled: INFO: Path of url: jdbc:sqlite:/data/user/0/com.dysconcsa.sondeo.sondeo2/.gluon/sondeo.db
D/GraalCompiled: Oct 25, 2022 9:52:05 AM com.dysconcsa.sondeo.dao.DataConnection getConnection
D/GraalCompiled: WARNING: Error: opening db: 'sondeo.db': Read-only file system
D/GraalCompiled: java.sql.SQLException: opening db: 'sondeo.db': Read-only file system