簡體   English   中英

嘗試升級 SDK 版本,但出現錯誤“需要針對 Android 12 及更高版本的應用程序才能指定顯式值”

[英]Trying to upgrade SDK version but error "Apps targeting Android 12 and higher are required to specify an explicit value"

我正在嘗試將我的 SDK 版本從 30 升級到 31,並添加一些android:export="true"到我的清單,但仍然出現錯誤Error: 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.

這是我的清單

    <application
        android:name=".app.MyApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:usesCleartextTraffic="true"
        android:theme="@style/NoActionBar">
        <activity android:name=".ui.SplashScreen"
            android:exported="true"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait"
            android:exported="false"
            android:theme="@style/NoActionBar"
            android:windowSoftInputMode="stateHidden"/>

        <service
            android:name=".firebase.FcmServices"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

我的代碼有什么問題? 有什么遺漏嗎?

實際上它工作正常,文檔也顯示了它:

https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceIdService

https://firebase.google.com/docs/cloud-messaging/android/client#manifest

奇怪的是,當我最初測試它時,它不起作用。 只是以后。 不知道怎么可能。 可能是 Android 上的一些錯誤。

無論如何,這是來自文檔:


<service
    android:name=".java.MyFirebaseMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

<!-- FirebaseInstanceIdService performs security checks at runtime,
      no need for explicit permissions despite exported="true"             -->
 <service android:name=".MyFirebaseInstanceIdService" android:exported="true">
     <intent-filter>
         <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
     </intent-filter>
 </service>


很簡單,你需要在<service>標簽中設置android:exported="true"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM