首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android:需要为元素<service#io.intercom.android.sdk.fcm.IntercomFcmMessengerService>显式指定导出

android:需要为元素<service#io.intercom.android.sdk.fcm.IntercomFcmMessengerService>显式指定导出
EN

Stack Overflow用户
提问于 2022-06-10 05:43:17
回答 3查看 2.9K关注 0票数 3

我在AndroidManifest.xml中得到了一个颤振构建错误

.:需要为元素

显式指定导出的当相应组件定义了意图筛选器时,需要针对Android 12及更高版本的应用程序为android:exported指定显式值。

在AndroidManifest.xml文件中没有名为intercom的元素。我还在活动".MainActivity“中添加了.MainActivity”true“,但错误仍然存在。

我的AndoidManifest.xml文件如下

代码语言:javascript
复制
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="social.myproject.app">

    <!-- The INTERNET permission is required for development. Specifically,
         flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <uses-feature
            android:name="android.hardware.camera"
            android:required="false"/>
    <uses-feature
            android:name="android.hardware.camera.autofocus"
            android:required="false" />

    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https"/>

        </intent>
        <intent>
            <action android:name="com.google.android.youtube.api.service.START" />
        </intent>
    </queries>

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
            android:requestLegacyExternalStorage="true"
            android:label="myproject"
            android:icon="@mipmap/ic_launcher"
            android:usesCleartextTraffic="true"
        >
        <meta-data
                android:name="flutterEmbedding"
                android:value="2" />
        <activity
                android:name=".MainActivity"
                android:launchMode="singleTop"
                android:theme="@style/LaunchTheme"
                android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
                android:hardwareAccelerated="true"
                android:exported="true"
                android:windowSoftInputMode="adjustResize">
            <!-- Specify that the launch screen should continue being displayed -->
            <!-- until Flutter renders its first frame. -->
            <meta-data
                    android:name="io.flutter.embedding.android.SplashScreenDrawable"
                    android:resource="@drawable/launch_background" />

            <!-- Theme to apply as soon as Flutter begins rendering frames -->
            <meta-data
                    android:name="io.flutter.embedding.android.NormalTheme"
                    android:resource="@style/NormalTheme"
            />
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data
                        android:scheme="https"
                        android:host="www.myproject.social"
                        android:pathPrefix="/api/auth/"/>
            </intent-filter>
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data
                        android:scheme="https"
                        android:host="www.myproject.io"
                        android:pathPrefix="/api/auth/"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="image/*"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="text/*"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="video/*"/>
            </intent-filter>
        </activity>
        <activity
                android:name="com.yalantis.ucrop.UCropActivity"
                android:screenOrientation="portrait"
                android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
    </application>
</manifest>

详细的错误跟踪:

代码语言:javascript
复制
 See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
[   +1 ms] E:\App Development\MyApp - Changes\android\app\src\main\AndroidManifest.xml:11:9-16:19 Error:
[        ]      android:exported needs to be explicitly specified for element <service#io.intercom.android.sdk.fcm.IntercomFcmMessengerService>. Apps targeting Android 12 and higher are required to specify an
explicit value for `android:exported` when the corresponding component has an intent filter defined



The error trace points to the following lines : 

 <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <uses-feature
            android:name="android.hardware.camera"
            android:required="true"/>
    <uses-feature
            android:name="android.hardware.camera.autofocus"
            android:required="false"/>

编辑:将内部通讯版本更新为7.2.0。我现在知道了

错误:无法使用静态访问访问实例成员“初始化”。(static_access_to_instance_member at lib\services\intercom.dart:27)

跟踪指向这一行:

等待Intercom.initialize(appId,iosApiKey: iosApiKey,androidApiKey: androidApiKey);

我的intercom.dart

代码语言:javascript
复制
import 'dart:convert';

import 'package:myproject/models/user.dart';
import 'package:myproject/services/user.dart';
import 'package:crypto/crypto.dart';
import 'package:meta/meta.dart';
import 'package:intercom_flutter/intercom_flutter.dart';

class IntercomService {
  late UserService _userService;

  late String iosApiKey;
  late String androidApiKey;
  late String appId;

  void setUserService(UserService userService) {
    _userService = userService;
  }

  void bootstrap(
      {required String iosApiKey,
      required String androidApiKey,
      required String appId}) async {
    this.iosApiKey = iosApiKey;
    this.androidApiKey = androidApiKey;
    this.appId = appId;
    await Intercom.initialize(appId,
        iosApiKey: iosApiKey, androidApiKey: androidApiKey);
  }

  Future displayMessenger() {
    return Intercom.displayMessenger();
  }

  Future enableIntercom() async {
    await disableIntercom();
    User? loggedInUser = _userService.getLoggedInUser();
    if (loggedInUser == null) throw 'Cannot enable intercom. Not logged in.';

    assert(loggedInUser.uuid != null && loggedInUser.id != null);

    String userId = _makeUserId(loggedInUser);
    return Intercom.registerIdentifiedUser(userId: userId);
  }

  Future disableIntercom() {
    return Intercom.logout();
  }

  String _makeUserId(User user) {
    var bytes = utf8.encode(user.uuid! + user.id.toString());
    var digest = sha256.convert(bytes);
    return digest.toString();
  }
}

EN

回答 3

Stack Overflow用户

发布于 2022-06-10 08:50:07

可能性:

  • 您是否尝试过“失效/缓存并重新启动”?

  • 您试过用Android文件夹打开项目吗?如果您遗漏了AndroidManifest.xml.

中的任何内容,它将显示错误。

  • 您也可以尝试使用flutter clean & flutter pub get再次运行.

编辑:

您已经添加了一些库,但是它们还没有用IntercomFcmMessengerService更新此服务exported = true/false

这就是你遇到问题的原因。您可以做一件事,在<application>标记中使用exported=true定义服务。它会覆盖那个服务。

票数 2
EN

Stack Overflow用户

发布于 2022-06-10 07:22:37

即使我们添加android导出,有时也会发生这种情况。解决办法是在android->app->build.gradle文件中将targetSdkVersion设置为31,compileSDKVersion设置为31。

票数 0
EN

Stack Overflow用户

发布于 2022-06-11 12:40:03

通过在外部库的核心intercom_flutter包部分中访问的方法添加静态来解决这个问题。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72569552

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档