我在 AndroidManifest.xml 中遇到 Flutter 構建錯誤
android:exported 需要為元素 <service#io.intercom.android.sdk.fcm.IntercomFcmMessengerService> 顯式指定。面向 Android 12 及更高版本的應用需要為
android:exported相應組件定義了 Intent 過濾器時指定顯式值
AndroidManifest.xml 檔案中沒有名為 intercom 的元素。我還在活動“.MainActivity”中添加了 android:exported="true" 但錯誤仍然存??在。
我的 AndoidManifest.xml 檔案如下
<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>
詳細的錯誤跟蹤:
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。我現在收到以下錯誤
錯誤:無法使用靜態訪問訪問實體成員“初始化”。(lib\services\intercom.dart:27 上的 static_access_to_instance_member)
跟蹤指向這一行:
等待 Intercom.initialize(appId, iosApiKey: iosApiKey, androidApiKey: androidApiKey);
我的對講機.dart
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();
}
}
uj5u.com熱心網友回復:
即使我們添加了匯出的 android,有時也會發生這種情況。解決方法是在 android->app->build.gradle 檔案中將 targetSdkVersion 設定為 31,并將 compileSDKVersion 設定為 31
uj5u.com熱心網友回復:
可能性:
您是否嘗試過“無效/快取并重新啟動”?
您是否嘗試過使用 Android 檔案夾打開專案?如果您遺漏了任何內容,它將顯示錯誤
AndroidManifest.xml.您也可以嘗試使用
flutter clean&flutter pub get再次運行。
編輯:
IntercomFcmMessengerService您添加了一些庫,但他們沒有更新此服務exported = true/false
這就是你遇到問題的原因。你可以做一件事,在你的<application>標簽中定義該服務exported=true。它將覆寫該服務。
uj5u.com熱心網友回復:
通過將靜態添加到外部庫的核心 intercom_flutter 包部分中正在訪問的方法來解決它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/489553.html
上一篇:當nameText為空時需要幫助輸出“您必須輸入名稱”。使用我目前擁有的代碼,當nameText為空時它無法識別
