【问题标题】:How to set Android exported for Cordova application如何设置为 Cordova 应用程序导出的 Android
【发布时间】:2022-11-01 23:46:38
【问题描述】:

我需要在针对 Android 12 的 Google Play 上发布 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

我在互联网上做了一些研究,发现应该将此配置添加到 config.xml:

    <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application/activity">
        <activity android:exported="true"/>
    </edit-config>  

它适用于我的一些应用程序,但其中一个应用程序在上传到 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>

任何想法,有什么问题?

【问题讨论】:

    标签: android cordova export android-manifest


    【解决方案1】:

    尝试在&lt;platform name="android"&gt; 下将其添加到您的cordova 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 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    • 将此添加到 config.xml Unable to graft xml at selector "/manifest/application/service" 后出现此错误
    • @August,不要在配置文件中这样做。在您的插件文件夹中,找到 plugin.xml 文件,并在其中添加您的服务,以及您需要的所有参数,就像这样。 <platform name="android"> <config-file parent="/manifest/application" target="AndroidManifest.xml"> <service android:name="com.adobe.phonegap.push.FCMService" android:exported=" false"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> </config-file> </platform>
    • @AlexanderGapanowich 你如何在 Cordova/Ionic Appflow 环境中做到这一点? (无法访问插件文件夹,因为它是在编译期间生成的)。在平台标签中添加答案时,我也有与 August 相同的结果。
    • @Michael,就我而言,我只是使用文件管理器转到插件文件夹,如下所示 - project_root_folder -> cordova -> plugins -> cordova-plugin-my-plugin-name -> plugin.xml 这不是生成的文件,而是用于插件调整,不能是生成的。
    【解决方案2】:

    跟进卡尔史密斯的回答。 您需要在更多标签上设置导出。 edit-config 标签顾名思义,它在生成 XML 配置文件后对其进行编辑。在这种情况下,它将添加 android:exported 标记。

    尝试将此添加到您的配置文件文件里面标签:

        <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>
    

    它不仅会为活动服务标签,但也为提供者接收者.

    请注意,这会将导出的标志设置为 true。最好的解决方案是等到您的插件的所有维护者都更新了插件,但在此之前,至少您可以将您的工作应用程序提交到 Play 商店并确认使用 API 31。

    【讨论】:

      猜你喜欢
      • 2022-11-14
      • 2017-05-25
      • 1970-01-01
      • 2021-08-30
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      • 1970-01-01
      相关资源
      最近更新 更多