Google Mobile Vision Library not loading

I am trying to embed the Google Mobile Vision TextRecogniser API in my application to read text from a given image. When I try to use this function, I get this error:

W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.dynamite not found. I/DynamiteModule: Considering local module com.google.android.gms.vision.dynamite:0 and remote module com.google.android.gms.vision.dynamite:801 I/DynamiteModule: Selected remote version of com.google.android.gms.vision.dynamite, version >= 801 W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/00000005/n/arm64-v8a D/ApplicationLoaders: ignored Vulkan layer search path /data/app/com.google.android.gms-1/lib/arm64:/system/fake-libs64:/data/app/com.google.android.gms-1/base.apk!/lib/arm64-v8a for namespace 0x7a2e8c60f0 I/Vision: Loading libocr library I/Vision: libocr load status: false I/TextRecognizerCreatorImpl: Requesting download for native text recognizer W/TextNativeHandle: Native handle not yet available. Reverting to no-op handle. 

Meaning, I believe that the library was not downloaded to the phone.

I have troubleshooting for common sources of errors, including lack of internet connection, out of memory, lack of dependencies, rebooting the phone, updating Google Play services, waiting for time, etc. Google repository and Play services are also updated in the studio Android.

However, I still get the same error, even when trying my application on different devices.

+8
source share
7 answers

I believe that the download is done using the Google Play Service application. Libraries are loaded as a zip file in a folder

 /data/data/com.google.android.gms/cache/downloadservice 

and retrieved in

  /data/data/com.google.android.gms/files/com.google.android.gms.vision 

and our application always checks the library in transit

  06-02 22:43:53.379 30258-30419/pzy64.searchbot I/Vision: Loading library libocr.so 

which shows an error if files are missing

  06-02 22:43:53.475 30258-30419/pzy64.searchbot I/Vision: libocr.so library load status: false 

otherwise

  06-03 09:42:33.372 23451-24679/pzy64.searchbot I/Vision: libocr.so library load status: true 

After loading, in my case (ARM) folder size

  /data/data/com.google.android.gms/files/com.google.android.gms.vision 

is about 5 MB. (Thus, the downloaded file is smaller than this size. The size may vary for different architectures. It took more time (x86) to load on my Asus phone).

See my Logcat - (filter using 'Vision').

 06-02 22:45:45.489 14970-31705/? I/Vision: Registration status ocr_armeabi_v7a.zip: The download is in progress. 06-02 22:45:45.542 14970-31705/? I/Vision: Download status ocr_armeabi_v7a.zip: The download is in progress. 06-02 22:43:53.379 30258-30419/pzy64.searchbot I/Vision: Loading library libocr.so 06-02 22:43:53.387 30258-30419/pzy64.searchbot I/Vision: libocr.so library load status: false 06-02 22:43:53.410 30258-30419/pzy64.searchbot I/Vision: Loading library libocr.so 06-02 22:43:53.411 30258-30419/pzy64.searchbot I/Vision: libocr.so library load status: false 06-02 22:43:53.475 30258-30419/pzy64.searchbot I/Vision: Loading library libocr.so 06-02 22:43:53.475 30258-30419/pzy64.searchbot I/Vision: libocr.so library load status: false ................... .............. ................... .............. 06-02 22:51:08.364 14970-3424/? I/Vision: Finished download ocr_armeabi_v7a.zip 06-02 22:51:08.421 14970-3424/? I/Vision: Unzipping /data/data/com.google.android.gms/cache/downloadservice/ocr_armeabi_v7a.zip to /data/data/com.google.android.gms/files/com.google.android.gms.vision/ocr 06-02 22:51:08.645 14970-3424/? I/Vision: Time to download ocr: 436558 06-02 22:51:09.142 3303-3489/pzy64.searchbot I/Vision: Loading library libocr.so 06-02 22:51:09.149 3303-3489/pzy64.searchbot I/Vision: libocr.so library load status: true 06-02 22:51:09.149 3303-3489/pzy64.searchbot I/Vision: Reading ocr models from /data/data/com.google.android.gms/files/com.google.android.gms.vision/ocr/data/models 

The application I'm working on

+5
source

I am doing a “Clear Data” application on the Google Play Apps app and it works!

+5
source

I think you missed adding the meta-data tag in the manifest file of your application. This metadata tag tells your application to download and integrate the library into your application. Try adding the metadata tag to your application tag above the activity tag in the manifest file. See below:

 <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> <meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="barcode"/> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 

This may solve your problem.

+2
source

after some testing, I realized that in the gradle file you should also add these lines:

 compile 'com.android.support:support-v4:24+' compile 'com.android.support:design:24+' 

So besides this

compile 'com.google.android.gms:play-services-vision:10.2.1' other two lines are also important.

+2
source

I don’t know if I was late, but guys, after several hours of testing, the problem was resolved for me using the Google Play Services Update to version (12.6.85) . I restarted the device and guess what? The application worked fine. To update this Google Play service these instructions .

+2
source

Have you included <uses-permission android:name="android.permission.INTERNET" /> ?

0
source

try this, its work for me.

build.gradle

 apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25" defaultConfig { applicationId "com.truiton.mobile.vision.ocr" minSdkVersion 15 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.0.0' testCompile 'junit:junit:4.12' compile 'com.google.android.gms:play-services-vision:9.8.0' compile 'com.android.support.constraint:constraint-layout:1.0.0-beta3' } 

activity_main.xml

 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout android:id="@+id/activity_main" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.truiton.mobile.vision.ocr.MainActivity"> <ImageView android:id="@+id/imageView" android:layout_width="200dp" android:layout_height="200dp" android:layout_marginTop="16dp" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@mipmap/truiton" tools:layout_constraintLeft_creator="1" tools:layout_constraintRight_creator="1"/> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:text="Scan Text" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" tools:layout_constraintLeft_creator="1" tools:layout_constraintRight_creator="1" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="40dp" android:text="Scan Results:" android:textAllCaps="false" android:textStyle="normal|bold" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/imageView" tools:layout_constraintLeft_creator="1" tools:layout_constraintRight_creator="1"/> <ScrollView android:layout_width="0dp" android:layout_height="0dp" android:layout_marginTop="8dp" android:paddingLeft="5dp" android:paddingRight="5dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_bias="1.0" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/textView" tools:layout_constraintTop_creator="1" tools:layout_constraintRight_creator="1" tools:layout_constraintBottom_creator="1" tools:layout_constraintLeft_creator="1"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/results" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="8dp" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" tools:layout_constraintLeft_creator="1" tools:layout_constraintRight_creator="1" tools:layout_constraintTop_creator="1"/> </LinearLayout> </ScrollView> </android.support.constraint.ConstraintLayout> 

AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?> <manifest package="com.truiton.mobile.vision.ocr" xmlns:android="http://schemas.android.com/apk/res/android"> <uses-feature android:name="android.hardware.camera" android:required="true"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="ocr"/> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest> 

MainActivity.java

 public class MainActivity extends AppCompatActivity { private static final String LOG_TAG = "Text API"; private static final int PHOTO_REQUEST = 10; private TextView scanResults; private Uri imageUri; private TextRecognizer detector; private static final int REQUEST_WRITE_PERMISSION = 20; private static final String SAVED_INSTANCE_URI = "uri"; private static final String SAVED_INSTANCE_RESULT = "result"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.button); scanResults = (TextView) findViewById(R.id.results); if (savedInstanceState != null) { imageUri = Uri.parse(savedInstanceState.getString(SAVED_INSTANCE_URI)); scanResults.setText(savedInstanceState.getString(SAVED_INSTANCE_RESULT)); } detector = new TextRecognizer.Builder(getApplicationContext()).build(); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_WRITE_PERMISSION); } }); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case REQUEST_WRITE_PERMISSION: if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { takePicture(); } else { Toast.makeText(MainActivity.this, "Permission Denied!", Toast.LENGTH_SHORT).show(); } } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PHOTO_REQUEST && resultCode == RESULT_OK) { launchMediaScanIntent(); try { Bitmap bitmap = decodeBitmapUri(this, imageUri); if (detector.isOperational() && bitmap != null) { Frame frame = new Frame.Builder().setBitmap(bitmap).build(); SparseArray<TextBlock> textBlocks = detector.detect(frame); String blocks = ""; String lines = ""; String words = ""; for (int index = 0; index < textBlocks.size(); index++) { //extract scanned text blocks here TextBlock tBlock = textBlocks.valueAt(index); blocks = blocks + tBlock.getValue() + "\n" + "\n"; for (Text line : tBlock.getComponents()) { //extract scanned text lines here lines = lines + line.getValue() + "\n"; for (Text element : line.getComponents()) { //extract scanned text words here words = words + element.getValue() + ", "; } } } if (textBlocks.size() == 0) { scanResults.setText("Scan Failed: Found nothing to scan"); } else { scanResults.setText(scanResults.getText() + "Blocks: " + "\n"); scanResults.setText(scanResults.getText() + blocks + "\n"); scanResults.setText(scanResults.getText() + "---------" + "\n"); scanResults.setText(scanResults.getText() + "Lines: " + "\n"); scanResults.setText(scanResults.getText() + lines + "\n"); scanResults.setText(scanResults.getText() + "---------" + "\n"); scanResults.setText(scanResults.getText() + "Words: " + "\n"); scanResults.setText(scanResults.getText() + words + "\n"); scanResults.setText(scanResults.getText() + "---------" + "\n"); } } else { scanResults.setText("Could not set up the detector!"); } } catch (Exception e) { Toast.makeText(this, "Failed to load Image", Toast.LENGTH_SHORT) .show(); Log.e(LOG_TAG, e.toString()); } } } private void takePicture() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File photo = new File(Environment.getExternalStorageDirectory(), "picture.jpg"); imageUri = Uri.fromFile(photo); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); startActivityForResult(intent, PHOTO_REQUEST); } @Override protected void onSaveInstanceState(Bundle outState) { if (imageUri != null) { outState.putString(SAVED_INSTANCE_URI, imageUri.toString()); outState.putString(SAVED_INSTANCE_RESULT, scanResults.getText().toString()); } super.onSaveInstanceState(outState); } private void launchMediaScanIntent() { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); mediaScanIntent.setData(imageUri); this.sendBroadcast(mediaScanIntent); } private Bitmap decodeBitmapUri(Context ctx, Uri uri) throws FileNotFoundException { int targetW = 600; int targetH = 600; BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeStream(ctx.getContentResolver().openInputStream(uri), null, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; int scaleFactor = Math.min(photoW / targetW, photoH / targetH); bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; return BitmapFactory.decodeStream(ctx.getContentResolver() .openInputStream(uri), null, bmOptions); } } 
-1
source

Source: https://habr.com/ru/post/1265094/


All Articles