Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can remove MonoRuntimeProvider from some process? #8387

Closed
Coloryr opened this issue Oct 2, 2023 · 20 comments
Closed

Can remove MonoRuntimeProvider from some process? #8387

Coloryr opened this issue Oct 2, 2023 · 20 comments
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.

Comments

@Coloryr
Copy link

Coloryr commented Oct 2, 2023

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

@Coloryr Coloryr added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels Oct 2, 2023
@dellis1972
Copy link
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

@dellis1972 dellis1972 removed the needs-triage Issues that need to be assigned. label Oct 2, 2023
@Coloryr
Copy link
Author

Coloryr commented Oct 2, 2023

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?

@dellis1972
Copy link
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

@Coloryr
Copy link
Author

Coloryr commented Oct 2, 2023

Ok try remove it.

@Coloryr
Copy link
Author

Coloryr commented Oct 2, 2023

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?

@Coloryr
Copy link
Author

Coloryr commented Oct 2, 2023

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

@Coloryr
Copy link
Author

Coloryr commented Oct 2, 2023

<?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 秒 ==========

@dellis1972
Copy link
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.

@Coloryr
Copy link
Author

Coloryr commented Oct 2, 2023

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

@Coloryr
Copy link
Author

Coloryr commented Oct 2, 2023

image

@dellis1972
Copy link
Contributor

I am trying to reproduce the issue. Can you provide an example of the C# code which has the :game process code on it?

@dellis1972
Copy link
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.

@Coloryr
Copy link
Author

Coloryr commented Oct 3, 2023

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

@Coloryr
Copy link
Author

Coloryr commented Oct 3, 2023

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

@Coloryr
Copy link
Author

Coloryr commented Oct 3, 2023

image

@dellis1972
Copy link
Contributor

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

Those changes worked for me here.

@Coloryr
Copy link
Author

Coloryr commented Oct 3, 2023

image

@Coloryr
Copy link
Author

Coloryr commented Oct 3, 2023

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?

@Coloryr
Copy link
Author

Coloryr commented Oct 3, 2023

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

@Coloryr Coloryr closed this as completed Oct 3, 2023
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Oct 3, 2023
Context dotnet#8387

The value for `AndroidManifestMerger` should be updated to
be `manifestmerger.jar`. This allows users to make use of
the new features like `AndroidManifestOverlay` out of the box.

The old system is still available, the users will need to
add the following to their csproj.

```
<AndroidManifestMerger>legacy</AndroidManifestMerger>
```
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Oct 6, 2023
Context dotnet#8387

The value for `AndroidManifestMerger` should be updated to
be `manifestmerger.jar`. This allows users to make use of
the new features like `AndroidManifestOverlay` out of the box.

The old system is still available, the users will need to
add the following to their csproj.

```
<AndroidManifestMerger>legacy</AndroidManifestMerger>
```
jonpryor pushed a commit that referenced this issue Oct 9, 2023
…8392)

Context: #8387

Context: 2c6f5cd
Context: f7ea4a3
Context: d794534

Update the value for `$(AndroidManifestMerger)` (f7ea4a3) to
`manifestmerger.jar`.  This allows users to make use of the new
features like `@(AndroidManifestOverlay)` (d794534) out of the box.

The old system is still available, users will need to add the
following to their csproj:

	<AndroidManifestMerger>legacy</AndroidManifestMerger>

AndroidX has been building with
`$(AndroidManifestMerger)`=manifestmerger.jar for
[over three years][0].

[0]: xamarin/AndroidX@c6c0e50
jonathanpeppers pushed a commit that referenced this issue Oct 10, 2023
…8392)

Context: #8387

Context: 2c6f5cd
Context: f7ea4a3
Context: d794534

Update the value for `$(AndroidManifestMerger)` (f7ea4a3) to
`manifestmerger.jar`.  This allows users to make use of the new
features like `@(AndroidManifestOverlay)` (d794534) out of the box.

The old system is still available, users will need to add the
following to their csproj:

	<AndroidManifestMerger>legacy</AndroidManifestMerger>

AndroidX has been building with
`$(AndroidManifestMerger)`=manifestmerger.jar for
[over three years][0].

[0]: xamarin/AndroidX@c6c0e50
jonathanpeppers pushed a commit that referenced this issue Oct 17, 2023
…8392)

Context: #8387

Context: 2c6f5cd
Context: f7ea4a3
Context: d794534

Update the value for `$(AndroidManifestMerger)` (f7ea4a3) to
`manifestmerger.jar`.  This allows users to make use of the new
features like `@(AndroidManifestOverlay)` (d794534) out of the box.

The old system is still available, users will need to add the
following to their csproj:

	<AndroidManifestMerger>legacy</AndroidManifestMerger>

AndroidX has been building with
`$(AndroidManifestMerger)`=manifestmerger.jar for
[over three years][0].

[0]: xamarin/AndroidX@c6c0e50
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App+Library Build Issues when building Library projects or Application projects.
Projects
None yet
Development

No branches or pull requests

3 participants