App crashes - E/AndroidRuntime: FATAL EXCEPTION: main


#1

I’m getting an error with my code and I’m not sure what is causing it. I’ve tried looking online but I can’t find anything that is of relevance.

It’s failing at this line
detector = new CameraDetector(this, CameraDetector.CameraType.CAMERA_FRONT, cameraPreview);

Error displayed:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.m_ars, PID: 10882
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/com.example.m_ars-r9JRJ-tsi4pPtF3VAtk-7w==/base.apk”, zip file “/data/app/com.example.m_ars-r9JRJ-tsi4pPtF3VAtk-7w==/split_lib_dependencies_apk.apk”, zip file
at java.lang.Runtime.loadLibrary0(Runtime.java:1011)
at java.lang.System.loadLibrary(System.java:1657)
at com.affectiva.android.affdex.sdk.detector.AffdexFaceJNI.(SourceFile:20)
at com.affectiva.android.affdex.sdk.detector.AffdexFaceJNI$$InjectAdapter.get(SourceFile:27)
at com.affectiva.android.affdex.sdk.detector.AffdexFaceJNI$$InjectAdapter.get(SourceFile:14)
at com.affectiva.android.affdex.sdk.detector.AffdexFaceJNIWrapper$$InjectAdapter.get(SourceFile:52)
at com.affectiva.android.affdex.sdk.detector.AffdexFaceJNIWrapper$$InjectAdapter.get(SourceFile:19)
at com.affectiva.android.affdex.sdk.detector.FrameProcessor$$InjectAdapter.get(SourceFile:62)
at com.affectiva.android.affdex.sdk.detector.FrameProcessor$$InjectAdapter.get(SourceFile:23)
at com.affectiva.android.affdex.sdk.detector.CameraDetector$$InjectAdapter.injectMembers(SourceFile:71)
at com.affectiva.android.affdex.sdk.detector.CameraDetector$$InjectAdapter.injectMembers(SourceFile:22)
at dagger.ObjectGraph$DaggerObjectGraph.inject(ObjectGraph.java:281)
at com.affectiva.android.affdex.sdk.detector.Detector.(SourceFile:69)
at com.affectiva.android.affdex.sdk.detector.CameraDetector.(SourceFile:72)
at com.affectiva.android.affdex.sdk.detector.CameraDetector.(SourceFile:111)
at com.example.m_ars.DefaultInfoActivity.onCreate(DefaultInfoActivity.java:113)
at android.app.Activity.performCreate(Activity.java:7183)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Log cat error:
2019-02-26 14:47:55.554 12047-12047/? E/Zygote: isWhitelistProcess - Process is Whitelisted
2019-02-26 14:47:55.555 12047-12047/? E/libpersona: scanKnoxPersonas
2019-02-26 14:47:55.555 12047-12047/? E/libpersona: Couldn’t open the File - /data/system/users/0/personalist.xml - No such file or directory

Thanks.


#2

It looks like our JNI code is failing to load our native library. Check that libaffdexface_jni.so is present in the APK’s lib/armeabi-v7a directory.


#3

Hi Andy,
Thanks for the reply, however, I don’t see anything inside the library folders in my project. I’ve attached a photo below
I’m using Android Studio 3.3.1

Thanks.


#4

I meant inside your APK. Open up the APK with a tool that understands zip files, and inside the APK, there should be a lib/armeabi-v7a directory, and in that directory there should be a libaffdexface_jni.so.


#5

Hi Andy,

The file is present

I think the issue is with the camera detector. The app I’m building features a qr code scanner and arcore. I’m not quite sure what is causing it as when I remove these activities it works perfectly fine as expected and the two combined work without any issues. The error occurs when I merge the three components.

Could there be an issue with the camera detector?


#6

Just saw this

I’ve attached the code below

package com.example.m_ars;

import android.Manifest;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.os.Vibrator;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.vision.CameraSource;
import com.google.android.gms.vision.Detector;
import com.google.android.gms.vision.barcode.Barcode;
import com.google.android.gms.vision.barcode.BarcodeDetector;

import java.io.IOException;

public class ScanActivity extends AppCompatActivity {

    SurfaceView surfaceView;
    CameraSource cameraSource;
    TextView textView;
    BarcodeDetector barcodeDetector;

    private int cameraPermissionCode = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scan);

        surfaceView = findViewById(R.id.camerapreview);
        textView = findViewById(R.id.scantext);

        //initialise barcode scanner - only accepts QR Codes
        barcodeDetector = new BarcodeDetector.Builder(this)
                .setBarcodeFormats(Barcode.QR_CODE)
                .build();
        if (!barcodeDetector.isOperational()) {
            Toast.makeText(getApplicationContext(), "Something went wrong, please try again", Toast.LENGTH_SHORT).show();
        }

        //initialise camera source
        cameraSource = new CameraSource.Builder(this, barcodeDetector)
                .setAutoFocusEnabled(true)
                .setFacing(CameraSource.CAMERA_FACING_BACK)
                .setRequestedFps(20)
                .setRequestedPreviewSize(640, 480)
                .build();

        surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
            @Override
            public void surfaceCreated(SurfaceHolder holder) {
                if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                    requestCameraPermission();
                    return;
                }
                try {
                    cameraSource.start(holder);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

            }

            @Override
            public void surfaceDestroyed(SurfaceHolder holder) {
                cameraSource.stop();
            }
        });

        barcodeDetector.setProcessor(new Detector.Processor<Barcode>() {
            @Override
            public void release() {

            }

            @Override
            public void receiveDetections(final Detector.Detections<Barcode> detections) {



                //after QR code is scanned - get the data
                final SparseArray<Barcode> qrcodes = detections.getDetectedItems();

                if(qrcodes.size() != 0) {
                    textView.post(new Runnable() {
                        @Override
                        public void run() {
                            //artifact details after qr code has been scanned successfully
                            Intent intent = new Intent(ScanActivity.this, ARActivity.class);
                            intent.putExtra("code", qrcodes.valueAt(0).displayValue);
                            startActivity(intent);

                            Vibrator vibrator = (Vibrator)getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
                            vibrator.vibrate(1000);
//                            textView.setText(qrcodes.valueAt(0).displayValue);
                            cameraSource.stop();
                        }
                    });
//                } else {
//                    Toast.makeText(ScanActivity.this, "An error has occurred while scanning. Please try again", Toast.LENGTH_SHORT).show();
                }
            }
        });
    } //end of onCreate Method

    //method displays a dialog explaining why permission is needed
    private void requestCameraPermission() {
        if(ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)){
            new AlertDialog.Builder(this)
                    .setTitle("Permission needed")
                    .setMessage("Permission is needed because the application needs to access the camera to capture QR Codes")
                    .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ActivityCompat.requestPermissions(ScanActivity.this, new String[] {Manifest.permission.CAMERA}, cameraPermissionCode);
                        }
                    })
                    .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    })
                    .create().show();
        } else {
            ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.CAMERA}, cameraPermissionCode);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        if(requestCode == cameraPermissionCode) {
            if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                Toast.makeText(this, "Permission GRANTED", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(this, "Permission DENIED", Toast.LENGTH_SHORT).show();
            }
        }
    }

}

#7

CameraDetector does use a deprecated API, but I don’t think that’s the cause of your runtime problem. From the earlier screenshot you provided, I can see that your app supports arm64-v8a, but our current SDK does not support that ABI; only armeabi-v7a (you can see that libaffdexface_jni.so is not present in the arm64-v8a directory). So if you are running on a 64 bit device, that would explain why it is failing to load.


#8

Is there a way to disable the arm64-v8a directory or only target the armeabi-v7a directory or make it the primary library?


#9

I think you just need to eliminate those other ABI subfolders. This may be helpful: https://developer.android.com/ndk/guides/abis#gc


#10

Thanks for the help. I’ll check it out