Installing of APK produced by capacitor fails

Dear community,
in the past days I created a small app by use of Capacitor that runs fine in Android Studio.
For simplicity I picked the debug version of the APK file from the project folder and tried to install it on my own mobile (Samsung A50). Android asked several questions regarding security and finally said “App not installed”. However the app was visible in the list of apps and ran fine.
Then I sent the APK to another user. Unfortunate installation fails on his mobile (Xiaomi) although he says that he installed APKs from unknown sources successfully before.
How to fix this? Is the debug version of the APK not suited for running standalone? How can I build a correct APK?
Best regards, Ulrich
In case it helps, this is the javascript:

        window.addEventListener('click', event => {
            if (event.target.id == 'btn-pick-db-file') {
                exportsFilepicker.pickFiles({
                    types: ['application/octet-stream'],
                    multiple: false
                }).then(result => {
                    console.log(result.files[0]);
                    Capacitor.Plugins.Filesystem.readFile({ path: result.files[0].path })
                        .then(file => {
                            console.log(file.data);
                            fetch('data:application/octet-stream;base64,' + file.data)
                                .then(res => res.blob())
                                .then(blob => {
                                    console.log(blob);
                                    window.capacitor_blob_writer({
                                        path: 'file:///data/user/0/com.substanzen.app/databases/SubstancesSQLite.db',
                                        blob: blob
                                        // fast_mode: true
                                    }).then(result => {
                                        alert('Datenbankdatei wurde erfolgreich eingelesen');
                                        displaySubstances();
                                    });
                                });
                        });
                });
            }
        });
        function readDatabaseFile(event) {
            Capacitor.Plugins.Filesystem.requestPermissions().then((status) => {
                console.log(status);
                fetch('https://example.com/path/db-cors.php')
                    .then(response => response.blob())
                    .then(blob => {
                        // console.log(blob);
                        window.capacitor_blob_writer({
                            path: 'file:///data/user/0/com.substanzen.app/databases/SubstancesSQLite.db',
                            blob: blob
                            // fast_mode: true
                        }).then(result => {
                            alert('Datenbankdatei wurde erfolgreich eingelesen');
                        });
                    });
            });
        }
        function displaySubstances() {
            conn = new exports.SQLiteConnection(exports.CapacitorSQLite);
            console.log(conn);
            conn.createConnection(
                "Substances", false, "no-encryption", 3, false
            ).then(db => {
                console.log(db);
                db.open("Substances", false, 'no-encryption', 3, true).then(() => {
                    const sql = 'select * from `Substanzen - Substanzen`';
                    db.query(sql).then(
                        result => {
                            console.log(result);
                            document.querySelector('section.substances').innerHTML = '';
                            result.values.forEach(row => {
                                console.log(row.Name + ' - ' + row.Art);
                                // HTML aus Template lesen und die Platzhalter ersetzen
                                let html = document.getElementById('substance-tpl').innerHTML
                                    .replace(/{{name}}/g, row.Name)
                                    .replace(/{{art}}/g, row.Art)
                                    .replace(/{{beschreibung}}/g, row.Beschreibung)
                                if (row.Bild) {
                                    console.log((typeof new Blob([new Uint8Array(row.Bild).buffer])))
                                    html = html.replace(/{{img}}/g, URL.createObjectURL(new Blob([new Uint8Array(row.Bild).buffer])));
                                } else {
                                    html = html.replace(/{{img}}/g, '""');
                                }
                                // HTML in section mit den Substanzen am Ende eintragen
                                document.querySelector('section.substances')
                                    .insertAdjacentHTML('beforeend', html)
                            });
                        });
                    db.close("Substances");
                });
            });
        }
        // displaySubstances();

Edit: In the meantime I read this:

and built a debug version of the app but no success, cannot be installed either.

Edit1: Performed some more research and built a release APK. Unfortunately installation of this APK fails complete: Message “App wasn’t installed” displaying immediately without any querys regarding security.

Update: Debug version can be installed and is running now.

Issue that release version cannot be installed persists. Hints how to fix this are welcome.

have you used a key?
wirthout the key i think you can’t install the “release” version (maybe i’m wrong, but i had a similar issue and i’ve solved using the release key)

1 Like

Hi @ciccilleju
thanks for this hint, I’m gonna try this later. I have to postpone the issue with the release Build as the debug version is still not running: Runs fine on my own mobile but when I send the APK to a friend it crashes.

Android tends to put up a fuss if you try to install an app from outside the Play Store, but that’s unrelated, it’ll still let you do it.
I believe release versions have to be signed before you can install them. If you want a signed version, you can generate a keystore and Android Studio can use that to sign the app - then you’ll be able to upload it to the Play Store or distribute as you please.

Create a first unsigned release apk.
Then signed the apk with apksigner . You can install signed apk on android mobile.

For details steps
///Ionic 7 Angular : How to generate, sign APK and Bundles for publishing to playstore console - YouTube