开发flutter插件时,华为获取到appId为空,配置文件.json文件不应该被读取

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

flutter插件开发中,

获取不到appId。我把配置文件.json放在java模块和example app目录下,获取不到appId。我该如何解决?

我把sdk封装到插件里报错:appId为空

getToken 失败,com.huawei.hms.common.ApiException:907135000:参数无效

appId可以通过以下代码获取:

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

请尝试以下步骤 1.将json文件放在Android层的assets目录下。如果没有,新建一个,在AndroidManifest.xml和Application中添加如下代码:

<application

android:name=".MyApplication"

…

>

public class MyApplication 扩展应用程序{

@Override

public void onCreate() {

   super.onCreate();

}

// TODO:添加以下代码:

@Override

protected void attachBaseContext(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;

           }

       }

   });

}

// 待办事项:结束

}

2.You可以通过以下代码获取App ID

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

如果还是不行,请在AndroidManifest.xml文件下添加标签

 <meta-data 

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

        android:value="appid=xxxxx"> 

    </meta-data>