Xamarin Android活动在AndroidManifest错误中重复 [英] Xamarin Android activity duplicated in AndroidManifest error

查看:95
本文介绍了Xamarin Android活动在AndroidManifest错误中重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将目标sdk/Android版本从Android 9更改为Android 10后,我正在使用Xamarin Android上的应用程序,并且卡在此错误上:

I'm working on a app in Xamarin Android and got stuck on this error, after changing target sdk/Android version from Android 9 to Android 10:

我的AndroidManifest(在Visual Studio中为):

my AndroidManifest (in Visual Studio!):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="0.7.1" package="com.INCREDIBLE.Video2mp3" android:installLocation="auto" android:versionCode="3">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
    <application android:allowBackup="true" android:label="@string/app_name" android:roundIcon="@drawable/micon" android:supportsRtl="true" android:theme="@style/AppTheme" android:icon="@drawable/micon">
        <activity android:name=".MainActivity" android:launchMode="singleTask">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter android:label="Download als mp3">
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>

但是在解决方案文件夹中,清单看起来像这样:

But in the Solution folder the Manifest looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="0.7.1" package="com.INCREDIBLE.Video2mp3" android:installLocation="auto" android:versionCode="3">
  <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <application android:allowBackup="true" android:label="@string/app_name" android:roundIcon="@drawable/micon" android:supportsRtl="true" android:theme="@style/AppTheme" android:icon="@drawable/micon" android:name="android.app.Application">
    <activity android:name=".MainActivity" android:launchMode="singleTask">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <intent-filter android:label="Download als mp3">
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/plain" />
      </intent-filter>
    </activity>
    <activity android:icon="@drawable/micon" android:label="@string/app_name" android:launchMode="singleTask" android:name="com.INCREDIBLE.Video2mp3.MainActivity" android:theme="@style/AppTheme">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="1999999999" android:authorities="com.INCREDIBLE.Video2mp3.mono.MonoRuntimeProvider.__mono_init__" />
  </application>
</manifest>

该应用程序应该只有一个活动(MainActivity).如果删除重复的" < activity .../> (直接在文件中),则不会收到错误消息,但是构建仍然会失败.在版本从9更改为10之前,它已按预期工作.现在(即使我将目标版本更改回9),也卡在这里.

The App should only have one Activity (MainActivity). If deleting the 'duplicated' <activity ... /> (in the file directly) I get no error massage, but the build fails anyways. Before the version changed from 9 to 10, it worked as expacted. Now (even when I change the target Version back to 9) I get stuck here.

推荐答案

在Xamarin中,您无需在清单中显式注册Activity.您可以从清单中删除所有活动代码,并在源文件中使用属性,如下所示:

In Xamarin, you don't need to explicitly register Activities in the Manifest. You can delete all activity code from the manifest and use Attributes in the source file like so:

[Activity(MainLauncher = true, LaunchMode = LaunchMode.SingleTask)]
[IntentFilter(new[] { "android.intent.action.SEND" }, Label = "Download als mp3", Categories = new[] { "android.intent.category.DEFAULT" }, DataMimeType = "text/plain")]
public class MainActivity: Activity
{

注意:您可能会同时做这两项,因此在构建项目时,活动的第二个条目可能会添加到清单中

Note: You may be doing both due to which a second entry for the activity maybe gets added to the manifest when you build the project

这篇关于Xamarin Android活动在AndroidManifest错误中重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆