Skip to content

Conversation

@jonathanpeppers
Copy link
Member

Context: dotnet/android-libraries#247

When porting AndroidX to .NET 6, I noticed something odd... I was
getting .aar files in the build output that appeared to contain the
contents of android-support-multidex.jar.

Then I noticed:

https://github.com/xamarin/AndroidX/blob/16b02ae51980f7bab7be395d44f9998eea9bf32f/source/AndroidXProject.cshtml#L18

The AndroidX binding projects are setting $(AndroidEnableMultiDex)?

This is surely not intentional to be set in a class library, but this
causes _AddMultiDexDependencyJars to run:

<Target Name="_AddMultiDexDependencyJars">
  <!-- ... -->
  <ItemGroup Condition=" '$(AndroidEnableMultiDex)' == 'True' AND '$(AndroidMultiDexSupportJar)' == '' ">
    <AndroidJavaLibrary Include="$(MonoAndroidToolsDirectory)\android-support-multidex.jar" />
  </ItemGroup>
</Target>

If this was added to @(AndroidJavaLibrary), then the <CreateAar/>
MSBuild task would happily package it in a .NET 6 class library!

I think the solution here is that the _AddMultiDexDependencyJars
MSBuild target shouldn't actually run unless $(AndroidApplication)
is true.

I updated an existing test for this scenario.

…r apps

Context: dotnet/android-libraries#247

When porting AndroidX to .NET 6, I noticed something odd... I was
getting `.aar` files in the build output that appeared to contain the
contents of `android-support-multidex.jar`.

Then I noticed:

https://github.com/xamarin/AndroidX/blob/16b02ae51980f7bab7be395d44f9998eea9bf32f/source/AndroidXProject.cshtml#L18

The AndroidX binding projects are setting `$(AndroidEnableMultiDex)`?

This is surely not intentional to be set in a class library, but this
causes `_AddMultiDexDependencyJars` to run:

    <Target Name="_AddMultiDexDependencyJars">
      <!-- ... -->
      <ItemGroup Condition=" '$(AndroidEnableMultiDex)' == 'True' AND '$(AndroidMultiDexSupportJar)' == '' ">
        <AndroidJavaLibrary Include="$(MonoAndroidToolsDirectory)\android-support-multidex.jar" />
      </ItemGroup>
    </Target>

If this was added to `@(AndroidJavaLibrary)`, then the `<CreateAar/>`
MSBuild task would happily package it in a .NET 6 class library!

I think the solution here is that the `_AddMultiDexDependencyJars`
MSBuild target shouldn't actually run unless `$(AndroidApplication)`
is `true`.

I added updated an existing test for this scenario.
@jonathanpeppers jonathanpeppers marked this pull request as ready for review January 27, 2021 14:40
@jonathanpeppers
Copy link
Member Author

The couple test failures look like they are related to FastDev, which hopefully #5544 will help.

Going to merge this one.

@jonathanpeppers jonathanpeppers merged commit 15b40af into dotnet:master Jan 27, 2021
@jonathanpeppers jonathanpeppers deleted the multidex-class-libraries branch January 27, 2021 19:47
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants