当前位置: 首页 > 知识库问答 >
问题:

添加服务后出现Android清单错误

吴建中
2023-03-14

所以,自从我在AndroidManifest文件中添加了一个服务块后,我一直收到一个错误,请查看我的清单。

错误显示:

“失败[INSTALL_PARSE_FAILED_MANIFEST_MALFORMED:在安装PackageLI:/data/app/vmdl1643630122.tmp/base.apk(位于二进制XML文件行#42):com.example.shoutout.MainActivity:Targeting S(版本31及以上)要求在存在意图筛选器时定义android:exported的显式值]”

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.shoutout">
   <uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
   <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
   <uses-permission android:name="android.permission.CAMERA" />
   <uses-permission android:name="android.permission.RECORD_AUDIO" />
   <uses-permission android:name="android.permission.BLUETOOTH"/>
   <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
   <application
        android:label="shoutout"
        android:icon="@mipmap/ic_launcher">
        <service android:name="com.example.shoutout.backgroundService"
         android:exported="false">
            <intent-filter>
                <action android:name="com.example.app.START_BACKGROUND" />
            </intent-filter>
        </service>
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

共有1个答案

黎玺
2023-03-14

错误显示您需要将android:exported=“true”添加到您的活动中,因为您有意向过滤器

试试这个:

<activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize"
            android:exported="true"> // add android:exported here
 类似资料: