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

[Xamarin.Android.Build.Tasks] <GenerateJavaStubs /> generates a shorter acw-map.txt #1131

Merged
merged 1 commit into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion external/Java.Interop
2 changes: 1 addition & 1 deletion src/Mono.Android/Android.Runtime/JNIEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ public static string GetJniName (Type type)
{
if (type == null)
throw new ArgumentNullException ("type");
var java = monodroid_typemap_managed_to_java (type.AssemblyQualifiedName);
var java = monodroid_typemap_managed_to_java (type.FullName + ", " + type.Assembly.GetName ().Name);
return java == IntPtr.Zero
? JavaNativeTypeManager.ToJniName (type)
: Marshal.PtrToStringAnsi (java);
Expand Down
13 changes: 9 additions & 4 deletions src/Mono.Android/Test/Java.Interop/JnienvTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,18 @@ public void JavaToManagedTypeMapping ()
[DllImport ("__Internal")]
static extern IntPtr monodroid_typemap_managed_to_java (string java);

string GetTypeName (Type type)
{
return type.FullName + ", " + type.Assembly.GetName ().Name;
}

[Test]
public void ManagedToJavaTypeMapping ()
{
var m = monodroid_typemap_managed_to_java (typeof (Activity).AssemblyQualifiedName);
Assert.AreNotEqual (IntPtr.Zero, m);
m = monodroid_typemap_managed_to_java (typeof (JnienvTest).AssemblyQualifiedName);
Assert.AreEqual (IntPtr.Zero, m);
var m = monodroid_typemap_managed_to_java (GetTypeName (typeof (Activity)));
Assert.AreNotEqual (IntPtr.Zero, m, "`Activity` subclasses Java.Lang.Object, it should be in the typemap!");
m = monodroid_typemap_managed_to_java (GetTypeName (typeof (JnienvTest)));
Assert.AreEqual (IntPtr.Zero, m, "`JnienvTest` does *not* subclass Java.Lang.Object, it should *not* be in the typemap!");
}

[Test]
Expand Down
1 change: 0 additions & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ void Run (DirectoryAssemblyResolver res)
string javaKey = JavaNativeTypeManager.ToJniName (type).Replace ('/', '.');

acw_map.WriteLine ("{0};{1}", type.GetPartialAssemblyQualifiedName (), javaKey);
acw_map.WriteLine ("{0};{1}", type.GetAssemblyQualifiedName (), javaKey);

TypeDefinition conflict;
if (managed.TryGetValue (managedKey, out conflict)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
Expand Down Expand Up @@ -174,6 +175,33 @@ public void BuildApplicationWithLibraryAndClean ([Values (false, true)] bool isR
}
}

[Test]
public void BuildIncrementingAssemblyVersion ()
{
var proj = new XamarinAndroidApplicationProject ();
proj.Sources.Add (new BuildItem ("Compile", "AssemblyInfo.cs") {
TextContent = () => "[assembly: System.Reflection.AssemblyVersion (\"1.0.0.*\")]"
});

using (var b = CreateApkBuilder ("temp/BuildIncrementingAssemblyVersion")) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");

var acwmapPath = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "acw-map.txt");
var assemblyPath = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, "UnnamedProject.dll");
var firstAssemblyVersion = AssemblyName.GetAssemblyName (assemblyPath).Version;
var expectedAcwMap = File.ReadAllText (acwmapPath);

b.Target = "Rebuild";
b.BuildLogFile = "rebuild.log";
Assert.IsTrue (b.Build (proj), "Rebuild should have succeeded.");

var secondAssemblyVersion = AssemblyName.GetAssemblyName (assemblyPath).Version;
Assert.AreNotEqual (firstAssemblyVersion, secondAssemblyVersion);
var actualAcwMap = File.ReadAllText (acwmapPath);
Assert.AreEqual (expectedAcwMap, actualAcwMap);
}
}

[Test]
public void BuildMkBundleApplicationRelease ()
{
Expand Down