Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] XA1039 error for Android.Support (#8629)
Browse files Browse the repository at this point in the history
Context: c927026
Context: 6836818
Context: 929e701
Context: #8478
Context: #8155
Context: #8168

Our build process has a bit of a "consistent sanity" problem: large
portions of the build process assume that the output of a `.csproj`
is a single assembly, and that single assembly is (eventually)
embedded into the `.apk`, to be loaded at runtime.

Unfortunately, that wasn't strictly true starting with .NET 5:
there were *multiple* `System.Private.CoreLib.dll` assemblies, which
needed to be treated specially; see also c927026.

We discovered that this assumption was even *less* true because of
the linker, which would quite happily *replace* `IntPtr.get_Size()`
method invocations with a *constant*, specific for the target ABI;
see also 6836818, 929e701.  This in turn could be responsible for
all sorts of weirdness if e.g. a 64-bit assembly were used in a
32-bit process, or vice versa.

Which brings us to the original assumption: there is (usually) only
one "source" assembly, which is (optionally) linked into one "linked"
assembly, which is packaged into one assembly in the `.apk`.

With the linker, though, we can have one "source" assembly, which
when linked becomes *N* assemblies, which *should be* separately
packaged as per-ABI assemblies within the `.apk`, but
*probably aren't*, which we *think* is the "root cause" of #8155.

PR #8478 is attempting fix this assumption, imbuing the build system
with knowledge that the linker may produce *multiple outputs* for a
single input assembly.

Unfortunately, in trying to fix things, various intermediate assembly
locations have *changed*, which in turn breaks
[AndroidX Migration in Xamarin.Forms][0], as it makes assumptions
about where various assemblies are located within `obj`:

	(_AndroidXCecilfy target) ->
	/Users/runner/.nuget/packages/xamarin.androidx.migration/1.0.8/buildTransitive/monoandroid90/Xamarin.AndroidX.Migration.targets(227,9): error : Source assembly does not exist: 'obj/Debug/android/assets/UnnamedProject.dll'.

as [`@(_AndroidXFileToCecilfy)`][1] uses
`$(MonoAndroidIntermediateAssetsDir)`, which does not account for the
ABI which is now in the path:

	<ItemGroup>
	  <_AndroidXFileToCecilfy Include="@(ResolvedUserAssemblies->'$(MonoAndroidIntermediateAssetsDir)%(Filename)%(Extension)')"
	    Condition="('%(ResolvedUserAssemblies.TargetFrameworkIdentifier)' == 'MonoAndroid' or '%(ResolvedUserAssemblies.HasMonoAndroidReference)' == 'true') and ('%(ResolvedUserAssemblies.AndroidXSkipAndroidXMigration)' != 'true')" />
	</ItemGroup>

Given that AndroidX Migration is mostly for Xamarin.Forms customers
(and *kinda* buggy, and unmaintained), and MAUI doesn't support the
Android Support libraries, and thus doesn't need AndroidX Migration,
we'd like to just *not worry about this*.

The problem?  The above error message is not actionable, and doesn't
tell anybody how to fix it.

Introduce a new `XA1039` *actionable* error in .NET 9:

	error XA1039: The Android Support libraries are not supported in .NET 9 and later,
	please migrate to AndroidX. See https://aka.ms/xamarin/androidx for more details.

The XA1039 error is generated if any NuGet packages are found matching:

  * `Xamarin.Android.Support.*`
  * `Xamarin.Android.Arch.*`

TODO: "port" XA1039 to .NET 8 *as a warning*, so that customers will
have some time to migrate off of the Android Support libraries before
.NET 9 is released in 2024-Nov.

	--<AndroidError Code="XA1039"
	++<AndroidWarning Code="XA1039"
	    ResourceName="XA1039"
	    Condition=" '@(_AndroidUnsupportedPackages->Count())' != '0' "
	/>

The biggest impact here is going to be many of our old tests, which
use the support libraries in various forms.

Improvements & general cleanup:

  * Removed all old/unused packages in `KnownPackages.cs`

  * Updated `KnownPackages.cs` to latest versions, including Xamarin.Forms

  * [Android Wear tests are now migrated from support to AndroidX][2]

  * `AndroidUpdateResourcesTest.CheckEmbeddedSupportLibraryResources()`
    is renamed to `.CheckEmbeddedAndroidXResources()`.

  * `BuildTest2.BuildHasNoWarnings()` was not appropriately applying
    `IsRelease`.

  * `Android.Support.v8.RenderScript` removed in favor of an inline
    `.so` file.

  * A few tests that used support libraries to create a project large
    numbers of dependencies, moved to
    `XamarinFormsAndroidApplicationProject`.

  * `IncrementalBuildTest.ResolveLibraryProjectImports()` now sorts
    items before comparing them.

  * `XamarinFormsAndroidApplicationProject` has a workaround for Guava:  
    <xamarin/AndroidX#535>

  * Fix a bug in `AndroidFastDeploymentType=Assemblies::Dexes`;
    see "AndroidFastDeploymentType=Assemblies::Dexes" section, below.

Removed tests:

  * `AndroidXMigration`, `AndroidXMigrationBug`

  * `ResolveLibraryImportsWithReadonlyFiles`, seemed duplicate of other
    Android Wear tests, and used support libraries.

  * `ExtraAaptManifest` as it depends on `Xamarin.Android.Fabric` and
    `Xamarin.Android.Crashlytics`. These are deprecated and depend on
    support libraries.

  * `BuildProguardEnabledProjectSource` now only tests `Release` mode.
    Since updating to AndroidX, `Debug` mode was triggering multi-dex.
    Making it difficult to assert contents of `*.dex` files.


~~ AndroidFastDeploymentType=Assemblies::Dexes ~~

The runtime test in `ApplicationRunsWithDebuggerAndBreaks()` was
crashing at runtime with:

	E monodroid-assembly: typemap: failed to stat TypeMap index file '/data/user/0/com.xamarin.applicationrunswithdebuggerandbreaks/files/.__override__/typemaps/typemap.index': No such file or directory
	F monodroid-assembly: typemap: unable to load TypeMap data index from '/data/user/0/com.xamarin.applicationrunswithdebuggerandbreaks/files/.__override__/typemaps/typemap.index'

This only happens when `AndroidFastDeploymentType=Assemblies::Dexes` is
used, as it is the case when typemap files like this are fast deployed
and used at runtime.

What was even more odd, was the file seems to exist after a
`-t:Install`, but ends up missing after `-t:Run`:

	> adb shell run-as com.xamarin.applicationrunswithdebuggerandbreaks ls -la files/.__override__/typemaps/typemap.index
	ls: files/.__override__/typemaps/typemap.index: No such file or directory

It appears that `-t:Install` successfully deploys the file:

	Pushed 3969 to /data/local/tmp/.xatools/typemap.index
	DEBUG RunShellCommand emulator-5554 "run-as" "com.xamarin.applicationrunswithdebuggerandbreaks" "--user" "0" "files/.__tools__/xamarin.cp" "/data/local/tmp/.xatools/typemap.index" "files/.__override__/typemaps/typemap.index" "1705432079367" [5ms]
	files/.__tools__/xamarin.cp returned: moved [/data/local/tmp/.xatools/typemap.index] to [files/.__override__/typemaps/typemap.index] modifieddate [1705432079367]
	moved /data/local/tmp/.xatools/typemap.index to files/.__override__/typemaps/typemap.index
	Installed files/.__override__/typemaps/typemap.index. [12ms]
	NotifySync CopyFile obj\Debug\android\typemaps\typemap.index. [0ms]

But then `-t:Run` deletes the file!

	Remove redundant file files/.__override__/typemaps/typemap.index
	DEBUG RunShellCommand 0A041FDD400327 "run-as" "com.xamarin.applicationrunswithdebuggerandbreaks" "rm" "-Rf" "files/.__override__/typemaps/typemap.index" [29ms]

This happens because the `@(_AndroidTypeMapping)` item group is empty
during an incremental build:

  * The `<GenerateJavaStubs/>` MSBuild task, during the first build
    outputs `@(_AndroidTypeMapping)` items

  * During an incremental build, the `_GenerateJavaStubs` MSBuild
    *target* is skipped, and so the `@(_AndroidTypeMapping)` item
    group is empty!

  * The `<FastDeploy/>` task happily deletes files that it thinks
    should be removed.

For now, let's add logic to the `_GenerateJavaStubs` target to fill
in the `@(_AndroidTypeMapping)` item group during incremental builds:

	<ItemGroup Condition=" '$(_InstantRunEnabled)' == 'True' and '@(_AndroidTypeMapping->Count())' == '0' ">
	  <_AndroidTypeMapping Include="$(_NativeAssemblySourceDir)typemaps\*" />
	</ItemGroup>

`<ItemGroup>`s are still evaluated when a target is *skipped*,
solving the problem.

I assume this is working in `main`, because Xamarin.AndroidX.Migration
package was involved.  It likely was running the `_GenerateJavaStubs`
target on every build.

[0]: https://learn.microsoft.com/xamarin/xamarin-forms/platform/android/androidx-migration
[1]: https://github.com/xamarin/AndroidX/blob/17e596fafe20331d7feb69240c38e0fbdc3ea640/source/migration/BuildTasks/Xamarin.AndroidX.Migration.targets#L205-L206
[2]: https://android-developers.googleblog.com/2016/04/build-beautifully-for-android-wear.html
  • Loading branch information
jonathanpeppers authored Jan 18, 2024
1 parent d538d7b commit 2f19238
Show file tree
Hide file tree
Showing 24 changed files with 457 additions and 834 deletions.
47 changes: 47 additions & 0 deletions Documentation/guides/messages/xa1039.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: Xamarin.Android error XA1039
description: XA1039 error code
ms.date: 1/10/2024
---
# Xamarin.Android error XA1039

## Example messages

```
error XA1039: The Android Support libraries are not supported in .NET 9 and later, please migrate to AndroidX. See https://aka.ms/xamarin/androidx for more details.
```

## Issue

Outdated "Android Support Library" packages are no longer supported in .NET 9:

* `Xamarin.Android.Arch.*`
* `Xamarin.Android.Support.*`

The underlying Java libraries are no longer supported by Google since the final
28.0.0 release. See the [Android Support Library Documentation][support] for
details.

Some example prefixes of the newer, supported AndroidX packages are:

* `Xamarin.AndroidX.*`
* `Xamarin.AndroidX.Arch.*`

For more information about the Android Support libraries or AndroidX, see:

* [Android Support Library Documentation][support]
* [AndroidX Documentation](https://developer.android.com/jetpack/androidx)

[support]: https://developer.android.com/topic/libraries/support-library/packages

## Solution

Remove all NuGet package references to `Xamarin.Android.Support` or
`Xamarin.Android.Arch` in favor of the new AndroidX equivalents.

This also can occur if you are using a NuGet package with a transitive
dependency on the Android support packages. In this case, you will need to
remove the package or contact the package author.

See the [AndroidX migration documentation](https://aka.ms/xamarin/androidx) for
details.
4 changes: 4 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1006,4 +1006,8 @@ To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MS
{0} - The deprecated MSBuild property name
{1} - The numeric version of .NET</comment>
</data>
<data name="XA1039" xml:space="preserve">
<value>The Android Support libraries are not supported in .NET 9 and later, please migrate to AndroidX. See https://aka.ms/xamarin/androidx for more details.</value>
<comment>The following are literal names and should not be translated: Android Support, AndroidX, .NET.</comment>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,17 @@ public void DesignTimeBuild ([Values(false, true)] bool isRelease, [Values (fals
}

[Test]
public void CheckEmbeddedSupportLibraryResources ()
public void CheckEmbeddedAndroidXResources ()
{
var proj = new XamarinAndroidApplicationProject () {
IsRelease = true,
PackageReferences = {
KnownPackages.SupportMediaCompat_27_0_2_1,
KnownPackages.SupportFragment_27_0_2_1,
KnownPackages.SupportCoreUtils_27_0_2_1,
KnownPackages.SupportCoreUI_27_0_2_1,
KnownPackages.SupportCompat_27_0_2_1,
KnownPackages.AndroidSupportV4_27_0_2_1,
KnownPackages.SupportV7AppCompat_27_0_2_1,
KnownPackages.AndroidXAppCompat,
},
};
using (var b = CreateApkBuilder ()) {
Assert.IsTrue (b.Build (proj), "First build should have succeeded.");
var Rdrawable = b.Output.GetIntermediaryPath (Path.Combine ("android", "bin", "classes", "android", "support", "v7", "appcompat", "R$drawable.class"));
var Rdrawable = b.Output.GetIntermediaryPath (Path.Combine ("android", "bin", "classes", "androidx", "appcompat", "R$drawable.class"));
Assert.IsTrue (File.Exists (Rdrawable), $"{Rdrawable} should exist");
}
}
Expand Down Expand Up @@ -410,8 +404,7 @@ protected override void OnClick()
}
}"
});
proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.AndroidXAppCompat);
using (var libb = CreateDllBuilder (Path.Combine (projectPath, lib.ProjectName), cleanupOnDispose: false))
using (var b = CreateApkBuilder (Path.Combine (projectPath, proj.ProjectName), cleanupOnDispose: false)) {
Assert.IsTrue (libb.Build (lib), "Library Build should have succeeded.");
Expand Down Expand Up @@ -831,10 +824,6 @@ public void CheckFilesAreRemoved () {
</resources>",
}
},
PackageReferences = {
KnownPackages.SupportV7AppCompat_27_0_2_1,
KnownPackages.AndroidSupportV4_27_0_2_1,
},
};
using (var builder = CreateApkBuilder ()) {
Assert.IsTrue (builder.Build (proj), "Build should have succeeded");
Expand Down Expand Up @@ -1033,13 +1022,7 @@ public void BuildAppWithManagedResourceParserAndLibraries ()
new BuildItem.ProjectReference (@"..\Lib1\Lib1.csproj", libProj.ProjectName, libProj.ProjectGuid),
},
PackageReferences = {
KnownPackages.SupportMediaCompat_27_0_2_1,
KnownPackages.SupportFragment_27_0_2_1,
KnownPackages.SupportCoreUtils_27_0_2_1,
KnownPackages.SupportCoreUI_27_0_2_1,
KnownPackages.SupportCompat_27_0_2_1,
KnownPackages.AndroidSupportV4_27_0_2_1,
KnownPackages.SupportV7AppCompat_27_0_2_1,
KnownPackages.AndroidXAppCompat,
},
};
appProj.SetProperty ("AndroidUseManagedDesignTimeResourceGenerator", "True");
Expand Down Expand Up @@ -1224,20 +1207,7 @@ public void CustomViewAddResourceId ()
{
var proj = new XamarinAndroidApplicationProject ();
proj.LayoutMain = proj.LayoutMain.Replace ("</LinearLayout>", "<android.support.design.widget.BottomNavigationView android:id=\"@+id/navigation\" /></LinearLayout>");
proj.PackageReferences.Add (KnownPackages.Android_Arch_Core_Common_26_1_0);
proj.PackageReferences.Add (KnownPackages.Android_Arch_Lifecycle_Common_26_1_0);
proj.PackageReferences.Add (KnownPackages.Android_Arch_Lifecycle_Runtime_26_1_0);
proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportCompat_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportCoreUI_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportCoreUtils_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportDesign_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportFragment_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportMediaCompat_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7CardView_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7MediaRouter_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7RecyclerView_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.AndroidXAppCompat);
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
Assert.IsTrue (b.Build (proj), "first build should have succeeded");

Expand All @@ -1257,7 +1227,7 @@ public void CustomViewAddResourceId ()
var r_java = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "src", proj.PackageNameJavaIntermediatePath, "R.java");
FileAssert.Exists (r_java);
var r_java_contents = File.ReadAllLines (r_java);
Assert.IsTrue (StringAssertEx.ContainsText (r_java_contents, textView1), $"android/support/compat/R.java should contain `{textView1}`!");
Assert.IsTrue (StringAssertEx.ContainsText (r_java_contents, textView1), $"{r_java} should contain `{textView1}`!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ public void BuildAarBindigLibraryWithNuGetPackageOfJar (string classParser)
var proj = new XamarinAndroidBindingProject () {
IsRelease = true,
};
proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1);
proj.Jars.Add (new AndroidItem.LibraryProjectZip ("Jars\\android-crop-1.0.1.aar") {
WebContent = "https://repo1.maven.org/maven2/com/soundcloud/android/android-crop/1.0.1/android-crop-1.0.1.aar"
});
Expand All @@ -187,13 +186,12 @@ public void BuildAarBindigLibraryWithNuGetPackageOfJar (string classParser)
[Test]
[TestCaseSource (nameof (ClassParseOptions))]
[NonParallelizable]
public void BuildLibraryZipBindigLibraryWithAarOfJar (string classParser)
public void BuildLibraryZipBindingLibraryWithAarOfJar (string classParser)
{
var proj = new XamarinAndroidBindingProject () {
IsRelease = true,
};
proj.AndroidClassParser = classParser;
proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1);
proj.Jars.Add (new AndroidItem.LibraryProjectZip ("Jars\\aFileChooserBinaries.zip") {
WebContentFileNameFromAzure = "aFileChooserBinaries.zip"
});
Expand All @@ -202,41 +200,6 @@ public void BuildLibraryZipBindigLibraryWithAarOfJar (string classParser)
<attr path=""/api/package[@name='com.ipaulpro.afilechooser']/class[@name='FileListAdapter']/method[@name='getItem' and count(parameter)=1 and parameter[1][@type='int']]"" name=""managedReturn"">Java.Lang.Object</attr>
<attr path=""/api/package[@name='com.ipaulpro.afilechooser']/class[@name='FileLoader']/method[@name='loadInBackground' and count(parameter)=0]"" name=""managedName"">LoadInBackgroundImpl</attr>
</metadata>";
proj.Sources.Add (new BuildItem (BuildActions.Compile, "Fixup.cs") {
TextContent = () => @"using System;
using System.Collections.Generic;
using Android.App;
using Android.Runtime;
namespace Com.Ipaulpro.Afilechooser {
[Activity (Name = ""com.ipaulpro.afilechooser.FileChooserActivity"",
Icon = ""@drawable/ic_chooser"",
Exported = true)]
[IntentFilter (new string [] {""android.intent.action.GET_CONTENT""},
Categories = new string [] {
""android.intent.category.DEFAULT"",
//""android.intent.category.OPENABLE""
},
DataMimeType = ""*/*"")]
public partial class FileChooserActivity
{
}
public partial class FileListFragment : global::Android.Support.V4.App.ListFragment, global::Android.Support.V4.App.LoaderManager.ILoaderCallbacks {
public void OnLoadFinished (global::Android.Support.V4.Content.Loader p0, Java.Lang.Object p1)
{
OnLoadFinished (p0, (IList<Java.IO.File>) new JavaList<Java.IO.File> (p1.Handle, JniHandleOwnership.DoNotTransfer));
}
}
public partial class FileLoader : Android.Support.V4.Content.AsyncTaskLoader {
public override Java.Lang.Object LoadInBackground ()
{
return (Java.Lang.Object) LoadInBackgroundImpl ();
}
}
}"
});
using (var b = CreateDllBuilder ()) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
}
Expand Down Expand Up @@ -467,7 +430,6 @@ public void RemoveEventHandlerResolution ()
<attr path=""/api/package[@name='com.actionbarsherlock.view']"" name=""managedName"">Xamarin.ActionbarSherlockBinding.Views</attr>
</metadata>",
};
binding.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1);
using (var bindingBuilder = CreateDllBuilder (Path.Combine ("temp", "RemoveEventHandlerResolution", "Binding"))) {
Assert.IsTrue (bindingBuilder.Build (binding), "binding build should have succeeded");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,9 @@ public void CheckAssemblyCounts (bool isRelease, bool aot)
EmbedAssembliesIntoApk = true,
AotAssemblies = aot,
};
proj.PackageReferences.Add (KnownPackages.AndroidXMigration);
proj.PackageReferences.Add (KnownPackages.AndroidXAppCompat);
proj.PackageReferences.Add (KnownPackages.AndroidXAppCompatResources);
proj.PackageReferences.Add (KnownPackages.AndroidXBrowser);
proj.PackageReferences.Add (KnownPackages.AndroidXMediaRouter);
proj.PackageReferences.Add (KnownPackages.AndroidXLegacySupportV4);
proj.PackageReferences.Add (KnownPackages.AndroidXLifecycleLiveData);
proj.PackageReferences.Add (KnownPackages.XamarinGoogleAndroidMaterial);

var abis = new [] { "armeabi-v7a", "x86" };
proj.SetAndroidSupportedAbis (abis);
proj.SetRuntimeIdentifiers (abis);
proj.SetProperty (proj.ActiveConfigurationProperties, "AndroidUseAssemblyStore", "True");

using (var b = CreateApkBuilder ()) {
Expand Down Expand Up @@ -292,10 +284,6 @@ public void SmokeTestBuildWithSpecialCharacters ([Values (false, true)] bool for
proj.IsRelease = true;
proj.AotAssemblies = aot;

if (forms) {
proj.PackageReferences.Clear ();
proj.PackageReferences.Add (KnownPackages.XamarinForms_4_7_0_1142);
}
using (var builder = CreateApkBuilder (Path.Combine (rootPath, proj.ProjectName))){
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
}
Expand Down Expand Up @@ -450,19 +438,14 @@ public void ApplicationIdPlaceholder ()
public void ExtraAaptManifest ()
{
var proj = new XamarinAndroidApplicationProject ();
proj.MainActivity = proj.DefaultMainActivity.Replace ("base.OnCreate (bundle);", "base.OnCreate (bundle);\nCrashlytics.Crashlytics.HandleManagedExceptions();");
proj.PackageReferences.Add (KnownPackages.Xamarin_Android_Crashlytics);
proj.PackageReferences.Add (KnownPackages.Xamarin_Android_Fabric);
proj.MainActivity = proj.DefaultMainActivity.Replace ("base.OnCreate (bundle);", "base.OnCreate (bundle);\nFirebase.Crashlytics.FirebaseCrashlytics.Instance.SendUnsentReports();");
proj.PackageReferences.Add (new Package { Id = "Xamarin.Firebase.Crashlytics", Version = "118.5.1.1" });
proj.PackageReferences.Add (KnownPackages.Xamarin_Build_Download);
using (var builder = CreateApkBuilder (Path.Combine ("temp", TestName))) {
builder.Target = "Restore";
Assert.IsTrue (builder.Build (proj), "Restore should have succeeded.");
builder.Target = "Build";
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
var manifest = File.ReadAllText (Path.Combine (Root, builder.ProjectDirectory, "obj", "Debug", "android", "AndroidManifest.xml"));
Assert.IsTrue (manifest.Contains ($"android:authorities=\"{proj.PackageName}.crashlyticsinitprovider\""), "placeholder not replaced");
Assert.IsFalse (manifest.Contains ("dollar_openBracket_applicationId_closeBracket"), "`aapt/AndroidManifest.xml` not ignored");
}
using var builder = CreateApkBuilder ();
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
var manifest = File.ReadAllText (Path.Combine (Root, builder.ProjectDirectory, "obj", "Debug", "android", "AndroidManifest.xml"));
Assert.IsTrue (manifest.Contains ($"android:authorities=\"{proj.PackageName}.firebaseinitprovider\""), "placeholder not replaced");
Assert.IsFalse (manifest.Contains ("dollar_openBracket_applicationId_closeBracket"), "`aapt/AndroidManifest.xml` not ignored");
}

[Test]
Expand Down Expand Up @@ -714,7 +697,10 @@ public void BuildAfterUpgradingNuget ()
var proj = new XamarinAndroidApplicationProject ();
proj.MainActivity = proj.DefaultMainActivity.Replace ("public class MainActivity : Activity", "public class MainActivity : AndroidX.AppCompat.App.AppCompatActivity");

proj.PackageReferences.Add (KnownPackages.AndroidXAppCompat);
proj.PackageReferences.Add (new Package {
Id = "Xamarin.AndroidX.AppCompat",
Version = "1.6.1.5",
});

using (var b = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
//[TearDown] will still delete if test outcome successful, I need logs if assertions fail but build passes
Expand All @@ -732,8 +718,8 @@ public void BuildAfterUpgradingNuget ()
FileAssert.Exists (build_props, "build.props should exist after first build.");

proj.PackageReferences.Clear ();
//NOTE: we can get all the other dependencies transitively, yay!
proj.PackageReferences.Add (KnownPackages.AndroidXAppCompat_1_6_0_1);
//NOTE: this should be newer than specified above
proj.PackageReferences.Add (KnownPackages.AndroidXAppCompat);
b.Save (proj, doNotCleanupOnUpdate: true);
Assert.IsTrue (b.Build (proj), "second build should have succeeded.");
Assert.IsFalse (b.Output.IsTargetSkipped ("_CleanIntermediateIfNeeded"), "`_CleanIntermediateIfNeeded` should have run for the second build!");
Expand Down Expand Up @@ -1165,6 +1151,7 @@ public MyWorker (Context c, WorkerParameters p) : base (c, p) { }
"
});
proj.PackageReferences.Add (KnownPackages.AndroidXWorkRuntime);
proj.PackageReferences.Add (KnownPackages.AndroidXLifecycleLiveData);
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
}
Expand Down Expand Up @@ -1436,12 +1423,7 @@ public void CheckLintErrorsAndWarnings ()
{
string disabledIssues = "StaticFieldLeak,ObsoleteSdkInt,AllowBackup,ExportedReceiver,RedundantLabel";

var proj = new XamarinAndroidApplicationProject () {
PackageReferences = {
KnownPackages.AndroidSupportV4_27_0_2_1,
KnownPackages.SupportConstraintLayout_1_0_2_2,
},
};
var proj = new XamarinAndroidApplicationProject ();
proj.SetProperty ("AndroidLintEnabled", true.ToString ());
proj.SetProperty ("AndroidLintDisabledIssues", disabledIssues);
proj.SetProperty ("AndroidLintEnabledIssues", "");
Expand All @@ -1458,14 +1440,12 @@ public class MainActivity : Activity
TextContent = () => {
return @"<?xml version=""1.0"" encoding=""utf-8""?>
<ConstraintLayout xmlns:android=""http://schemas.android.com/apk/res/android""
xmlns:app=""http://schemas.android.com/apk/res-auto""
android:orientation=""vertical""
android:layout_width=""fill_parent""
android:layout_height=""fill_parent"">
<TextView android:id=""@+id/foo""
android:layout_width=""150dp""
android:layout_height=""wrap_content""
app:layout_constraintTop_toTopOf=""parent""
/>
</ConstraintLayout>";
}
Expand Down Expand Up @@ -1621,25 +1601,18 @@ public void DuplicateValuesInResourceCaseMap ()
[Test]
public void CheckLintResourceFileReferencesAreFixed ()
{
var proj = new XamarinAndroidApplicationProject () {
PackageReferences = {
KnownPackages.AndroidSupportV4_27_0_2_1,
KnownPackages.SupportConstraintLayout_1_0_2_2,
},
};
var proj = new XamarinAndroidApplicationProject ();
proj.SetProperty ("AndroidLintEnabled", true.ToString ());
proj.AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\layout\\test.axml") {
TextContent = () => {
return @"<?xml version=""1.0"" encoding=""utf-8""?>
<ConstraintLayout xmlns:android=""http://schemas.android.com/apk/res/android""
xmlns:app=""http://schemas.android.com/apk/res-auto""
android:orientation=""vertical""
android:layout_width=""fill_parent""
android:layout_height=""fill_parent"">
<TextView android:id=""@+id/foo""
android:layout_width=""150dp""
android:layout_height=""wrap_content""
app:layout_constraintTop_toTopOf=""parent""
/>
<EditText
android:id=""@+id/phone""
Expand Down
Loading

0 comments on commit 2f19238

Please sign in to comment.