use*_*426 15 android export android-manifest cordova
我需要在 Google Play 上发布针对 Android 12 的 Cordova 应用程序。当我上传 APK 文件时,出现错误
You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without the 'android:exported' property set. This file can't be installed on Android 12 or higher. See: developer.android.com/about/versions/12/behavior-changes-12#exported
Run Code Online (Sandbox Code Playgroud)
我在互联网上做了一些研究,发现这个配置应该添加到 config.xml 中:
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application/activity">
<activity android:exported="true"/>
</edit-config>
Run Code Online (Sandbox Code Playgroud)
它对于我的一些应用程序运行良好,但其中一个应用程序在上传到 Google Play 时仍然显示错误。它的 AndroidManifest.xml 如下所示:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="750" android:versionName="7.5.0" package="cz.foxtrot.motoquest" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:usesCleartextTraffic="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/activity_name" android:launchMode="singleTask" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:enabled="true" android:name="nl.xservices.plugins.ShareChooserPendingIntent">
<intent-filter>
<action android:name="android.intent.action.SEND" />
</intent-filter>
</receiver>
<provider android:authorities="${applicationId}.sharing.provider" android:exported="true" android:grantUriPermissions="true" android:name="nl.xservices.plugins.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/sharing_paths" />
</provider>
<meta-data android:name="com.transistorsoft.locationmanager.license_key" android:value="b2c8e0bf1863da91b0f941ddf8278f699d320a320182cf7eb1d1e5c660ee17be" />
</application>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Run Code Online (Sandbox Code Playgroud)
有什么想法,可能有什么问题吗?
piz*_*ter 13
跟进卡尔·史密斯的回答。您可能需要在更多标签上设置导出。edit-config 标签的作用正如其名称所示,它在生成 XML 配置文件后对其进行编辑。在这种情况下,它将添加 android:exported 标签。
尝试将其添加到您的config.xml文件中标签:
<edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/application/activity" mode="merge">
<activity android:exported="true"/>
</edit-config>
<edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/application/service" mode="merge">
<service android:exported="true" />
</edit-config>
<edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/application/provider" mode="merge">
<provider android:exported="true" />
</edit-config>
<edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/application/receiver" mode="merge">
<receiver android:exported="true" />
</edit-config>
Run Code Online (Sandbox Code Playgroud)
它不仅会为活动和服务标签设置标志,还会为提供者和接收者设置标志。
请注意,这会将导出的标志设置为 true。最好的解决方案是等到插件的所有维护者都更新了插件,但在那之前至少您可以将工作应用程序提交到 Play 商店并确认是否需要使用 API 31+。
请注意,您的配置可能不需要所有这 4 项编辑。这取决于您使用的插件以及它们的更新程度。从一个开始(从上到下),如果它不起作用,请添加更多,如果它起作用,请尝试删除其他以找出您需要的最小值。不要进行超出需要的更改。
我在config.xml中添加了以下代码
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application/activity" xmlns:android="http://schemas.android.com/apk/res/android">
<activity android:exported="true" />
</edit-config>
Run Code Online (Sandbox Code Playgroud)
我尝试添加<edit-config>服务、提供者和接收者,但是抛出以下错误
Unable to graft xml at selector "/manifest/application/receiver"
Run Code Online (Sandbox Code Playgroud)
当我仅添加活动时,它开始起作用。另外不要忘记包含xmlns:android="http://schemas.android.com/apk/res/android"在<edit-config> for活动中
尝试将其添加到您的 cordova config.xml 下<platform name="android">:
<edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/application/activity" mode="merge">
<activity android:exported="true" />
</edit-config>
<edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/application/service" mode="merge">
<service android:exported="true" />
</edit-config>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19481 次 |
| 最近记录: |