When developing the flutter plugin, Huawei obtained that the appId is empty, and the configuration file .json file should not be read

Viewed 651

In the development of the flutter plugin,

I ca n't get the appId. I put the configuration file .json in the java module and example app directories, and the appId cannot be obtained. How can I solve it?

I encapsulated the sdk into the plugin and reported an error: appId is empty

getToken failed, com.huawei.hms.common.ApiException: 907135000: arguments invalid

2 Answers

Please try the following steps 1. Place the json file in the assets directory of the Android layer. If not, create a new one and add the following code in AndroidManifest.xml and Application:

<application

android:name=".MyApplication"

…

>

…

public class MyApplication extends Application{

@Override

public void onCreate() {

   super.onCreate();

}

// TODO: Add the following code:

@Override

protected void attachBaseContext(Context context) {

   super.attachBaseContext(context);

   AGConnectServicesConfig config = AGConnectServicesConfig.fromContext(context);

   config.overlayWith(new LazyInputStream(context) {

       public InputStream get(Context context) {

           try {

               return context.getAssets().open("agconnect-services.json");

           } catch (IOException e) {

               return null;

           }

       }

   });

}

// TODO: End

}

2.You can obtaine App ID by the following code

String appId = AGConnectServicesConfig.fromContext(this).getString("client/app_id");

If it still fails, please add tags under the AndroidManifest.xml file

 <meta-data 

        android:name="com.huawei.hms.client.appid" 

        android:value="appid=xxxxx"> 

    </meta-data>

The appId can be obtained by the following code:

String appId = AGConnectServicesConfig.fromContext(this).getString("client/app_id");
Related