Error compiling my application flutter application on a huawei p40 lite without google services

Viewed 875

I have this error compiling my flutter application, I am using a huawei p40 lite (without google services) to reproduce this error. On devices with google services it works perfectly.

E/AndroidRuntime(29459): FATAL EXCEPTION: main                          
E/AndroidRuntime(29459): Process: com.google.android.gms.persistent, PID: 29459
E/AndroidRuntime(29459): java.lang.RuntimeException: Unable to create service com.google.android.location.internal.GoogleLocationManagerService: java.lang.SecurityException: Failed to find provider com.google.settings for 
user 0; expected to find a valid ContentProvider for this authority
E/AndroidRuntime(29459):        at android.app.ActivityThread.handleCreateService(ActivityThread.java:4650)
E/AndroidRuntime(29459):        at android.app.ActivityThread.access$2800(ActivityThread.java:308)
E/AndroidRuntime(29459):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2330)
E/AndroidRuntime(29459):        at android.os.Handler.dispatchMessage(Handler.java:110)
E/AndroidRuntime(29459):        at android.os.Looper.loop(Looper.java:219)
E/AndroidRuntime(29459):        at android.app.ActivityThread.main(ActivityThread.java:8349)
E/AndroidRuntime(29459):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(29459):        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
E/AndroidRuntime(29459):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
E/AndroidRuntime(29459): Caused by: java.lang.SecurityException: Failed to find provider com.google.settings for user 0; expected to find a valid ContentProvider for this authority
E/AndroidRuntime(29459):        at android.os.Parcel.createException(Parcel.java:2071)
E/AndroidRuntime(29459):        at android.os.Parcel.readException(Parcel.java:2039)
E/AndroidRuntime(29459):        at android.os.Parcel.readException(Parcel.java:1987)
E/AndroidRuntime(29459):        at android.content.IContentService$Stub$Proxy.registerContentObserver(IContentService.java:1234)
E/AndroidRuntime(29459):        at android.content.ContentResolver.registerContentObserver(ContentResolver.java:2301)
E/AndroidRuntime(29459):        at android.content.ContentResolver.registerContentObserver(ContentResolver.java:2289)
E/AndroidRuntime(29459):        at azlm.<init>(:com.google.android.gms@19420000@19.4.20 (000300-271418971):17)
E/AndroidRuntime(29459):        at aznh.<init>(:com.google.android.gms@19420000@19.4.20 (000300-271418971):1)
E/AndroidRuntime(29459):        at com.google.android.location.internal.GoogleLocationManagerChimeraService.onCreate(:com.google.android.gms@19420000@19.4.20 (000300-271418971):6)
E/AndroidRuntime(29459):        at ebp.onCreate(:com.google.android.gms@19420000@19.4.20 (000300-271418971):1)
E/AndroidRuntime(29459):        at msb.onCreate(:com.google.android.gms@19420000@19.4.20 (000300-271418971):4)
E/AndroidRuntime(29459):        at android.app.ActivityThread.handleCreateService(ActivityThread.java:4636)
E/AndroidRuntime(29459):        ... 8 more

New huawei devices no longer come with google services, does anyone know how I can correct this problem?.

1 Answers

Your app has integrated GMS . As new Huawei phones are banned from using GMS, you app will be unable to run on new Huawei phones. If you want your app to run on these phones, integrate Huawei Mobile Services (HMS).

Huawei provides Flutter plug-ins for you to integrate HMS Core kits. Currently, Flutter plug-ins are available for Account Kit, Ads Kit, Analytics Kit, AR Kit, In-App Purchases, Location Kit, Map Kit, Push Kit, Scan Kit and Site Kit. You can download them on GitHub.


Take Flutter Location Plugin as an example, if you need to integrate it:

  1. Install HMS Core (APK)

To use HUAWEI Location Kit, you need to download and install HMS Core (APK) 4.0.1.300 or later on your device.

  1. Install the Android SDK
  2. Configure App Information in AppGallery Connect

Including creating an app, generating a signing certificate fingerprint, generating a signature file, obtaining the SHA-256 fingerprint from signature file, configuring the signing certificate fingerprint, enabling required services.

  1. Configure Your Flutter Project

a. Sign in to AppGallery Connect, select My projects, and click the desired app name.

b. Go to Project Setting > General information. In the App information field, click agconnect-services.json to download the configuration file.

c. Run the following command and make sure that no errors are reported.

1.  [project_path]> flutter doctor

d. Copy the agconnect-services.json file to the android/app directory of your Flutter project.

e. Copy the generated signature file to the android/app directory of your Flutter project.

f. Verify that the agconnect-services.json file and signature file are successfully added to the android/app directory of your Flutter project.

g. Open the build.gradle file in the android directory of your Flutter project.

  • Go to buildscript, and configure the Maven repository address and AppGallery Connect plugin for the HMS Core SDK
buildscript {    
    repositories {        
        google()        
        jcenter()        
        maven { url 'https://developer.huawei.com/repo/' }
    }    
    dependencies {        
        /*          
         * <Other dependencies>
         */        
        classpath 'com.huawei.agconnect:agcp:1.4.1.300'
    }
}
  • Go to allprojects, and configure the Maven repository address for the HMS Core SDK
allprojects {    
    repositories {        
        google()        
        jcenter()        
        maven { url 'https://developer.huawei.com/repo/' }    
    }
}

h. Open the build.gradle file in the android/app directory of your Flutter project.

  • Add the apply plugin: 'com.huawei.agconnect' line after the apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle' line.
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.huawei.agconnect'
  • Set minSdkVersion to 19 or higher in android > defaultConfig.
defaultConfig {
    applicationId "<package_name>"
    minSdkVersion 19
    /*
     * <Other configurations>
     */
}
  • Configure the signature in android based on the signature file information.
android {    
   /*     
    * <Other configurations>     
    */    
   signingConfigs {       
       release {            
           storeFile file('<keystore_file>')            
           storePassword '<keystore_password>'            
           keyAlias '<key_alias>'            
           keyPassword '<key_password>'        
       }    
   }   
   buildTypes {        
       debug {            
           signingConfig signingConfigs.release        
       }       
       release {            
           signingConfig signingConfigs.release        
       }    
    }
}
  1. Integrate the Plugin

a. Download the Location Kit Flutter Plugin and decompress it.

b. Open the pubspec.yaml file in your Flutter project and add the plugin dependency to the dependencies section.

dependencies:    
    huawei_location:
        path: {library path}

c. Run following command to update the package information:

[project_path]> flutter pub get

d. Run the following command or click the run icon on the toolbar to start the app:

[project_path]> flutter run
  1. Configuration Obfuscation Scripts

Before building the APK, configure the obfuscation configuration file to prevent the HMS Core SDK from being obfuscated.

The obfuscation configuration file is proguard-rules.pro in Android Studio.

a. Open the obfuscation configuration file proguard-rules.pro in the app directory.

b. Add configurations to exclude the HMS Core SDK from obfuscation.

-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}
-repackageclasses
Related