Implementing the Huawei QR Scanner

HYPR SDK for Android

Mobile devices manufactured by Huawei require a custom scanner in order to successfully scan QR codes. The capability is integrated into HYPR SDK for Android, so you just need to make the build.gradle configuration changes described below in order to enable it from the top-level app.

Implementation

HYPR SDK for Android uses a device model check to determine if the HYPR-implemented Huawei QR Scanner should be used instead of the default Firebase scanner.

string manufacturer = android.os.Build.MANUFACTURER;
 manufacturer.toLowerCase().equals("huawei"); // if true, use the Huawei QR Scanner

Configuration Changes

πŸ“˜

Note

For additional information, see the Huawei documentation here.

Configure the Maven Repository Address for the Huawei Mobile Services (HMS) SDK

  1. Open the build.gradle file in the root directory of your Android Studio project.
  2. Under allprojects > repositories, configure the Maven repository address for the HMS SDK:
allprojects {
  repositories
  {
    google()
    jcenter()
    maven {
      url 'https://developer.huawei.com/repo/'
    }
  }
}
  1. Under buildscript > repositories, configure the Maven repository address for the HMS SDK:
buildscript {
  repositories {
    google()
    jcenter()
    maven {
      url 'https://developer.huawei.com/repo/'
    }
  }
}
  1. Under buildscript > dependencies, add the following dependency:
buildscript {
  dependencies {
    classpath 'com.huawei.agconnect:agcp:1.2.1.301'
  }
}

Add Build Dependencies

  1. Open the build.gradle file in the /app directory.
  2. Add the hms:scan dependency:
dependencies {
  implementation 'com.huawei.hms:scan:{version}'
}
  1. Add the AppGallery Connect plugin dependency to the file header:
apply plugin: 'com.huawei.agconnect'

Synchronize

Open the modified build.gradle file again and you’ll find a Sync Now link in the upper right corner of the page. Click Sync Now and wait until synchronization is complete. If an error occurs, check the network connection and the configurations in the build.gradle file.

Configure Obfuscation Scripts

Add configurations to exclude the HMS SDK from obfuscation:

-ignorewarnings
   -keepattributes *Annotation*
   -keepattributes Exceptions
   -keepattributes InnerClasses
   -keepattributes Signature
   -keepattributes SourceFile,LineNumberTable
   -keep class com.hianalytics.android.**{*;}
   -keep class com.huawei.**{*;}

Associated Error Codes

Error CodeCauseRecommended Resolution
114106Huawei barcode scanner failure.Internal SDK error. Check the logs for more details.