diff --git a/src/Microsoft.Android.Templates/android-activity/Activity1.cs b/src/Microsoft.Android.Templates/android-activity/Activity1.cs
index f974a451ba3..e6d6f33c9a5 100644
--- a/src/Microsoft.Android.Templates/android-activity/Activity1.cs
+++ b/src/Microsoft.Android.Templates/android-activity/Activity1.cs
@@ -1,14 +1,9 @@
-using Android.App;
-using Android.OS;
-using Android.Runtime;
-using Android.Widget;
-
namespace AndroidApp1
{
[Activity(Label = "@string/app_name", MainLauncher = true)]
public class Activity1 : Activity
{
- protected override void OnCreate(Bundle savedInstanceState)
+ protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
diff --git a/src/Microsoft.Android.Templates/android-bindinglib/AndroidBinding1.csproj b/src/Microsoft.Android.Templates/android-bindinglib/AndroidBinding1.csproj
index 5a6a74ace70..2cf3b2f456a 100644
--- a/src/Microsoft.Android.Templates/android-bindinglib/AndroidBinding1.csproj
+++ b/src/Microsoft.Android.Templates/android-bindinglib/AndroidBinding1.csproj
@@ -3,5 +3,7 @@
net6.0-android
SUPPORTED_OS_PLATFORM_VERSION
AndroidBinding1
+ enable
+ enable
\ No newline at end of file
diff --git a/src/Microsoft.Android.Templates/android/AndroidApp1.csproj b/src/Microsoft.Android.Templates/android/AndroidApp1.csproj
index 1fd328a5c21..906e1314de1 100644
--- a/src/Microsoft.Android.Templates/android/AndroidApp1.csproj
+++ b/src/Microsoft.Android.Templates/android/AndroidApp1.csproj
@@ -4,5 +4,7 @@
SUPPORTED_OS_PLATFORM_VERSION
AndroidApp1
Exe
+ enable
+ enable
\ No newline at end of file
diff --git a/src/Microsoft.Android.Templates/android/MainActivity.cs b/src/Microsoft.Android.Templates/android/MainActivity.cs
index 7e49926946e..b48279dbee4 100644
--- a/src/Microsoft.Android.Templates/android/MainActivity.cs
+++ b/src/Microsoft.Android.Templates/android/MainActivity.cs
@@ -1,14 +1,9 @@
-using Android.App;
-using Android.OS;
-using Android.Runtime;
-using Android.Widget;
-
namespace AndroidApp1
{
[Activity(Label = "@string/app_name", MainLauncher = true)]
public class MainActivity : Activity
{
- protected override void OnCreate(Bundle savedInstanceState)
+ protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
diff --git a/src/Microsoft.Android.Templates/androidlib/AndroidLib1.csproj b/src/Microsoft.Android.Templates/androidlib/AndroidLib1.csproj
index 5eb4df59b23..46aa993fc7f 100644
--- a/src/Microsoft.Android.Templates/androidlib/AndroidLib1.csproj
+++ b/src/Microsoft.Android.Templates/androidlib/AndroidLib1.csproj
@@ -3,5 +3,7 @@
net6.0-android
SUPPORTED_OS_PLATFORM_VERSION
AndroidLib1
+ enable
+ enable
\ No newline at end of file
diff --git a/src/Microsoft.Android.Templates/androidlib/Class1.cs b/src/Microsoft.Android.Templates/androidlib/Class1.cs
index 1004d5770c0..5eebfbb4e60 100644
--- a/src/Microsoft.Android.Templates/androidlib/Class1.cs
+++ b/src/Microsoft.Android.Templates/androidlib/Class1.cs
@@ -1,5 +1,3 @@
-using System;
-
namespace AndroidLib1
{
public class Class1
diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/Sdk/AutoImport.props b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/Sdk/AutoImport.props
index fb26abb21e9..90843410620 100644
--- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/Sdk/AutoImport.props
+++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/Sdk/AutoImport.props
@@ -20,6 +20,12 @@ https://github.com/dotnet/designs/blob/4703666296f5e59964961464c25807c727282cae/
<_DefaultJavaSourceJarPattern>**\*-source.jar;**\*-sources.jar;**\*-src.jar
+
+
+
+
+
+
diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs
index 492df957658..a144287297f 100644
--- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs
+++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs
@@ -204,6 +204,7 @@ public void DotNetNew ([Values ("android", "androidlib", "android-bindinglib")]
Assert.IsTrue (dotnet.New ("android-activity"), "`dotnet new android-activity` should succeed");
Assert.IsTrue (dotnet.New ("android-layout", Path.Combine (dotnet.ProjectDirectory, "Resources", "layout")), "`dotnet new android-layout` should succeed");
Assert.IsTrue (dotnet.Build (), "`dotnet build` should succeed");
+ dotnet.AssertHasNoWarnings ();
}
[Test]
@@ -511,7 +512,7 @@ public void SupportedOSPlatformVersion ([Values (21, 30)] int minSdkVersion)
};
// Call AccessibilityTraversalAfter from API level 22
// https://developer.android.com/reference/android/view/View#getAccessibilityTraversalAfter()
- proj.MainActivity = proj.DefaultMainActivity.Replace ("button.Click", "button.AccessibilityTraversalAfter.ToString ();\nbutton.Click");
+ proj.MainActivity = proj.DefaultMainActivity.Replace ("button!.Click", "button!.AccessibilityTraversalAfter.ToString ();\nbutton!.Click");
var dotnet = CreateDotNetBuilder (proj);
Assert.IsTrue (dotnet.Build (), "`dotnet build` should succeed");
@@ -606,7 +607,7 @@ void CreateEmptyFile (params string [] paths)
public void XamarinLegacySdk ()
{
var proj = new XASdkProject (outputType: "Library") {
- Sdk = "Xamarin.Legacy.Sdk/0.1.0-alpha2",
+ Sdk = "Xamarin.Legacy.Sdk/0.1.0-alpha3",
Sources = {
new AndroidItem.AndroidLibrary ("javaclasses.jar") {
BinaryContent = () => ResourceData.JavaSourceJarTestJar,
diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownProperties.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownProperties.cs
index 43c92db5284..73c8cf3f888 100644
--- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownProperties.cs
+++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownProperties.cs
@@ -36,6 +36,8 @@ public static class KnownProperties
public const string AndroidFastDeploymentType = "AndroidFastDeploymentType";
public const string AndroidClassParser = "AndroidClassParser";
public const string _AndroidAllowDeltaInstall = "_AndroidAllowDeltaInstall";
+ public const string Nullable = "Nullable";
+ public const string ImplicitUsings = "ImplicitUsings";
}
}
diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XASdkProject.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XASdkProject.cs
index 6882724244f..623a21df08d 100644
--- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XASdkProject.cs
+++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XASdkProject.cs
@@ -28,7 +28,7 @@ static XASdkProject ()
var assembly = typeof (XASdkProject).Assembly;
using (var sr = new StreamReader (assembly.GetManifestResourceStream ("Xamarin.ProjectTools.Resources.Base.AndroidManifest.xml")))
default_android_manifest = sr.ReadToEnd ();
- using (var sr = new StreamReader (assembly.GetManifestResourceStream ("Xamarin.ProjectTools.Resources.Base.MainActivity.cs")))
+ using (var sr = new StreamReader (assembly.GetManifestResourceStream ("Xamarin.ProjectTools.Resources.DotNet.MainActivity.cs")))
default_main_activity_cs = sr.ReadToEnd ();
using (var sr = new StreamReader (assembly.GetManifestResourceStream ("Xamarin.ProjectTools.Resources.Base.LayoutMain.axml")))
default_layout_main = sr.ReadToEnd ();
@@ -61,6 +61,8 @@ public XASdkProject (string outputType = "Exe", [CallerMemberName] string packag
JavaPackageName = JavaPackageName ?? PackageName.ToLowerInvariant ();
GlobalPackagesFolder = FileSystemUtils.FindNugetGlobalPackageFolder ();
SetProperty (KnownProperties.OutputType, outputType);
+ SetProperty (KnownProperties.Nullable, "enable");
+ SetProperty (KnownProperties.ImplicitUsings, "enable");
// Add relevant Android content to our project without writing it to the .csproj file
if (outputType == "Exe") {
diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs
index a02e24fdd1b..2d1be00bb30 100644
--- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs
+++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs
@@ -24,7 +24,8 @@ public class XamarinAndroidApplicationProject : XamarinAndroidCommonProject
static XamarinAndroidApplicationProject ()
{
- using (var sr = new StreamReader (typeof(XamarinAndroidApplicationProject).Assembly.GetManifestResourceStream ("Xamarin.ProjectTools.Resources.Base.MainActivity.cs")))
+ var folder = Builder.UseDotNet ? "DotNet" : "Base";
+ using (var sr = new StreamReader (typeof(XamarinAndroidApplicationProject).Assembly.GetManifestResourceStream ($"Xamarin.ProjectTools.Resources.{folder}.MainActivity.cs")))
default_main_activity_cs = sr.ReadToEnd ();
using (var sr = new StreamReader (typeof(XamarinAndroidApplicationProject).Assembly.GetManifestResourceStream ("Xamarin.ProjectTools.Resources.Base.MainActivity.fs")))
default_main_activity_fs = sr.ReadToEnd ();
@@ -40,6 +41,8 @@ public XamarinAndroidApplicationProject (string debugConfigurationName = "Debug"
{
if (Builder.UseDotNet) {
SetProperty (KnownProperties.OutputType, "Exe");
+ SetProperty (KnownProperties.Nullable, "enable");
+ SetProperty (KnownProperties.ImplicitUsings, "enable");
SetProperty ("XamarinAndroidSupportSkipVerifyVersions", "True");
SetProperty ("_FastDeploymentDiagnosticLogging", "True");
@@ -81,7 +84,7 @@ public XamarinAndroidApplicationProject (string debugConfigurationName = "Debug"
}
// it is exposed as public because we may want to slightly modify this.
- public string DefaultMainActivity {
+ public virtual string DefaultMainActivity {
get { return Language == XamarinAndroidProjectLanguage.FSharp ? default_main_activity_fs : default_main_activity_cs; }
}
diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidLibraryProject.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidLibraryProject.cs
index 86b3142c557..2879f8cfa8b 100644
--- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidLibraryProject.cs
+++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidLibraryProject.cs
@@ -15,6 +15,8 @@ public XamarinAndroidLibraryProject (string debugConfigurationName = "Debug", st
: base (debugConfigurationName, releaseConfigurationName)
{
if (!Builder.UseDotNet) {
+ SetProperty (KnownProperties.Nullable, "enable");
+ SetProperty (KnownProperties.ImplicitUsings, "enable");
SetProperty ("AndroidApplication", "False");
SetProperty ("AndroidResgenFile", Path.Combine ("Resources", "Resource.designer.cs"));
}
diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinFormsAndroidApplicationProject.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinFormsAndroidApplicationProject.cs
index 1d740f477cf..9981e78a859 100644
--- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinFormsAndroidApplicationProject.cs
+++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinFormsAndroidApplicationProject.cs
@@ -42,6 +42,8 @@ public XamarinFormsAndroidApplicationProject (string debugConfigurationName = "D
: base (debugConfigurationName, releaseConfigurationName, packageName)
{
if (Builder.UseDotNet) {
+ // Don't opt into ImplicitUsings
+ RemoveProperty (KnownProperties.ImplicitUsings);
PackageReferences.Add (KnownPackages.XamarinForms_4_7_0_1142);
} else {
PackageReferences.Add (KnownPackages.XamarinForms_4_0_0_425677);
@@ -76,6 +78,8 @@ public XamarinFormsAndroidApplicationProject (string debugConfigurationName = "D
MainPage = MainPage_xaml_cs;
}
+ public override string DefaultMainActivity => default_main_activity_cs;
+
public string MainPage { get; set; }
protected virtual string MainPageXaml () => ProcessSourceTemplate (MainPage_xaml);
diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinFormsXASdkProject.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinFormsXASdkProject.cs
index e8f0e8ccc73..ddfb338d0ba 100644
--- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinFormsXASdkProject.cs
+++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinFormsXASdkProject.cs
@@ -44,6 +44,8 @@ static XamarinFormsXASdkProject ()
public XamarinFormsXASdkProject (string outputType = "Exe", [CallerMemberName] string packageName = "")
: base (outputType, packageName)
{
+ // Don't opt into ImplicitUsings
+ RemoveProperty (KnownProperties.ImplicitUsings);
PackageReferences.Add (KnownPackages.XamarinForms_4_7_0_1142);
// Workaround for AndroidX, see: https://github.com/xamarin/AndroidSupportComponents/pull/239
diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64SimpleDotNet.apkdesc b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64SimpleDotNet.apkdesc
index 755fbf3f522..1d79f0c8cdb 100644
--- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64SimpleDotNet.apkdesc
+++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64SimpleDotNet.apkdesc
@@ -23,7 +23,7 @@
"Size": 2676
},
"assemblies/UnnamedProject.dll": {
- "Size": 3171
+ "Size": 3535
},
"classes.dex": {
"Size": 316792
diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/DotNet/MainActivity.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/DotNet/MainActivity.cs
new file mode 100644
index 00000000000..ed408f5cf1b
--- /dev/null
+++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/DotNet/MainActivity.cs
@@ -0,0 +1,24 @@
+namespace ${ROOT_NAMESPACE}
+{
+ [Android.Runtime.Register ("${JAVA_PACKAGENAME}.MainActivity"), Activity (Label = "${PROJECT_NAME}", MainLauncher = true, Icon = "@drawable/icon")]
+ public class MainActivity : Activity
+ {
+ int count = 1;
+
+ protected override void OnCreate (Bundle? bundle)
+ {
+ base.OnCreate (bundle);
+
+ // Set our view from the "main" layout resource
+ SetContentView (Resource.Layout.Main);
+
+ var button = FindViewById