问题
Every call to scanner.process(image) is resulting in the onFailure call, with the following error:
Error:com.google.mlkit.common.MlKitException: Internal error has occurred when executing ML Kit tasks
Any further details or ideas as to why the task is failing? Presenting it with a barcode does not seem to change this behavior either.
This error is shown when using a Pixel 3a, but totally crashes a Nexus 5 with a SIGENV error. I've been building my code from snippets while reading through the overview
Entry point activity
package jp.oist.cameraxapp;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.core.Camera;
import androidx.camera.core.CameraSelector;
import androidx.camera.core.ImageAnalysis;
import androidx.camera.core.ImageCapture;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.Preview;
import androidx.camera.lifecycle.ProcessCameraProvider;
import androidx.camera.view.PreviewView;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.media.Image;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.mlkit.vision.barcode.Barcode;
import com.google.mlkit.vision.barcode.BarcodeScanner;
import com.google.mlkit.vision.barcode.BarcodeScannerOptions;
import com.google.mlkit.vision.barcode.BarcodeScanning;
import com.google.mlkit.vision.common.InputImage;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class MainActivity extends AppCompatActivity {
private static final int PERMISSION_REQUESTS = 1;
private ListenableFuture<ProcessCameraProvider> cameraProviderFuture;
private ExecutorService executor;
private static String TAG = "abcvlibCameraX";
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!allPermissionsGranted()) {
getRuntimePermissions();
}
setContentView(R.layout.activity_main);
executor = Executors.newSingleThreadExecutor();
PreviewView previewView = findViewById(R.id.previewView);
cameraProviderFuture = ProcessCameraProvider.getInstance(this);
cameraProviderFuture.addListener(() -> {
try {
// Camera provider is now guaranteed to be available
ProcessCameraProvider cameraProvider = cameraProviderFuture.get();
// Set up the view finder use case to display camera preview
Preview preview = new Preview.Builder().build();
// Choose the camera by requiring a lens facing
CameraSelector cameraSelector = new CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_FRONT)
.build();
// Connect the preview use case to the previewView
preview.setSurfaceProvider(
previewView.createSurfaceProvider());
// Set up the capture use case to allow users to take photos
ImageCapture imageCapture = new ImageCapture.Builder()
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
.build();
ImageAnalysis imageAnalysis =
new ImageAnalysis.Builder()
.build();
imageAnalysis.setAnalyzer(ContextCompat.getMainExecutor(this), new ImageAnalysis.Analyzer() {
private BarcodeScanner scanner = buildBarCodeScanner();
@Override
public void analyze(ImageProxy imageProxy) {
@SuppressLint("UnsafeExperimentalUsageError") Image mediaImage = imageProxy.getImage();
if (mediaImage != null) {
InputImage image =
InputImage.fromMediaImage(mediaImage, imageProxy.getImageInfo().getRotationDegrees());
// Pass image to an ML Kit Vision API
Task<List<Barcode>> result = scanner.process(image);
result.addOnSuccessListener(new OnSuccessListener<List<Barcode>>() {
@Override
public void onSuccess(List<Barcode> barcodes) {
// Task completed successfully
Log.i("CameraXApp3", "scanner task successful");
processBarCodes(barcodes);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// Task failed with an exception
Log.i("CameraXApp3", "scanner task failed. Error:" + e);
}
});
mediaImage.close();
imageProxy.close();
}
}
private BarcodeScanner buildBarCodeScanner() {
BarcodeScannerOptions options =
new BarcodeScannerOptions.Builder()
.setBarcodeFormats(
Barcode.FORMAT_QR_CODE)
.build();
return BarcodeScanning.getClient(options);
}
//
private void processBarCodes(List<Barcode> barcodes) {
for (Barcode barcode : barcodes) {
String rawValue = barcode.getRawValue();
int valueType = barcode.getValueType();
// See API reference for complete list of supported types
if (valueType == Barcode.TYPE_TEXT) {
toast(MainActivity.this, "Received Message:" + rawValue);
}
}
}
public void toast(final Context context, final String text) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(() -> Toast.makeText(context, text, Toast.LENGTH_LONG).show());
}
});
// Attach use cases to the camera with the same lifecycle owner
Camera camera = cameraProvider.bindToLifecycle(
((LifecycleOwner) this),
cameraSelector,
preview,
imageCapture,
imageAnalysis);
} catch (InterruptedException | ExecutionException e) {
// Currently no exceptions thrown. cameraProviderFuture.get() should
// not block since the listener is being called, so no need to
// handle InterruptedException.
}
}, ContextCompat.getMainExecutor(this));
}
private void getRuntimePermissions() {
List<String> allNeededPermissions = new ArrayList<>();
for (String permission : getRequiredPermissions()) {
if (!isPermissionGranted(this, permission)) {
allNeededPermissions.add(permission);
}
}
if (!allNeededPermissions.isEmpty()) {
ActivityCompat.requestPermissions(
this, allNeededPermissions.toArray(new String[0]), PERMISSION_REQUESTS);
}
}
private static boolean isPermissionGranted(Context context, String permission) {
if (ContextCompat.checkSelfPermission(context, permission)
== PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, "Permission granted: " + permission);
return true;
}
Log.i(TAG, "Permission NOT granted: " + permission);
return false;
}
private boolean allPermissionsGranted() {
for (String permission : getRequiredPermissions()) {
if (!isPermissionGranted(this, permission)) {
return false;
}
}
return true;
}
private String[] getRequiredPermissions() {
try {
PackageInfo info =
this.getPackageManager()
.getPackageInfo(this.getPackageName(), PackageManager.GET_PERMISSIONS);
String[] ps = info.requestedPermissions;
if (ps != null && ps.length > 0) {
return ps;
} else {
return new String[0];
}
} catch (Exception e) {
return new String[0];
}
}
}
App-level Gradle File
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "30.0.0"
defaultConfig {
applicationId "jp.oist.cameraxapp"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.camera:camera-camera2:1.0.0-beta07'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// CameraX core library using the camera2 implementation
def camerax_version = "1.0.0-beta07"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
implementation "androidx.camera:camera-view:1.0.0-alpha14"
implementation 'com.google.mlkit:barcode-scanning:16.0.2'
}
Full Logcat surrounding the error from stop to start of app:
2020-08-04 12:51:05.192 17716-17716/? I/oist.cameraxap: Late-enabling -Xcheck:jni
2020-08-04 12:51:05.224 17716-17716/? E/oist.cameraxap: Unknown bits set in runtime_flags: 0x8000
2020-08-04 12:51:05.596 17716-17716/jp.oist.cameraxapp I/abcvlibCameraX: Permission granted: android.permission.CAMERA
2020-08-04 12:51:05.647 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2020-08-04 12:51:05.648 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2020-08-04 12:51:05.699 17716-17751/jp.oist.cameraxapp I/CameraManagerGlobal: Connecting to camera service
2020-08-04 12:51:05.714 17716-17751/jp.oist.cameraxapp D/CameraRepository: Added camera: 0
2020-08-04 12:51:05.729 17716-17751/jp.oist.cameraxapp I/Camera2CameraInfo: Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_FULL
2020-08-04 12:51:05.732 17716-17751/jp.oist.cameraxapp D/CameraRepository: Added camera: 1
2020-08-04 12:51:05.734 17716-17752/jp.oist.cameraxapp D/UseCaseAttachState: Active and attached use case: [] for camera: 0
2020-08-04 12:51:05.735 17716-17751/jp.oist.cameraxapp I/Camera2CameraInfo: Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_FULL
2020-08-04 12:51:05.737 17716-17752/jp.oist.cameraxapp D/UseCaseAttachState: Active and attached use case: [] for camera: 1
2020-08-04 12:51:05.749 17716-17747/jp.oist.cameraxapp I/AdrenoGLES: QUALCOMM build : ba734b1, I0a3e8c4129
Build Date : 11/11/19
OpenGL ES Shader Compiler Version: EV031.27.05.02
Local Branch :
Remote Branch : refs/tags/AU_LINUX_ANDROID_LA.UM.7.8.9.C1.08.00.00.516.287
Remote Branch : NONE
Reconstruct Branch : NOTHING
2020-08-04 12:51:05.749 17716-17747/jp.oist.cameraxapp I/AdrenoGLES: Build Config : S P 8.0.11 AArch64
2020-08-04 12:51:05.752 17716-17747/jp.oist.cameraxapp I/AdrenoGLES: PFP: 0x016ee183, ME: 0x00000000
2020-08-04 12:51:05.765 17716-17747/jp.oist.cameraxapp W/Gralloc3: mapper 3.x is not supported
2020-08-04 12:51:05.844 17716-17755/jp.oist.cameraxapp I/DynamiteModule: Considering local module com.google.mlkit.dynamite.barcode:10000 and remote module com.google.mlkit.dynamite.barcode:0
2020-08-04 12:51:05.844 17716-17755/jp.oist.cameraxapp I/DynamiteModule: Selected local version of com.google.mlkit.dynamite.barcode
2020-08-04 12:51:05.851 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->objectFieldOffset(Ljava/lang/reflect/Field;)J (greylist,core-platform-api, linking, allowed)
2020-08-04 12:51:05.853 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)
2020-08-04 12:51:05.853 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
2020-08-04 12:51:05.853 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
2020-08-04 12:51:05.854 17716-17755/jp.oist.cameraxapp I/tflite: Initialized TensorFlow Lite runtime.
2020-08-04 12:51:05.855 17716-17755/jp.oist.cameraxapp I/native: barcode_detector_client.cc:238 Not using NNAPI
2020-08-04 12:51:05.857 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->allocateInstance(Ljava/lang/Class;)Ljava/lang/Object; (greylist, linking, allowed)
2020-08-04 12:51:05.857 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed)
2020-08-04 12:51:05.857 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->arrayBaseOffset(Ljava/lang/Class;)I (greylist,core-platform-api, linking, allowed)
2020-08-04 12:51:05.857 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->arrayIndexScale(Ljava/lang/Class;)I (greylist, linking, allowed)
2020-08-04 12:51:05.859 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Llibcore/io/Memory;->peekLong(JZ)J (greylist, reflection, allowed)
2020-08-04 12:51:05.859 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Llibcore/io/Memory;->pokeLong(JJZ)V (greylist, reflection, allowed)
2020-08-04 12:51:05.859 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Llibcore/io/Memory;->pokeInt(JIZ)V (greylist, reflection, allowed)
2020-08-04 12:51:05.859 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Llibcore/io/Memory;->peekInt(JZ)I (greylist, reflection, allowed)
2020-08-04 12:51:05.859 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Llibcore/io/Memory;->pokeByte(JB)V (greylist, reflection, allowed)
2020-08-04 12:51:05.859 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Llibcore/io/Memory;->peekByte(J)B (greylist, reflection, allowed)
2020-08-04 12:51:05.859 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Llibcore/io/Memory;->pokeByteArray(J[BII)V (greylist, reflection, allowed)
2020-08-04 12:51:05.859 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Llibcore/io/Memory;->peekByteArray(J[BII)V (greylist, reflection, allowed)
2020-08-04 12:51:05.859 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2020-08-04 12:51:05.859 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
2020-08-04 12:51:05.859 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, reflection, allowed)
2020-08-04 12:51:05.860 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden field Ljava/nio/Buffer;->address:J (greylist, reflection, allowed)
2020-08-04 12:51:05.860 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, reflection, allowed)
2020-08-04 12:51:05.860 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, reflection, allowed)
2020-08-04 12:51:05.860 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, reflection, allowed)
2020-08-04 12:51:05.860 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, reflection, allowed)
2020-08-04 12:51:05.860 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, reflection, allowed)
2020-08-04 12:51:05.860 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, reflection, allowed)
2020-08-04 12:51:05.870 17716-17754/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)
2020-08-04 12:51:05.870 17716-17754/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed)
2020-08-04 12:51:05.870 17716-17754/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2020-08-04 12:51:05.947 17716-17751/jp.oist.cameraxapp D/UseCaseAttachState: Active and attached use case: [] for camera: 1
2020-08-04 12:51:05.951 17716-17752/jp.oist.cameraxapp D/UseCaseAttachState: Active and attached use case: [] for camera: 1
2020-08-04 12:51:05.955 17716-17751/jp.oist.cameraxapp D/UseCaseAttachState: Active and attached use case: [] for camera: 1
2020-08-04 12:51:05.955 17716-17751/jp.oist.cameraxapp I/chatty: uid=10124(jp.oist.cameraxapp) CameraX-core_ca identical 1 line
2020-08-04 12:51:05.955 17716-17751/jp.oist.cameraxapp D/UseCaseAttachState: Active and attached use case: [] for camera: 1
2020-08-04 12:51:05.956 17716-17751/jp.oist.cameraxapp D/UseCaseAttachState: All use case: [androidx.camera.core.Preview-7f499a18-73ff-41cb-9217-2d0fe0b6345c255079241, androidx.camera.core.ImageAnalysis-22cf2c3d-6cbe-447a-9fa4-192f608ff6d5223414639, androidx.camera.core.ImageCapture-041129af-ca2e-48a7-85f5-0fa752f78a4172369230] for camera: 1
2020-08-04 12:51:05.957 17716-17751/jp.oist.cameraxapp D/UseCaseAttachState: Active and attached use case: [androidx.camera.core.Preview-7f499a18-73ff-41cb-9217-2d0fe0b6345c255079241, androidx.camera.core.ImageAnalysis-22cf2c3d-6cbe-447a-9fa4-192f608ff6d5223414639, androidx.camera.core.ImageCapture-041129af-ca2e-48a7-85f5-0fa752f78a4172369230] for camera: 1
2020-08-04 12:51:05.959 17716-17751/jp.oist.cameraxapp D/UseCaseAttachState: All use case: [androidx.camera.core.Preview-7f499a18-73ff-41cb-9217-2d0fe0b6345c255079241, androidx.camera.core.ImageAnalysis-22cf2c3d-6cbe-447a-9fa4-192f608ff6d5223414639, androidx.camera.core.ImageCapture-041129af-ca2e-48a7-85f5-0fa752f78a4172369230] for camera: 1
2020-08-04 12:51:05.964 17716-17716/jp.oist.cameraxapp D/PreviewView: Surface requested by Preview.
2020-08-04 12:51:05.977 17716-17751/jp.oist.cameraxapp D/UseCaseAttachState: All use case: [androidx.camera.core.Preview-7f499a18-73ff-41cb-9217-2d0fe0b6345c255079241, androidx.camera.core.ImageAnalysis-22cf2c3d-6cbe-447a-9fa4-192f608ff6d5223414639, androidx.camera.core.ImageCapture-041129af-ca2e-48a7-85f5-0fa752f78a4172369230] for camera: 1
2020-08-04 12:51:05.992 17716-17716/jp.oist.cameraxapp D/SurfaceViewImpl: Surface created.
2020-08-04 12:51:05.992 17716-17716/jp.oist.cameraxapp D/SurfaceViewImpl: Surface changed. Size: 1600x1200
2020-08-04 12:51:05.994 17716-17716/jp.oist.cameraxapp D/SurfaceViewImpl: Surface set on Preview.
2020-08-04 12:51:05.997 17716-17752/jp.oist.cameraxapp D/CaptureSession: Opening capture session.
2020-08-04 12:51:06.149 17716-17752/jp.oist.cameraxapp D/CaptureSession: Attempting to send capture request onConfigured
2020-08-04 12:51:06.149 17716-17752/jp.oist.cameraxapp D/CaptureSession: Issuing request for session.
2020-08-04 12:51:06.153 17716-17752/jp.oist.cameraxapp D/CaptureSession: CameraCaptureSession.onConfigured() mState=OPENED
2020-08-04 12:51:06.154 17716-17752/jp.oist.cameraxapp D/CaptureSession: CameraCaptureSession.onReady() OPENED
2020-08-04 12:51:06.154 17716-17739/jp.oist.cameraxapp W/Gralloc3: allocator 3.x is not supported
2020-08-04 12:51:06.320 17716-17752/jp.oist.cameraxapp D/StreamStateObserver: Update Preview stream state to STREAMING
2020-08-04 12:51:06.359 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)
2020-08-04 12:51:06.359 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
2020-08-04 12:51:06.359 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
2020-08-04 12:51:06.363 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed)
2020-08-04 12:51:06.365 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Llibcore/io/Memory;->pokeByte(JB)V (greylist, reflection, allowed)
2020-08-04 12:51:06.365 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Llibcore/io/Memory;->peekByte(J)B (greylist, reflection, allowed)
2020-08-04 12:51:06.365 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2020-08-04 12:51:06.365 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
2020-08-04 12:51:06.365 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, reflection, allowed)
2020-08-04 12:51:06.365 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, reflection, allowed)
2020-08-04 12:51:06.365 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, reflection, allowed)
2020-08-04 12:51:06.365 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, reflection, allowed)
2020-08-04 12:51:06.365 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, reflection, allowed)
2020-08-04 12:51:06.365 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, reflection, allowed)
2020-08-04 12:51:06.365 17716-17716/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, reflection, allowed)
2020-08-04 12:51:06.369 17716-17716/jp.oist.cameraxapp I/CameraXApp3: scanner task failed. Error:com.google.mlkit.common.MlKitException: Internal error has occurred when executing ML Kit tasks
2020-08-04 12:51:06.373 17716-17754/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2020-08-04 12:51:06.373 17716-17716/jp.oist.cameraxapp I/CameraXApp3: scanner task failed. Error:com.google.mlkit.common.MlKitException: Internal error has occurred when executing ML Kit tasks
2020-08-04 12:51:06.376 17716-17754/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)
2020-08-04 12:51:06.376 17716-17754/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
2020-08-04 12:51:06.377 17716-17754/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
2020-08-04 12:51:06.378 17716-17754/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)
2020-08-04 12:51:06.378 17716-17754/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
2020-08-04 12:51:06.379 17716-17754/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
2020-08-04 12:51:06.379 17716-17754/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
2020-08-04 12:51:06.379 17716-17754/jp.oist.cameraxapp W/oist.cameraxap: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2020-08-04 12:51:06.406 17716-17716/jp.oist.cameraxapp I/CameraXApp3: scanner task failed. Error:com.google.mlkit.common.MlKitException: Internal error has occurred when executing ML Kit tasks
2020-08-04 12:51:07.309 17716-17716/jp.oist.cameraxapp I/chatty: uid=10124(jp.oist.cameraxapp) identical 27 lines
回答1:
Inadvertently found the cause of the error by reading this. Adding an OnCompleteListener to the result Task and placing the imageProxy.close() inside, resolved this. i.e.:
Errors
Task<List<Barcode>> result = scanner.process(image);
result.addOnSuccessListener(new OnSuccessListener<List<Barcode>>() {
@Override
public void onSuccess(List<Barcode> barcodes) {
// Task completed successfully
Log.i("CameraXApp3", "scanner task successful");
processBarCodes(barcodes);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// Task failed with an exception
Log.i("CameraXApp3", "scanner task failed. Error:" + e);
}
});
mediaImage.close();
imageProxy.close();
No Errors
Task<List<Barcode>> result = scanner.process(image);
result.addOnSuccessListener(new OnSuccessListener<List<Barcode>>() {
@Override
public void onSuccess(List<Barcode> barcodes) {
// Task completed successfully
Log.i("CameraXApp3", "scanner task successful");
processBarCodes(barcodes);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// Task failed with an exception
Log.i("CameraXApp3", "scanner task failed. Error:" + e);
}
}).addOnCompleteListener(new OnCompleteListener<List<Barcode>>() {
@Override
public void onComplete(@NonNull Task<List<Barcode>> task) {
mediaImage.close();
imageProxy.close();
}
});
Will wait to mark as answer in case @Hoi wants to grab the points, which he deserves. :)
来源:https://stackoverflow.com/questions/63240081/mlkit-barcode-sanner-implementation-results-in-internal-error-when-executing-ml