Categories
discuss

which function should I use? .toDataURL() or .toBlob()?

I want to resize image at client side using JavaScript. I found 2 solutions, one is using .toDataURL() function and the other is using .toBlob() function. Both solutions are worked. Well, I just curious what is the difference between those two functions? which one is better? or when should I use .toDataURL() function or .toBlob() function?

Here is the code I used to output those two function, and I got very slightly different in image size (bytes) and image color (I’m not sure about this one). Is something wrong with the code?

<html>
    <head>
        <title>Php code compress the image</title>
    </head>
    <body>
        <input id="file" type="file" onchange="fileInfo();"><br>
        <div>
            <h3>Original Image</h3>
            <img id="source_image"/>
            <button onclick="resizeImage()">Resize Image</button>
            <button onclick="compressImage()">Compress Image</button>
            <h1 id="source_image_size"></h1>
        </div>
        <div>
            <h3>Resized Image</h3>
            <h1> image from dataURL function </h1>
            <img id="result_resize_image_dataURL"/>

            <h1> image from toBlob function </h1>
            <img id="result_resize_image_toBlob"/>
        </div>
        <div>
            <fieldset>
                <legend>Console output</legend>
                <div id='console_out'></div>
            </fieldset>
        </div>

        <script>
            //Console logging (html)
            if (!window.console)
            console = {};

            var console_out = document.getElementById('console_out');
            var output_format = "jpg";

            console.log = function(message) {
                console_out.innerHTML += message + '<br />';
                console_out.scrollTop = console_out.scrollHeight;
            }

            var encodeButton = document.getElementById('jpeg_encode_button');
            var encodeQuality = document.getElementById('jpeg_encode_quality');

            function fileInfo(){
                var preview = document.getElementById('source_image');
                var file   = document.querySelector('input[type=file]').files[0];
                var reader  = new FileReader();
                reader.addEventListener("load", function(e) {
                    preview.src = e.target.result;
                }, false);
                if (file) {
                    reader.readAsDataURL(file);
                }
            }
            function resizeImage() {
                var loadedData = document.getElementById('source_image');
                var result_image = document.getElementById('result_resize_image_dataURL');

                var cvs = document.createElement('canvas'),ctx;
                cvs.width = Math.round(loadedData.width/4);
                cvs.height = Math.round(loadedData.height/4);
                var ctx = cvs.getContext("2d").drawImage(loadedData, 0, 0, cvs.width, cvs.height);
                cvs.toBlob(function(blob) {
                    var newImg = document.getElementById('result_resize_image_toBlob'),
                        url = URL.createObjectURL(blob);
                    newImg.onload = function() {
                        // no longer need to read the blob so it's revoked
                        URL.revokeObjectURL(url);
                    };

                    newImg.src = url;
                    console.log(blob.size/1024);
                }, 'image/jpeg', 0.92);

                var newImageData = cvs.toDataURL('image/jpeg', 0.92);
                var result_image_obj = new Image();
                result_image_obj.src = newImageData;
                result_image.src = result_image_obj.src;
                var head = 'data:image/png;base64,';
                var imgFileSize = ((newImageData.length - head.length)*3/4)/1024;
                console.log(imgFileSize);
            }

Edited:

Based on Result of html5 Canvas getImageData or toDataURL – Which takes up more memory?, its said that

“DataURL (BASE64) is imageData compressed to JPG or PNG, then converted to string, and this string is larger by 37% (info) than BLOB.”

What is the string mean? is it same as size in bytes? using the code I provided above, the size difference is less than 1Kb (less than 1%). is .toBlob() always better than .toDataURL() function? or there is a specific condition where it would be better to use .toDataURL() function?

Answer

Definitely go with toBlob().
toDataURL is really just an early error in the specs, and had it been defined a few months later, it certainly wouldn’t be here anymore, since we can do the same but better using toBlob.

toDataURL() is synchronous and will block your UI while doing the different operations

  • move the bitmap from GPU to CPU
  • conversion to the image format
  • conversion to base64 string

toBlob() on the other hand will only do the first bullet synchronously, but will do the conversion to image format in a non blocking manner. Also, it will simply not do the third bullet.
So in raw operations, this means toBlob() does less, in a better way.

toDataURL result takes way more memory than toBlob‘s.

The data-URL returned by toDataURL is an USVString, which contains the full binary data compressed in base64.
As the quote in your question said, base64 encoding in itself means that the binary data will now be ~37% bigger. But here it’s not only encoded to base64, it is stored using UTF-16 encoding, which means that every ascii character will take twice the memory needed by raw ascii text, and we jump to a 174% bigger file than its original binary data…
And it’s not over… Every time you’ll use this string somewhere, e.g as the src of a DOM element*, or when sending it through a network request, this string can get reassigned in memory once again.
*Though modern browsers seem to have mechanism to handle this exact case

You (almost) never need a data-url.

Everything you can do with a data-url, you can do the same better with a Blob and a Blob-URI.

To display, or locally link to the binary data (e.g for user to download it), use a Blob-URI, using the URL.createObjectURL() method.
It is just a pointer to the binary data held in memory that the Blob itself points to. This means you can duplicate the blob-URI as many times as you wish, it will always be a ~100 chars UTF-16 string, and the binary data will not move.

If you wish to send the binary data to a server, send it as binary directly, or through a multipart/formdata request.

If you wish to save it locally, then use IndexedDB, which is able to save binary files. Storing binary files in LocalStorage is a very bad idea as the Storage object has to be loaded at every page-load.

The only case you may need data-urls is if you wish to create standalone documents that need to embed binary data, accessible after the current document is dead. But even then, to create a data-url version of the image from your canvas, use a FileReader to which you’d pass the Blob returned by canvas.toBlob(). That would make for a complete asynchronous conversion, avoiding your UI to be blocked for no good reasons.

Categories
discuss

Electron run in production mode

I’m using the npm package https://github.com/sindresorhus/electron-is-dev

For some reason, isDev always returns true.

My npm script looks as follows:

"start:prod": "cross-env NODE_ENV=production && electron dist/main.js"

main.js:

import isDev from 'electron-is-dev';

app.on('ready', () => {
  console.log('isDev', isDev);
  if (!isDev) {
    const {session} = require('electron');
    session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
      callback({responseHeaders: `default-src http: ws:`})
    })
  }
  const win = createWindow();
  createMenu(win);
});

The console outputs:

isDev true

Documentation mentions:

You can force development mode by setting the ELECTRON_IS_DEV environment variable to 1.

But I don’t feel that putting the variable to zero should be necessary.

Outputting process.env.ELECTRON_IS_DEV logs undefined.

I found the following thread that I found confusing: https://github.com/electron/electron/issues/7714

I don’t see the use of an extra environment variable, when you set the NODE_ENV on startup… Unless there is a compelling reason not to, I will just check on process.env.NODE_ENV as I’m used to.

Answer

I don’t use that npm package but I’ll share what I do – (no idea if it is right or wrong but it works. I use it to run electron-reload during development).

package.json – set an env var in my ‘start’ script

  "scripts": {
    "start": "APP_DEV=true electron ."
   }

main.js – check for the env var in “main.js”

var isDev = process.env.APP_DEV ? (process.env.APP_DEV.trim() == "true") : false;

use it

if (isDev) {
    require('electron-reload')(__dirname, {
        electron: upath.toUnix(upath.join(__dirname, 'node_modules', '.bin', 'electron'))
    });
}

UPDATE: 4.28.20

Had to bring my project over to a Windows machine to work on some Windows-specific issues and the method above does not work there. Here is my question on that and an answer which gets it working on Windows: Setting an env var in package.json for use with electron-reload?

Categories
discuss

How to get number from promise?

Why does typescript says?

let shouldbeNumber: number Type ‘unknown’ is not assignable to type ‘number’.Vetur(2322)

turnIntoNumberwill always get strings of numbers such as 1,2,3,4,5,6… , so I know shouldbeNumber will always be a number. How can I convince typescript or develop this piece of code? 🙂

async function makeMagic() {
  let shouldbeNumber: number = await turnIntoNumber("2");
}
function turnIntoNumber(get) {
  return new Promise((resolve, reject) => {
    let shouldbeNumber : number =  Number(get);
    resolve(shouldbeNumber);
  });
}

Would you please help me to turn this javascript into a better typescript? Thanks in advance.

Answer

Annotate the functions return type

function turnIntoNumber(get) : Promise<number> {
  return new Promise((resolve, reject) => {
    let shouldbeNumber : number =  Number(get);
    resolve(shouldbeNumber);
  });
}
Categories
discuss

React-Native fresh App immediately closes when launch on real devices

I want to develop android app using React-Native, it works well on emulator, but when I try with real device, the app immediately closes when launch, even if it with fress react-native init projectName.

When I try to see at the Logcat, here is the result when I try to open the fresh app:

11-24 07:03:39.408 2007-2007/? E/PhoneStatusBar: updateNotificationTitleText  preIsInsidePanelCanSlide =true,misInsidePanelCanSlide = true,misInsidePanelOpen = false
11-24 07:03:40.068 2708-3433/? D/PhoneInterfaceManager: [PhoneIntfMgr] getDefaultSubscription, sub = 12
11-24 07:03:40.068 2708-3609/? D/PhoneInterfaceManager: [PhoneIntfMgr] getDefaultSubscription, sub = 12
11-24 07:03:40.098 2708-3600/? D/PhoneInterfaceManager: [PhoneIntfMgr] getDefaultSubscription, sub = 12
11-24 07:03:40.108 2708-3107/? D/PhoneInterfaceManager: [PhoneIntfMgr] getDefaultSubscription, sub = 12

    --------- beginning of system
11-24 07:03:40.118 1022-1042/? I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.library_app2/.MainActivity bnds=[286,87][539,358]} from uid 10059 and from pid 2779 on display 0
11-24 07:03:40.128 15968-15988/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.128 15968-15968/? D/KeyguardViewMediator: handleKeyguardVisibilityChanged mKeyguardViewManager = com.android.keyguard.KeyguardViewManager@12d66782
11-24 07:03:40.128 15968-15968/? D/KeyguardViewManager: handleKeyguardVisibilityChanged showing = true
11-24 07:03:40.138 1022-1042/? V/WindowManager: addAppToken: AppWindowToken{3930ddf5 token=Token{148c1f2c ActivityRecord{272956df u0 com.library_app2/.MainActivity t1328}}} to stack=1 task=1328 at 0
11-24 07:03:40.138 1022-1060/? V/WindowManager: Based on layer: Adding window Window{3f5127c4 u0 Starting com.library_app2} at 5 of 15
11-24 07:03:40.148 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.158 15968-15988/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.168 26069-26069/? I/art: Late-enabling -Xcheck:jni
11-24 07:03:40.168 1022-1904/? I/ActivityManager: Start proc 26069:com.library_app2/u0a343 for activity com.library_app2/.MainActivity
11-24 07:03:40.168 1022-1904/? D/ActivityManager:  (1) delay start com.library_app2 startResult.usingWrapper false
11-24 07:03:40.208 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.348 15968-15987/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.348 1022-1904/? V/WindowManager: Changing focus from Window{1786b351 u0 com.oppo.launcher/com.oppo.launcher.Launcher} to null Callers=com.android.server.wm.WindowManagerService.handleAppTransitionReadyLocked:9943 com.android.server.wm.WindowManagerService.performLayoutAndPlaceSurfacesLockedInner:10529 com.android.server.wm.WindowManagerService.performLayoutAndPlaceSurfacesLockedLoop:9333 com.android.server.wm.WindowManagerService.performLayoutAndPlaceSurfacesLocked:9275 
11-24 07:03:40.348 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.348 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.358 15968-15988/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.368 15968-15988/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.368 15968-15987/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.378 15968-15988/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.378 26069-26069/com.library_app2 D/SoLoader: init start
11-24 07:03:40.378 26069-26069/com.library_app2 D/SoLoader: adding system library source: /vendor/lib
11-24 07:03:40.378 26069-26069/com.library_app2 D/SoLoader: adding system library source: /system/lib
11-24 07:03:40.378 26069-26069/com.library_app2 D/SoLoader: adding application source: com.facebook.soloader.DirectorySoSource[root = /data/app/com.library_app2-1/lib/arm flags = 0]
11-24 07:03:40.388 26069-26069/com.library_app2 D/SoLoader: adding backup source from : com.facebook.soloader.ApkSoSource[root = /data/data/com.library_app2/lib-main flags = 1]
11-24 07:03:40.388 26069-26069/com.library_app2 D/SoLoader: Preparing SO source: com.facebook.soloader.DirectorySoSource[root = /system/lib flags = 2]
11-24 07:03:40.388 26069-26069/com.library_app2 D/SoLoader: Preparing SO source: com.facebook.soloader.DirectorySoSource[root = /system/vendor/lib flags = 2]
11-24 07:03:40.388 26069-26069/com.library_app2 D/SoLoader: Preparing SO source: com.facebook.soloader.DirectorySoSource[root = /data/app/com.library_app2-1/lib/arm flags = 0]
11-24 07:03:40.388 26069-26069/com.library_app2 D/SoLoader: Preparing SO source: com.facebook.soloader.ApkSoSource[root = /data/data/com.library_app2/lib-main flags = 1]
11-24 07:03:40.388 26069-26069/com.library_app2 V/fb-UnpackingSoSource: locked dso store /data/data/com.library_app2/lib-main
11-24 07:03:40.388 26069-26069/com.library_app2 I/fb-UnpackingSoSource: dso store is up-to-date: /data/data/com.library_app2/lib-main
11-24 07:03:40.388 26069-26069/com.library_app2 V/fb-UnpackingSoSource: releasing dso store lock for /data/data/com.library_app2/lib-main
11-24 07:03:40.388 26069-26069/com.library_app2 D/SoLoader: init finish: 4 SO sources prepared
11-24 07:03:40.388 26069-26069/com.library_app2 D/SoLoader: init exiting
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err: java.lang.ClassNotFoundException: com.facebook.flipper.ReactNativeFlipper
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at java.lang.Class.classForName(Native Method)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at java.lang.Class.forName(Class.java:309)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at java.lang.Class.forName(Class.java:273)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at com.library_app2.MainApplication.initializeFlipper(MainApplication.java:61)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at com.library_app2.MainApplication.onCreate(MainApplication.java:46)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4735)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at android.app.ActivityThread.access$1600(ActivityThread.java:164)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1492)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at android.os.Looper.loop(Looper.java:159)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5473)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.flipper.ReactNativeFlipper" on path: DexPathList[[zip file "/data/app/com.library_app2-1/base.apk"],nativeLibraryDirectories=[/data/app/com.library_app2-1/lib/arm, /vendor/lib, /system/lib]]
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:   ... 16 more
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:   Suppressed: java.lang.ClassNotFoundException: com.facebook.flipper.ReactNativeFlipper
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at java.lang.Class.classForName(Native Method)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:       ... 17 more
11-24 07:03:40.388 26069-26069/com.library_app2 W/System.err:   Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
11-24 07:03:40.448 26069-26069/com.library_app2 W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: About to load: libjscexecutor.so
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: libjscexecutor.so found on /data/data/com.library_app2/lib-main
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: Loading lib dependencies: [libfb.so, libreactnativejni.so, libjsc.so, libjsinspector.so, libfolly_json.so, libglog.so, libc++_shared.so, liblog.so, libc.so, libm.so, libdl.so]
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: About to load: libfb.so
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: libfb.so found on /data/data/com.library_app2/lib-main
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: Loading lib dependencies: [libc++_shared.so, liblog.so, libdl.so, libandroid.so, libc.so, libm.so]
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: About to load: libc++_shared.so
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: libc++_shared.so found on /data/data/com.library_app2/lib-main
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: Loading lib dependencies: [libc.so, libdl.so]
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: About to load: libc.so
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: libc.so not found on /data/data/com.library_app2/lib-main
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: libc.so not found on /data/app/com.library_app2-1/lib/arm
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: libc.so not found on /system/vendor/lib
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: libc.so found on /system/lib
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: libc.so loaded implicitly
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: Loaded: libc.so
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: About to load: libdl.so
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: libdl.so not found on /data/data/com.library_app2/lib-main
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: libdl.so not found on /data/app/com.library_app2-1/lib/arm
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: libdl.so not found on /system/vendor/lib
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: libdl.so found on /system/lib
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: libdl.so loaded implicitly
11-24 07:03:40.488 26069-26069/com.library_app2 D/SoLoader: Loaded: libdl.so
11-24 07:03:40.488 26069-26069/com.library_app2 E/art: dlopen("/data/data/com.library_app2/lib-main/libc++_shared.so", RTLD_LAZY) failed: dlopen failed: "/data/data/com.library_app2/lib-main/libc++_shared.so" is 64-bit instead of 32-bit
11-24 07:03:40.488 26069-26069/com.library_app2 E/SoLoader: couldn't find DSO to load: libc++_shared.so caused by: dlopen failed: "/data/data/com.library_app2/lib-main/libc++_shared.so" is 64-bit instead of 32-bit
11-24 07:03:40.488 26069-26069/com.library_app2 E/SoLoader: couldn't find DSO to load: libfb.so caused by: couldn't find DSO to load: libc++_shared.so caused by: dlopen failed: "/data/data/com.library_app2/lib-main/libc++_shared.so" is 64-bit instead of 32-bit
11-24 07:03:40.488 26069-26069/com.library_app2 E/SoLoader: couldn't find DSO to load: libjscexecutor.so caused by: couldn't find DSO to load: libfb.so caused by: couldn't find DSO to load: libc++_shared.so caused by: dlopen failed: "/data/data/com.library_app2/lib-main/libc++_shared.so" is 64-bit instead of 32-bit
11-24 07:03:40.498 26069-26069/com.library_app2 D/ReactNative: ReactInstanceManager.ctor()
11-24 07:03:40.498 26069-26069/com.library_app2 D/SoLoader: init exiting
11-24 07:03:40.558 26069-26069/com.library_app2 D/ReactNative: ReactInstanceManager.createReactContextInBackground()
11-24 07:03:40.568 26069-26069/com.library_app2 D/ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
11-24 07:03:40.598 26069-26069/com.library_app2 I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
11-24 07:03:40.598 26069-26069/com.library_app2 I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
11-24 07:03:40.608 26069-26101/com.library_app2 W/unknown:InspectorPackagerConnection: Couldn't connect to packager, will silently retry
11-24 07:03:40.608 26069-26100/com.library_app2 W/unknown:ReconnectingWebSocket: Couldn't connect to "ws://localhost:8081/message?device=R7sf%20-%205.1.1%20-%20API%2022&app=com.library_app2&clientid=DevSupportManagerImpl", will silently retry
11-24 07:03:40.608 26069-26099/com.library_app2 W/unknown:ReactNative: The packager does not seem to be running as we got an IOException requesting its status: Failed to connect to localhost/127.0.0.1:8081
11-24 07:03:40.638 26069-26105/com.library_app2 D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
11-24 07:03:40.638 1022-2005/? V/WindowManager: Adding window Window{39362e65 u0 com.library_app2/com.library_app2.MainActivity} at 2 of 16 (before Window{3f5127c4 u0 Starting com.library_app2})
11-24 07:03:40.648 26069-26069/com.library_app2 D/ReactNative: ReactInstanceManager.recreateReactContextInBackgroundFromBundleLoader()
11-24 07:03:40.648 26069-26069/com.library_app2 D/ReactNative: ReactInstanceManager.recreateReactContextInBackground()
11-24 07:03:40.648 26069-26069/com.library_app2 D/ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
11-24 07:03:40.648 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.668 26069-26069/com.library_app2 W/unknown:ReactNative: Packager connection already open, nooping.
11-24 07:03:40.668 26069-26107/com.library_app2 D/SoLoader: About to load: libhermes.so
11-24 07:03:40.668 26069-26107/com.library_app2 D/SoLoader: libhermes.so not found on /data/data/com.library_app2/lib-main
11-24 07:03:40.668 26069-26107/com.library_app2 D/SoLoader: libhermes.so not found on /data/app/com.library_app2-1/lib/arm
11-24 07:03:40.668 26069-26107/com.library_app2 D/SoLoader: libhermes.so not found on /system/vendor/lib
11-24 07:03:40.668 26069-26107/com.library_app2 D/SoLoader: libhermes.so not found on /system/lib
11-24 07:03:40.668 26069-26107/com.library_app2 E/SoLoader: couldn't find DSO to load: libhermes.so
11-24 07:03:40.678 26069-26107/com.library_app2 E/AndroidRuntime: FATAL EXCEPTION: create_react_context
    Process: com.library_app2, PID: 26069
    java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so
        at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:738)
        at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:591)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:529)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484)
        at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20)
        at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java:27)
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:952)
        at java.lang.Thread.run(Thread.java:818)
11-24 07:03:40.678 1022-2704/? D/ActivityManager: addErrorToDropBox processName = com.library_app2
11-24 07:03:40.678 1022-2489/? V/WindowManager: Changing focus from null to Window{39362e65 u0 com.library_app2/com.library_app2.MainActivity} Callers=com.android.server.wm.WindowManagerService.relayoutWindow:3446 com.android.server.wm.Session.relayout:202 android.view.IWindowSession$Stub.onTransact:273 com.android.server.wm.Session.onTransact:130 
11-24 07:03:40.678 15968-15987/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.698 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.698 1022-2704/? W/ActivityManager:   Force finishing activity 1 com.library_app2/.MainActivity
11-24 07:03:40.698 26069-26105/com.library_app2 I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BR.1.1.3.C8.05.01.00.115.099_msm8916_64_refs/tags/AU_LINUX_ANDROID_LA.BR.1.1.3.C8.05.01.00.115.099__release_AU (Ib5665b357a)
    OpenGL ES Shader Compiler Version: E031.25.03.04
    Build Date: 11/13/15 Fri
    Local Branch: 
    Remote Branch: refs/tags/AU_LINUX_ANDROID_LA.BR.1.1.3.C8.05.01.00.115.099
    Local Patches: NONE
    Reconstruct Branch: NOTHING
11-24 07:03:40.708 15968-15988/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.708 1022-26108/? D/DropBoxManagerService: file :: /data/system/dropbox/data_app_crash@1574553820706.txt
11-24 07:03:40.708 26069-26105/com.library_app2 I/OpenGLRenderer: Initialized EGL, version 1.4
11-24 07:03:40.718 26069-26105/com.library_app2 D/OpenGLRenderer: Enabling debug mode 0
11-24 07:03:40.768 2531-2531/? W/ResourceType: For resource 0x7f0b001d, entry index(29) is beyond type entryCount(23)
11-24 07:03:40.778 1022-1051/? V/WindowManager: Changing focus from Window{39362e65 u0 com.library_app2/com.library_app2.MainActivity} to Window{17b4c51d u0 Application Error: com.library_app2} Callers=com.android.server.wm.WindowManagerService.addWindow:2696 com.android.server.wm.Session.addToDisplay:173 android.view.ViewRootImpl.setView:612 android.view.WindowManagerGlobal.addView:300 
11-24 07:03:40.778 1022-1051/? W/ActivityManager:  Dismiss app error dialog : com.library_app2
11-24 07:03:40.798 15968-15988/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.808 15968-15987/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.818 1022-1040/? I/art: Background sticky concurrent mark sweep GC freed 144079(7MB) AllocSpace objects, 0(0B) LOS objects, 3% free, 134MB/138MB, paused 2.940ms total 108.195ms
11-24 07:03:40.818 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.818 1022-1051/? V/WindowManager: Changing focus from Window{17b4c51d u0 Application Error: com.library_app2} to null Callers=com.android.server.wm.WindowManagerService.removeWindowLocked:2866 com.android.server.wm.WindowManagerService.removeWindowLocked:2775 com.android.server.wm.WindowManagerService.removeWindow:2765 com.android.server.wm.Session.remove:192 
11-24 07:03:40.818 26069-26107/com.library_app2 V/Process: killProcess [26069] Callers=com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException:99 java.lang.ThreadGroup.uncaughtException:693 java.lang.ThreadGroup.uncaughtException:690 <bottom of call stack> 
11-24 07:03:40.818 26069-26107/com.library_app2 I/Process: Sending signal. PID: 26069 SIG: 9
11-24 07:03:40.818 298-298/? E/lowmemorykiller: Error writing /proc/26069/oom_score_adj; errno=22
11-24 07:03:40.828 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.838 15968-15988/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.868 15968-15988/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.868 15968-15987/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.878 1022-1042/? I/WindowState: WIN DEATH: Window{39362e65 u0 com.library_app2/com.library_app2.MainActivity}
11-24 07:03:40.878 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.878 1022-1984/? I/ActivityManager: Process com.library_app2 (pid 26069) has died
11-24 07:03:40.888 1022-1984/? D/ActivityManager: cleanUpApplicationRecordLocked app:ProcessRecord{3a5807bc 26069:com.library_app2/u0a343}, restarting:false, allowRestart:true, index:-1
11-24 07:03:40.888 1022-1984/? D/ActivityManager: cleanUpApplicationRecordLocked from:com.android.server.am.ActivityManagerService.handleAppDiedLocked:4985 com.android.server.am.ActivityManagerService.appDiedLocked:5164 com.android.server.am.ActivityManagerService$AppDeathRecipient.binderDied:1373 android.os.BinderProxy.sendDeathNotice:551 
11-24 07:03:40.888 1022-1984/? D/ActivityManager: cleanUpApplicationRecordLocked:goodbye proc com.library_app2
11-24 07:03:40.888 1022-1984/? D/ActivityManager: resumeTopActivityLocked: set keepResume to true.
11-24 07:03:40.888 15968-15988/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.898 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.908 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.918 1022-2005/? V/WindowManager: Changing focus from null to Window{1786b351 u0 com.oppo.launcher/com.oppo.launcher.Launcher} Callers=com.android.server.wm.WindowManagerService.relayoutWindow:3446 com.android.server.wm.Session.relayout:202 android.view.IWindowSession$Stub.onTransact:273 com.android.server.wm.Session.onTransact:130 
11-24 07:03:40.918 15968-15988/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.918 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.928 1022-2721/? W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 26069 uid 10343
11-24 07:03:40.938 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.938 15968-15987/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.948 15968-15987/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.948 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.948 15968-15987/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.968 15968-15999/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:40.968 15968-15987/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:41.378 567-567/? I/MSM-irqbalance: Decided to move IRQ215 from CPU4 to CPU5
11-24 07:03:41.408 15968-15987/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:41.408 15968-15968/? D/KeyguardViewMediator: handleKeyguardVisibilityChanged mKeyguardViewManager = com.android.keyguard.KeyguardViewManager@12d66782
11-24 07:03:41.408 15968-15968/? D/KeyguardViewManager: handleKeyguardVisibilityChanged showing = true
11-24 07:03:41.408 15968-15988/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:41.418 15968-15987/? D/KeyguardViewMediator: setOccluded false
11-24 07:03:42.778 2531-2531/? W/InputConnectionWrapper.ICC: Timed out waiting on IInputContextCallback
11-24 07:03:42.798 2531-2531/? E/FullInputEventModel: onStartInput event aborted: dwa: could not obtain extracted text (class dwa)
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: >>>ANR MAY HAPPEN!!!<<<
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: >>>History msg List is:
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: History msg <1> { when=-2s24ms what=32 target=com.android.internal.os.HandlerCaller$MyHandler }, cost = 2024 ms
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: History msg <2> { when=0 what=45 target=com.android.internal.os.HandlerCaller$MyHandler arg1=1 }, cost = 0 ms
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: History msg <3> { when=0 what=45 target=com.android.internal.os.HandlerCaller$MyHandler }, cost = 0 ms
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: History msg <4> { when=-1ms what=20 target=com.android.internal.os.HandlerCaller$MyHandler }, cost = 1 ms
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: History msg <5> { when=-3ms what=40 target=com.android.internal.os.HandlerCaller$MyHandler }, cost = 3 ms
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: History msg <6> { when=-1ms what=30 target=com.android.internal.os.HandlerCaller$MyHandler }, cost = 0 ms
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: History msg <7> { when=0 what=110 target=com.android.internal.os.HandlerCaller$MyHandler }, cost = 0 ms
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: History msg <8> { when=-21ms what=32 target=com.android.internal.os.HandlerCaller$MyHandler }, cost = 21 ms
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: History msg <9> { when=0 what=45 target=com.android.internal.os.HandlerCaller$MyHandler arg1=1 }, cost = 0 ms
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: History msg <10> { when=0 what=45 target=com.android.internal.os.HandlerCaller$MyHandler }, cost = 0 ms
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: >>>HISTORY MSG DUMP OVER<<<
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: >>>Current msg List is:
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: Current msg <1>  = { when=-1s923ms what=110 target=com.android.internal.os.HandlerCaller$MyHandler }
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: Current msg <2>  = { when=-1s858ms what=30 target=com.android.internal.os.HandlerCaller$MyHandler }
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: Current msg <3>  = { when=-1s857ms what=20 target=com.android.internal.os.HandlerCaller$MyHandler obj=InputBinding{android.os.BinderProxy@39230931 / uid 10059 / pid 2779} }
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: Current msg <4>  = { when=-1s857ms what=45 target=com.android.internal.os.HandlerCaller$MyHandler arg1=1 obj=android.inputmethodservice.InputMethodService$InputMethodSessionImpl@3cbe03e4 }
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: Current msg <5>  = { when=-1s857ms what=32 target=com.android.internal.os.HandlerCaller$MyHandler obj=com.android.internal.os.SomeArgs@f70eec3 }
11-24 07:03:42.798 2531-2531/? D/ANR_LOG: >>>CURRENT MSG DUMP OVER<<<
11-24 07:03:42.798 2531-2531/? W/ResourceType: For resource 0x7f0b001d, entry index(29) is beyond type entryCount(23)
11-24 07:03:43.218 2007-2007/? E/PhoneStatusBar: updateNotificationTitleText  preIsInsidePanelCanSlide =true,misInsidePanelCanSlide = true,misInsidePanelOpen = false

I have trying to figure out this few days, but no luck.

Please, any helps would be very appreciated.

Answer

I resolved this by added this line to: myProjectName/android/app/build.gradle

configurations.all {
     resolutionStrategy {
       force "com.facebook.soloader:soloader:0.8.0"
     }
}

I hope that information will be helpful for someone who also facing this issue in the future.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..