Skip to content

Can remove MonoRuntimeProvider from some process? #8387

Closed

Description

@Coloryr

Android application type

.NET Android (net7.0-android, etc.)

Affected platform version

VS2022 net7

Description

I found a MonoRuntimeProvider in final AndroidManifest.xml

</activity>
    <provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="1999999999" android:authorities="coloryr.colormc.android.mono.MonoRuntimeProvider.__mono_init__" />
    <provider android:name="mono.MonoRuntimeProvider_1" android:exported="false" android:initOrder="1999999998" android:process=":game" android:authorities="coloryr.colormc.android.mono.MonoRuntimeProvider_1.__mono_init__" />

I want to remove MonoRuntimeProvider from process :game, cound write some config or command to remove it when building project?

Steps to Reproduce

  1. Just building

Did you find any workaround?

No response

Relevant log output

No response

Activity

  1. added
    Area: App+Library Build
    needs-triage
    on Oct 2, 2023
  2. dellis1972 commented on Oct 2, 2023

    @dellis1972
    Contributor

    You can probably user the AndroidManifestOverlay as described here https://github.com/xamarin/xamarin-android/blob/41aaf3873f702d260eb20b354ffdbb8884c51984/Documentation/guides/building-apps/build-items.md?plain=1#L142.

    That said if your process is written using .net then it won't work without the MonoRuntimeProvider

  3. removed
    needs-triage
    on Oct 2, 2023
  4. Coloryr commented on Oct 2, 2023

    @Coloryr
    Author

    No the

    <provider android:name="mono.MonoRuntimeProvider_1" android:exported="false" android:initOrder="1999999998" android:process=":game" android:authorities="coloryr.colormc.android.mono.MonoRuntimeProvider_1.__mono_init__" />
    

    Is auto gen.

    My AndroidManifest

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    		  android:installLocation="auto"
    		  xmlns:tools="http://schemas.android.com/tools">
    	<uses-feature android:glEsVersion="0x00033000" />
    	<uses-feature android:name="android.hardware.type.pc" android:required="false" />
    	<uses-permission android:name="android.permission.INTERNET" />
    	<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    	<uses-permission
                android:name="android.permission.WRITE_EXTERNAL_STORAGE"
                android:maxSdkVersion="28" />
    	<uses-permission
                android:name="android.permission.READ_EXTERNAL_STORAGE"
                android:maxSdkVersion="28" />
    	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    	<uses-permission android:name="android.permission.RECORD_AUDIO" />
    	<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    
    		<application
    			    .....
    	</application>
    </manifest>
    

    final AndroidManifest find in \obj\Debug\net7.0-android\AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <!--
        This code was generated by a tool.
        It was generated from E:\code\ColorMC.Android\src\ColorMC.Android\Properties\AndroidManifest.xml
        Changes to this file may cause incorrect behavior and will be lost if
        the contents are regenerated.
        -->
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" xmlns:tools="http://schemas.android.com/tools" android:versionCode="1" package="coloryr.colormc.android" android:versionName="1.0">
      <uses-sdk android:minSdkVersion="24" android:targetSdkVersion="33" />
      <uses-feature android:glEsVersion="0x00033000" />
      <uses-feature android:name="android.hardware.type.pc" android:required="false" />
      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
      <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
      <uses-permission android:name="android.permission.RECORD_AUDIO" />
      <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
      <application android:name="coloryr.colormc.load.MainApplication" android:debuggable="true" android:label="ColorMC" android:icon="@drawable/icon" android:appCategory="game" android:allowNativeHeapPointerTagging="false" android:hasFragileUserData="true" android:isGame="true" android:process=":launcher" android:resizeableActivity="true" android:allowBackup="true" android:requestLegacyExternalStorage="true" android:theme="@style/AppTheme" android:usesCleartextTraffic="true" android:extractNativeLibs="true">
        ....
        <provider android:name="mono.MonoRuntimeProvider_1" android:exported="false" android:initOrder="1999999998" android:process=":game" android:authorities="coloryr.colormc.android.mono.MonoRuntimeProvider_1.__mono_init__" />
      </application>
    </manifest>
    

    can remove

    <provider android:name="mono.MonoRuntimeProvider_1" android:exported="false" android:initOrder="1999999998" android:process=":game" android:authorities="coloryr.colormc.android.mono.MonoRuntimeProvider_1.__mono_init__" />
    

    from final AndroidManifest?

  5. dellis1972 commented on Oct 2, 2023

    @dellis1972
    Contributor

    I know it is auto generated. The AndroidManifestOverlay can help you remove items from the manifest before packaging.
    I recommend you read up on the AndroidManifestOverlay link https://github.com/xamarin/xamarin-android/blob/41aaf3873f702d260eb20b354ffdbb8884c51984/Documentation/guides/building-apps/build-items.md?plain=1#L142 and https://developer.android.com/build/manage-manifests#merge-manifests

  6. Coloryr commented on Oct 2, 2023

    @Coloryr
    Author

    Ok try remove it.

  7. Coloryr commented on Oct 2, 2023

    @Coloryr
    Author

    It not work.

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    		  package="coloryr.colormc.android"
    		  xmlns:tools="http://schemas.android.com/tools">
    	<application android:name="coloryr.colormc.load.MainApplication">
    		<provider android:name="mono.MonoRuntimeProvider_1" tools:node="remove" />
    	</application>
    </manifest>
    
    <ItemGroup>
      <AndroidManifestOverlay Include="RemoveNode.xml" />
    </ItemGroup>
    

    It can't match?

  8. Coloryr commented on Oct 2, 2023

    @Coloryr
    Author

    Remove other thing is work, but remove MonoRuntimeProvider not work.

  9. Coloryr commented on Oct 2, 2023

    @Coloryr
    Author
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    		  xmlns:tools="http://schemas.android.com/tools"
    		  package="coloryr.colormc.android">
    	<application android:name="coloryr.colormc.load.MainApplication">
    		<provider android:name="mono.MonoRuntimeProvider_1" tools:node="removeAll" />
    	</application>
    </manifest>
    

    Error msg is empty.

    6>E:\code\ColorMC.Android\src\ColorMC.Android\MainActivity.cs(197,19,197,33): warning CS8600: 将 null 文本或可能的 null 值转换为不可为 null 类型。
    6>E:\code\ColorMC.Android\src\ColorMC.Android\MainActivity.cs(41,28,41,32): warning CS8618: 在退出构造函数时,不可为 null 的 字段“_obj”必须包含非 null 值。请考虑将 字段 声明为可以为 null。
    6>ColorMC.Android -> E:\code\ColorMC.Android\src\ColorMC.Android\bin\Debug\net7.0-android\ColorMC.Android.dll
    6>E : \code\ColorMC.Android\src\ColorMC.Android\RemoveNode.xml error :
    6>已完成生成项目“ColorMC.Android.csproj”的操作 - 失败。
    ========== “全部重新生成”: 5 成功,1 失败,0已跳过 ==========
    ========= 重新生成 开始于 0:57,并花费了 29.489 秒 ==========
    
    
  10. dellis1972 commented on Oct 2, 2023

    @dellis1972
    Contributor

    try

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    		  xmlns:tools="http://schemas.android.com/tools">
    	<application>
    		<provider android:name="mono.MonoRuntimeProvider_1" tools:node="remove" />
    	</application>
    </manifest>
    

    See if that works.

  11. Coloryr commented on Oct 2, 2023

    @Coloryr
    Author

    try

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    		  xmlns:tools="http://schemas.android.com/tools">
    	<application>
    		<provider android:name="mono.MonoRuntimeProvider_1" tools:node="remove" />
    	</application>
    </manifest>
    

    See if that works.

    no work

  12. Coloryr commented on Oct 2, 2023

    @Coloryr
    Author

    image

  13. 2 remaining items

  14. dellis1972 commented on Oct 3, 2023

    @dellis1972
    Contributor

    You need to opt into the Manifest Merger. Its not on by default. Add the following to your PropertyGroup

        <AndroidManifestMerger>manifestmerger.jar</AndroidManifestMerger>
    

    You can then user the following in RemoveNode.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    		  xmlns:tools="http://schemas.android.com/tools">
    	<application>
    		<provider tools:node="remove"
                android:name="mono.MonoRuntimeProvider_1" />
    	</application>
    </manifest>
    

    See https://learn.microsoft.com/en-us/xamarin/android/deploy-test/building-apps/build-properties#androidmanifestmerger for more details.

  15. Coloryr commented on Oct 3, 2023

    @Coloryr
    Author

    You need to opt into the Manifest Merger. Its not on by default. Add the following to your PropertyGroup

        <AndroidManifestMerger>manifestmerger.jar</AndroidManifestMerger>
    

    You can then user the following in RemoveNode.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    		  xmlns:tools="http://schemas.android.com/tools">
    	<application>
    		<provider tools:node="remove"
                android:name="mono.MonoRuntimeProvider_1" />
    	</application>
    </manifest>
    

    See https://learn.microsoft.com/en-us/xamarin/android/deploy-test/building-apps/build-properties#androidmanifestmerger for more details.

    Ok try it

  16. Coloryr commented on Oct 3, 2023

    @Coloryr
    Author

    No, it still can't remove

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net7.0-android</TargetFramework>
        <Nullable>enable</Nullable>
        <ApplicationId>coloryr.colormc.android</ApplicationId>
        <ApplicationVersion>1</ApplicationVersion>
        <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
        <AndroidPackageFormat>apk</AndroidPackageFormat>
        <AndroidEnableProfiledAot>False</AndroidEnableProfiledAot>
        <SupportedOSPlatformVersion>24.0</SupportedOSPlatformVersion>
        <IsPublishable>True</IsPublishable>
        <Platforms>anycpu</Platforms>
    	<AndroidManifestMerger>manifestmerger.jar</AndroidManifestMerger>
      </PropertyGroup>
    
    	<ItemGroup>
    		<AndroidManifestOverlay Include="RemoveNode.xml" />
    	</ItemGroup>
    ....
    
  17. Coloryr commented on Oct 3, 2023

    @Coloryr
    Author

    image

  18. dellis1972 commented on Oct 3, 2023

    @dellis1972
    Contributor

    I think the final manifest is in \obj\Debug\net7.0-android\manifest\AndroidManifest.xml

    Those changes worked for me here.

  19. Coloryr commented on Oct 3, 2023

    @Coloryr
    Author

    image

  20. Coloryr commented on Oct 3, 2023

    @Coloryr
    Author

    I found about three AndroidManifest.xml
    obj\Debug\net7.0-android\AndroidManifest.xml
    obj\Debug\net7.0-android\android\AndroidManifest.xml
    obj\Debug\net7.0-android\android\manifest\AndroidManifest.xml

    what is the final AndroidManifest.xml?

  21. Coloryr commented on Oct 3, 2023

    @Coloryr
    Author

    Oh it work, mono's so not load int game process
    image

  22. locked and limited conversation to collaborators on Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area: App+Library Build

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions