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

Android ecosytem updates #15399

Conversation

moljac
Copy link
Contributor

@moljac moljac commented Jun 1, 2023

Description of Change

  • updated Android nugets to the latest for net8 TFM
    • eng/AndroidX.targets
    • eng/Versions.props
    • src/Core/AndroidNative/*
    • src/Compatibility/Maps/src/Android/Compatibility.Maps.Android.csproj
  • some updates required tooling update[s]
    • gradle

@moljac moljac self-assigned this Jun 1, 2023
@moljac moljac marked this pull request as draft June 1, 2023 18:38
@rmarinho
Copy link
Member

rmarinho commented Jun 1, 2023

D:\a\_work\1\s\src\Compatibility\Maps\src\Android\Compatibility.Maps.Android.csproj : error NU1605: Warning As Error: Detected package downgrade: Xamarin.GooglePlayServices.Maps from 118.1.0.2 to 118.1.0.1. Reference the package directly from the project to select a different version.  [D:\a\_work\1\s\Microsoft.Maui.sln]
D:\a\_work\1\s\src\Compatibility\Maps\src\Android\Compatibility.Maps.Android.csproj : error NU1605:  Microsoft.Maui.Controls.Compatibility.Maps.Android -> Microsoft.Maui.Controls.Maps -> Microsoft.Maui.Maps -> Xamarin.GooglePlayServices.Maps (>= 118.1.0.2)  [D:\a\_work\1\s\Microsoft.Maui.sln]
D:\a\_work\1\s\src\Compatibility\Maps\src\Android\Compatibility.Maps.Android.csproj : error NU1605:  Microsoft.Maui.Controls.Compatibility.Maps.Android -> Xamarin.GooglePlayServices.Maps (>= 118.1.0.1) [D:\a\_work\1\s\Microsoft.Maui.sln]
    0 Warning(s)
    1 Error(s)

@@ -54,11 +54,11 @@
<_MicrosoftWebWebView2Version>1.0.1774.30</_MicrosoftWebWebView2Version>
<!-- GLIDE - the android maven artifact in /src/Core/AndroidNative/maui/build.gradle -->
<!-- must be kept in sync with the binding library version to it here: -->
<_XamarinAndroidGlideVersion>4.14.2.1</_XamarinAndroidGlideVersion>
<_XamarinAndroidGlideVersion>4.15.1.1</_XamarinAndroidGlideVersion>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to update the maven also

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found it.

I am going to hit the sack soon.

@moljac
Copy link
Contributor Author

moljac commented Jun 1, 2023

D:\a\_work\1\s\src\Compatibility\Maps\src\Android\Compatibility.Maps.Android.csproj : error NU1605: Warning As Error: Detected package downgrade: Xamarin.GooglePlayServices.Maps from 118.1.0.2 to 118.1.0.1. Reference the package directly from the project to select a different version.  [D:\a\_work\1\s\Microsoft.Maui.sln]
D:\a\_work\1\s\src\Compatibility\Maps\src\Android\Compatibility.Maps.Android.csproj : error NU1605:  Microsoft.Maui.Controls.Compatibility.Maps.Android -> Microsoft.Maui.Controls.Maps -> Microsoft.Maui.Maps -> Xamarin.GooglePlayServices.Maps (>= 118.1.0.2)  [D:\a\_work\1\s\Microsoft.Maui.sln]
D:\a\_work\1\s\src\Compatibility\Maps\src\Android\Compatibility.Maps.Android.csproj : error NU1605:  Microsoft.Maui.Controls.Compatibility.Maps.Android -> Xamarin.GooglePlayServices.Maps (>= 118.1.0.1) [D:\a\_work\1\s\Microsoft.Maui.sln]
    0 Warning(s)
    1 Error(s)

OK. Found it. Didn't know there are also PackageReferences with versions in csproj files.

@moljac
Copy link
Contributor Author

moljac commented Jun 1, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@moljac
Copy link
Contributor Author

moljac commented Jun 2, 2023

investigating gradle error:

Cannot use @TaskAction annotation on method IncrementalTask.taskAction$gradle_core() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.

https://stackoverflow.com/questions/19642280/could-not-call-incrementaltask-taskaction-on-task-mergedebugassets

https://stackoverflow.com/questions/74025711/could-not-create-task-appcompiledebugkotlin-could-not-create-task-app

@moljac
Copy link
Contributor Author

moljac commented Jun 2, 2023

gradle

  • compile works
  • lint fails
> Task :maui:lintDebug FAILED
Lint found 3 errors, 3 warnings. First failure:

./src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java:320: Error: TintTypedArray.obtainStyledAttributes can only be called from within the same library group prefix (referenced groupId=androidx.appcompat with prefix androidx from groupId=DOTNET MAUI) [RestrictedApi]
        TintTypedArray styledAttributes = TintTypedArray.obtainStyledAttributes(context, null, R.styleable.Toolbar, resId, 0);

@moljac
Copy link
Contributor Author

moljac commented Jun 2, 2023

gradle

  • lint fails
> Task :maui:lintDebug FAILED
Lint found 3 errors, 3 warnings. First failure:

./src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java:320: Error: TintTypedArray.obtainStyledAttributes can only be called from within the same library group prefix (referenced groupId=androidx.appcompat with prefix androidx from groupId=DOTNET MAUI) [RestrictedApi]
        TintTypedArray styledAttributes = TintTypedArray.obtainStyledAttributes(context, null, R.styleable.Toolbar, resId, 0);

solved (locally) by adding quick-n-dirty solution:

    lintOptions {
        disable 'RestrictedApi'
    }

But (always this but) there are few lint errors that might be needed to be addressed (cleaned up a bit):

./src/Core/AndroidNative/maui/build.gradle:11: Warning: Not targeting the latest versions of Android; compatibility modes apply. Consider testing and updating this version. Consult the android.os.Build.VERSION_CODES javadoc for details. [OldTargetApi]
        targetSdk 31
        ~~~~~~~~~~~~

   Explanation for issues of type "OldTargetApi":
   When your application runs on a version of Android that is more recent than
   your targetSdkVersion specifies that it has been tested with, various
   compatibility modes kick in. This ensures that your application continues
   to work, but it may look out of place. For example, if the targetSdkVersion
   is less than 14, your app may get an option button in the UI.

   To fix this issue, set the targetSdkVersion to the highest available value.
   Then test your app to make sure everything works correctly. You may want to
   consult the compatibility notes to see what changes apply to each version
   you are adding support for:
   https://developer.android.com/reference/android/os/Build.VERSION_CODES.html
   as well as follow this guide:
   https://developer.android.com/distribute/best-practices/develop/target-sdk.
   html

   https://developer.android.com/distribute/best-practices/develop/target-sdk.html

./src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java:320: Error: TintTypedArray.obtainStyledAttributes can only be called from within the same library group prefix (referenced groupId=androidx.appcompat with prefix androidx from groupId=DOTNET MAUI) [RestrictedApi]
        TintTypedArray styledAttributes = TintTypedArray.obtainStyledAttributes(context, null, R.styleable.Toolbar, resId, 0);
                                                         ~~~~~~~~~~~~~~~~~~~~~~
./src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java:322: Error: TintTypedArray.getColorStateList can only be called from within the same library group prefix (referenced groupId=androidx.appcompat with prefix androidx from groupId=DOTNET MAUI) [RestrictedApi]
            return styledAttributes.getColorStateList(index);
                                    ~~~~~~~~~~~~~~~~~
./src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java:324: Error: TintTypedArray.recycle can only be called from within the same library group prefix (referenced groupId=androidx.appcompat with prefix androidx from groupId=DOTNET MAUI) [RestrictedApi]
            styledAttributes.recycle();
                             ~~~~~~~

   Explanation for issues of type "RestrictedApi":
   This API has been flagged with a restriction that has not been met.

   Examples of API restrictions:
   * Method can only be invoked by a subclass
   * Method can only be accessed from within the same library (defined by the
   Gradle library group id)
   * Method can only be accessed from tests.

   You can add your own API restrictions with the @RestrictTo annotation.

./src/Core/AndroidNative/maui/src/main/res/values/strings.xml:2: Warning: The resource R.string.maui_empty_unused appears to be unused [UnusedResources]
    <string name="maui_empty_unused"></string>
            ~~~~~~~~~~~~~~~~~~~~~~~~

   Explanation for issues of type "UnusedResources":
   Unused resources make applications larger and slow down builds.


   The unused resource check can ignore tests. If you want to include
   resources that are only referenced from tests, consider packaging them in a
   test source set instead.

   You can include test sources in the unused resource check by setting the
   system property lint.unused-resources.include-tests =true, and to exclude
   them (usually for performance reasons), use
   lint.unused-resources.exclude-tests =true.
   ,

./src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/MauiViewGroup.java:67: Warning: Custom view MauiViewGroup overrides onTouchEvent but not performClick [ClickableViewAccessibility]
    public boolean onTouchEvent (MotionEvent ev)
                   ~~~~~~~~~~~~

   Explanation for issues of type "ClickableViewAccessibility":
   If a View that overrides onTouchEvent or uses an OnTouchListener does not
   also implement performClick and call it when clicks are detected, the View
   may not handle accessibility actions properly. Logic handling the click
   actions should ideally be placed in View#performClick as some accessibility
   services invoke performClick when a click action should occur.

3 errors, 3 warnings

@moljac
Copy link
Contributor Author

moljac commented Jun 2, 2023

regarding lint errors:

[Android] Remove all uses of Styleable arrays inside the .NET MAUI code
In order to enable some optimization features we need to remove uses of Styleable arrays from our code

#4889

Maybe this would apply to native code too?

@moljac
Copy link
Contributor Author

moljac commented Jun 2, 2023

stuck at (investigating):

D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024: System.IO.IOException: The process cannot access the file 'D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\obj\Release\net8.0-android\android-arm64\android\assets\Xamarin.AndroidX.CustomView.pdb' because it is being used by another process. [D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Xamarin.Android.Tasks.MarshalMethodsAssemblyRewriter.Rewrite(DirectoryAssemblyResolver resolver, List`1 targetAssemblyPaths, Boolean brokenExceptionTransitions) [D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res, Boolean useMarshalMethods) [D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask() [D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25 [D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024: System.IO.IOException: The process cannot access the file 'D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.pdb' because it is being used by another process. [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\Compatibility.ControlGallery.Android.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\Compatibility.ControlGallery.Android.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Xamarin.Android.Tasks.MarshalMethodsAssemblyRewriter.Rewrite(DirectoryAssemblyResolver resolver, List`1 targetAssemblyPaths, Boolean brokenExceptionTransitions) [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\Compatibility.ControlGallery.Android.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res, Boolean useMarshalMethods) [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\Compatibility.ControlGallery.Android.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask() [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\Compatibility.ControlGallery.Android.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25 [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\Compatibility.ControlGallery.Android.csproj]
    1388 Warning(s)
    2 Error(s)

@moljac
Copy link
Contributor Author

moljac commented Jun 2, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@moljac
Copy link
Contributor Author

moljac commented Jun 2, 2023

Last errors about binary something

kill me if I understand

@moljac
Copy link
Contributor Author

moljac commented Jun 2, 2023

please help

Child node "8"

I have only 3 kids not 8

D:\a\_work\1\s\src\Maui.InTree.targets(20,5): error MSB4024: The imported project file "D:\a\_work\1\s\.buildtasks\Microsoft.Maui.Core.targets" could not be loaded. The process cannot access the file 'D:\a\_work\1\s\.buildtasks\Microsoft.Maui.Core.targets' because it is being used by another process. [D:\a\_work\1\s\src\Core\tests\DeviceTests\Core.DeviceTests.csproj]
MSBUILD : error MSB4166: Child node "8" exited prematurely. Shutting down. Diagnostic information may be found in files in "C:\Users\cloudtest\AppData\Local\Temp\MSBuildTempcloudtest\" and will be named MSBuild_*.failure.txt. This location can be changed by setting the MSBUILDDEBUGPATH environment variable to a different directory.
MSBUILD : error MSB4166: C:\Users\cloudtest\AppData\Local\Temp\MSBuildTempcloudtest\MSBuild_pid-4064_9581c556143a4c849b65365260e35410.failure.txt:
MSBUILD : error MSB4166: UNHANDLED EXCEPTIONS FROM PROCESS 4064:
MSBUILD : error MSB4166: =====================
MSBUILD : error MSB4166: 6/2/2023 5:51:10 PM
MSBUILD : error MSB4166: System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.
MSBUILD : error MSB4166:    at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
MSBUILD : error MSB4166:    at Microsoft.Build.BackEnd.BinaryTranslator.BinaryWriteTranslator.TranslateException(Exception& value)
MSBUILD : error MSB4166:    at Microsoft.Build.Execution.BuildResult.Microsoft.Build.BackEnd.ITranslatable.Translate(ITranslator translator)
MSBUILD : error MSB4166:    at Microsoft.Build.BackEnd.NodeEndpointOutOfProcBase.RunReadLoop(Stream localReadPipe, Stream localWritePipe, ConcurrentQueue`1 localPacketQueue, AutoResetEvent localPacketAvailable, AutoResetEvent localTerminatePacketPump)
M

@moljac
Copy link
Contributor Author

moljac commented Jun 3, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@moljac
Copy link
Contributor Author

moljac commented Jun 4, 2023

still

D:\a\_work\1\s\bin\dotnet\sdk\8.0.100-preview.5.23271.2\Microsoft.Common.CurrentVersion.targets(4687,5): error MSB3027: Could not copy "obj\Release\netstandard2.0\Microsoft.Maui.Graphics.Text.Markdig.dll" to "bin\Release\netstandard2.0\Microsoft.Maui.Graphics.Text.Markdig.dll". Exceeded retry count of 10. Failed.  [D:\a\_work\1\s\src\Graphics\src\Text.Markdig\Graphics.Text.Markdig.csproj]
D:\a\_work\1\s\bin\dotnet\sdk\8.0.100-preview.5.23271.2\Microsoft.Common.CurrentVersion.targets(4687,5): error MSB3021: Unable to copy file "obj\Release\netstandard2.0\Microsoft.Maui.Graphics.Text.Markdig.dll" to "bin\Release\netstandard2.0\Microsoft.Maui.Graphics.Text.Markdig.dll". The requested operation cannot be performed on a file with a user-mapped section open. : 'D:\a\_work\1\s\src\Graphics\src\Text.Markdig\bin\Release\netstandard2.0\Microsoft.Maui.Graphics.Text.Markdig.dll' [D:\a\_work\1\s\src\Graphics\src\Text.Markdig\Graphics.Text.Markdig.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024: System.IO.IOException: The process cannot access the file 'D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\obj\Release\net8.0-android\android-arm64\android\assets\Xamarin.AndroidX.CustomView.pdb' because it is being used by another process. [D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Xamarin.Android.Tasks.MarshalMethodsAssemblyRewriter.<Rewrite>g__CopyFile|6_0(String source, String target) [D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Xamarin.Android.Tasks.MarshalMethodsAssemblyRewriter.Rewrite(DirectoryAssemblyResolver resolver, List`1 targetAssemblyPaths, Boolean brokenExceptionTransitions) [D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res, Boolean useMarshalMethods) [D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask() [D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25 [D:\a\_work\1\s\src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024: System.IO.IOException: The process cannot access the file 'D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.pdb' because it is being used by another process. [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\Compatibility.ControlGallery.Android.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\Compatibility.ControlGallery.Android.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Xamarin.Android.Tasks.MarshalMethodsAssemblyRewriter.Rewrite(DirectoryAssemblyResolver resolver, List`1 targetAssemblyPaths, Boolean brokenExceptionTransitions) [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\Compatibility.ControlGallery.Android.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res, Boolean useMarshalMethods) [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\Compatibility.ControlGallery.Android.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask() [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\Compatibility.ControlGallery.Android.csproj]
D:\a\_work\1\s\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.5.309\tools\Xamarin.Android.Common.targets(1513,3): error XAGJS7024:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25 [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\Compatibility.ControlGallery.Android.csproj]
    1392 Warning(s)
    4 Error(s)

@jonathanpeppers
Copy link
Member

The first error is:

System.IO.IOException: The process cannot access the file 'D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.pdb' because it is being used by another process.
   at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite)
   at Xamarin.Android.Tasks.MarshalMethodsAssemblyRewriter.Rewrite(DirectoryAssemblyResolver resolver, List`1 targetAssemblyPaths, Boolean brokenExceptionTransitions)
   at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res, Boolean useMarshalMethods)
   at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask()
   at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25

Is there any major changes to Xamarin.AndroidX.CustomView here?

@jonathanpeppers
Copy link
Member

@rmarinho the underlying cause here is the timmer/linker is disabled in this project:

I wouldn't recommend turning this off, as you probably want to be testing trimmed projects.

I can reproduce the issue in a test, but it may not be solved in the next .NET 8 Preview as there is an easy workaround.

jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this pull request Jun 27, 2023
…Rewriter

Context: dotnet/maui#15399 (comment)

During a PR updating AndroidX dependencies in .NET MAUI, we got the
error:

    Task GenerateJavaStubs
    ...
    System.IO.IOException: The process cannot access the file 'D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.pdb' because it is being used by another process.
    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite)
    at Xamarin.Android.Tasks.MarshalMethodsAssemblyRewriter.Rewrite(DirectoryAssemblyResolver resolver, List`1 targetAssemblyPaths, Boolean brokenExceptionTransitions)
    at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res, Boolean useMarshalMethods)
    at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask()
    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25

Which has some very odd logging right before the failure:

    Copying rewritten assembly: obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.dll.new -> obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.dll
    Copying rewritten assembly: obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.pdb -> obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.pdb

Copying `Xamarin.AndroidX.CustomView.PoolingContainer.pdb` to
`Xamarin.AndroidX.CustomView.pdb`?

I could reproduce the issue in a test with `PublishTrimmed=false`:

    [Test]
    public void SimilarAndroidXAssemblyNames ([Values(true, false)] bool publishTrimmed)
    {
        var proj = new XamarinAndroidApplicationProject {
            IsRelease = true,
            AotAssemblies = publishTrimmed,
            PackageReferences = {
                new Package { Id = "Xamarin.AndroidX.CustomView", Version = "1.1.0.17" },
                new Package { Id = "Xamarin.AndroidX.CustomView.PoolingContainer", Version = "1.0.0.4" },
            }
        };
        proj.SetProperty (KnownProperties.PublishTrimmed, publishTrimmed.ToString());
        proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", "AndroidX.CustomView.PoolingContainer.PoolingContainer.IsPoolingContainer (null);");
        using var builder = CreateApkBuilder ();
        Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
    }

In `MarshalMethodsAssemblyRewriter` we write temporary assembly files to
`foo.new` and copy to the original path at `foo.dll`. We next copy any
symbol files if found.

I found two underlying issues here.

First, this `Mono.Cecil` API:

    AssemblyDefinition.Write("foo.new", new WriterParameters {
        WriteSymbols = true
    });

It would write a `foo.pdb` instead of `foo.new.pdb`, and so we have no
way for this to write symbols to a temporary location.

I put the temporary location in a `new` subdirectory instead of
appending `.new` to the path.

The second problem is this code:

    target = Path.ChangeExtension (Path.Combine (targetPath, Path.GetFileNameWithoutExtension (pdb)), ".pdb");
    CopyFile (pdb, target);

It appears to lose `.PoolingContainer` from the path, and so it uses the
destination of:

    obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.pdb

But using a `new` subdirectory instead, we bypass this issue.

After these changes, we instead get:

    Copying rewritten assembly: obj\Release\android\assets\new\Xamarin.AndroidX.CustomView.PoolingContainer.dll -> obj\Release\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.dll
    Copying rewritten assembly: obj\Release\android\assets\new\Xamarin.AndroidX.CustomView.PoolingContainer.pdb -> obj\Release\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.pdb
    Deleting: obj\Release\android\assets\new\Xamarin.AndroidX.CustomView.PoolingContainer.dll
    Deleting: obj\Release\android\assets\new\Xamarin.AndroidX.CustomView.PoolingContainer.pdb

Lastly, I removed `.mdb` file support -- but that is completely
unrelated to the issue.
@moljac moljac force-pushed the dev/moljac/net8-manual-updates-20230601-android-dependencies branch 2 times, most recently from 50cceaa to 9d4be10 Compare June 28, 2023 17:56
jonpryor pushed a commit to dotnet/android that referenced this pull request Jun 28, 2023
…#8151)

Context: dotnet/maui#15399 (comment)

During a PR updating AndroidX dependencies in .NET MAUI, we saw:

	Task GenerateJavaStubs
	  …
	  System.IO.IOException: The process cannot access the file 'D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.pdb' because it is being used by another process.
	     at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite)
	     at Xamarin.Android.Tasks.MarshalMethodsAssemblyRewriter.Rewrite(DirectoryAssemblyResolver resolver, List`1 targetAssemblyPaths, Boolean brokenExceptionTransitions)
	     at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res, Boolean useMarshalMethods)
	     at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask()
	     at Microsoft.Android.Build.Tasks.AndroidTask.Execute()

Which has some very odd logging right before the failure:

	Copying rewritten assembly: obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.dll.new -> obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.dll
	Copying rewritten assembly: obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.pdb -> obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.pdb

Copying `Xamarin.AndroidX.CustomView.PoolingContainer.pdb` to
`Xamarin.AndroidX.CustomView.pdb`?  Where is  `.PoolingContainer`?

I could reproduce the issue in a test with `$(PublishTrimmed)`=False:

	[Test]
	public void SimilarAndroidXAssemblyNames ([Values(true, false)] bool publishTrimmed)
	{
	    var proj = new XamarinAndroidApplicationProject {
	        IsRelease = true,
	        AotAssemblies = publishTrimmed,
	        PackageReferences = {
	            new Package { Id = "Xamarin.AndroidX.CustomView", Version = "1.1.0.17" },
	            new Package { Id = "Xamarin.AndroidX.CustomView.PoolingContainer", Version = "1.0.0.4" },
	        }
	    };
	    proj.SetProperty (KnownProperties.PublishTrimmed, publishTrimmed.ToString());
	    proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", "AndroidX.CustomView.PoolingContainer.PoolingContainer.IsPoolingContainer (null);");
	    using var builder = CreateApkBuilder ();
	    Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
	}

In `MarshalMethodsAssemblyRewriter` we write temporary assembly files
to `foo.new` and copy to the original path at `foo.dll`.  We next
copy  any symbol files if found.

I found two underlying issues here:

First, this `Mono.Cecil` API:

	AssemblyDefinition.Write("foo.new", new WriterParameters {
	    WriteSymbols = true,
	});

would write a `foo.pdb` instead of `foo.new.pdb`, and so we have no
way for this to write symbols to a temporary location.

I put the temporary location in a `new` subdirectory instead of
appending `.new` to the path.

The second problem is this code:

	target = Path.ChangeExtension (Path.Combine (targetPath, Path.GetFileNameWithoutExtension (pdb)), ".pdb");
	CopyFile (pdb, target);

It appears to lose `.PoolingContainer` from the path, and so it uses
the destination of:

	obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.pdb

By using a `new` subdirectory instead, we bypass this issue.

After these changes, we instead get:

	Copying rewritten assembly: obj\Release\android\assets\new\Xamarin.AndroidX.CustomView.PoolingContainer.dll -> obj\Release\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.dll
	Copying rewritten assembly: obj\Release\android\assets\new\Xamarin.AndroidX.CustomView.PoolingContainer.pdb -> obj\Release\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.pdb
	Deleting: obj\Release\android\assets\new\Xamarin.AndroidX.CustomView.PoolingContainer.dll
	Deleting: obj\Release\android\assets\new\Xamarin.AndroidX.CustomView.PoolingContainer.pdb

Lastly, I removed `.mdb` file support -- but that is completely
unrelated to the issue.
jonathanpeppers added a commit to dotnet/android that referenced this pull request Jun 28, 2023
…#8151)

Context: dotnet/maui#15399 (comment)

During a PR updating AndroidX dependencies in .NET MAUI, we saw:

	Task GenerateJavaStubs
	  …
	  System.IO.IOException: The process cannot access the file 'D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Android\obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.pdb' because it is being used by another process.
	     at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite)
	     at Xamarin.Android.Tasks.MarshalMethodsAssemblyRewriter.Rewrite(DirectoryAssemblyResolver resolver, List`1 targetAssemblyPaths, Boolean brokenExceptionTransitions)
	     at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res, Boolean useMarshalMethods)
	     at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask()
	     at Microsoft.Android.Build.Tasks.AndroidTask.Execute()

Which has some very odd logging right before the failure:

	Copying rewritten assembly: obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.dll.new -> obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.dll
	Copying rewritten assembly: obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.pdb -> obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.pdb

Copying `Xamarin.AndroidX.CustomView.PoolingContainer.pdb` to
`Xamarin.AndroidX.CustomView.pdb`?  Where is  `.PoolingContainer`?

I could reproduce the issue in a test with `$(PublishTrimmed)`=False:

	[Test]
	public void SimilarAndroidXAssemblyNames ([Values(true, false)] bool publishTrimmed)
	{
	    var proj = new XamarinAndroidApplicationProject {
	        IsRelease = true,
	        AotAssemblies = publishTrimmed,
	        PackageReferences = {
	            new Package { Id = "Xamarin.AndroidX.CustomView", Version = "1.1.0.17" },
	            new Package { Id = "Xamarin.AndroidX.CustomView.PoolingContainer", Version = "1.0.0.4" },
	        }
	    };
	    proj.SetProperty (KnownProperties.PublishTrimmed, publishTrimmed.ToString());
	    proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", "AndroidX.CustomView.PoolingContainer.PoolingContainer.IsPoolingContainer (null);");
	    using var builder = CreateApkBuilder ();
	    Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
	}

In `MarshalMethodsAssemblyRewriter` we write temporary assembly files
to `foo.new` and copy to the original path at `foo.dll`.  We next
copy  any symbol files if found.

I found two underlying issues here:

First, this `Mono.Cecil` API:

	AssemblyDefinition.Write("foo.new", new WriterParameters {
	    WriteSymbols = true,
	});

would write a `foo.pdb` instead of `foo.new.pdb`, and so we have no
way for this to write symbols to a temporary location.

I put the temporary location in a `new` subdirectory instead of
appending `.new` to the path.

The second problem is this code:

	target = Path.ChangeExtension (Path.Combine (targetPath, Path.GetFileNameWithoutExtension (pdb)), ".pdb");
	CopyFile (pdb, target);

It appears to lose `.PoolingContainer` from the path, and so it uses
the destination of:

	obj\Release\net8.0-android\android\assets\Xamarin.AndroidX.CustomView.pdb

By using a `new` subdirectory instead, we bypass this issue.

After these changes, we instead get:

	Copying rewritten assembly: obj\Release\android\assets\new\Xamarin.AndroidX.CustomView.PoolingContainer.dll -> obj\Release\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.dll
	Copying rewritten assembly: obj\Release\android\assets\new\Xamarin.AndroidX.CustomView.PoolingContainer.pdb -> obj\Release\android\assets\Xamarin.AndroidX.CustomView.PoolingContainer.pdb
	Deleting: obj\Release\android\assets\new\Xamarin.AndroidX.CustomView.PoolingContainer.dll
	Deleting: obj\Release\android\assets\new\Xamarin.AndroidX.CustomView.PoolingContainer.pdb

Lastly, I removed `.mdb` file support -- but that is completely
unrelated to the issue.
@moljac moljac marked this pull request as ready for review June 30, 2023 07:40
@moljac moljac requested a review from rmarinho June 30, 2023 07:41
@moljac moljac marked this pull request as draft June 30, 2023 07:43
@moljac
Copy link
Contributor Author

moljac commented Jun 30, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@moljac moljac marked this pull request as ready for review June 30, 2023 09:00
@rmarinho
Copy link
Member

I think something got wrong with rebase or merge, I think these changes are coming from main and not net8.

@moljac
Copy link
Contributor Author

moljac commented Jul 1, 2023

I think something got wrong with rebase or merge, I think these changes are coming from main and not net8.

I noticed it last week when there were some issues with github. Not sure what happened. I cannot resolve these 3 issues either.
I will create new PR and close this one.

@moljac moljac closed this Jul 2, 2023
@samhouts samhouts added the area-testing Unit tests, device tests label Jul 11, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants