Skip to content

Commit 3f14705

Browse files
committed
Merge branch 'main' into dev/grendel/tmt-fix
* main: [monodroid] typemaps may need to load assemblies (#8625) Bump $(AndroidNetPreviousVersion) to 34.0.79 (#8693) Bump to xamarin/java.interop/main@07c73009 (#8681)
2 parents 3629d11 + 06b1d7f commit 3f14705

22 files changed

+147
-56
lines changed

Configuration.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<DebugType Condition=" '$(DebugType)' == '' ">portable</DebugType>
4444
<Deterministic Condition=" '$(Deterministic)' == '' ">True</Deterministic>
4545
<LangVersion Condition=" '$(LangVersion)' == '' ">latest</LangVersion>
46-
<AndroidNetPreviousVersion Condition=" '$(AndroidNetPreviousVersion)' == '' ">34.0.56</AndroidNetPreviousVersion>
46+
<AndroidNetPreviousVersion Condition=" '$(AndroidNetPreviousVersion)' == '' ">34.0.79</AndroidNetPreviousVersion>
4747
</PropertyGroup>
4848
<PropertyGroup Condition=" '$(HostOS)' == '' ">
4949
<HostOS Condition="$([MSBuild]::IsOSPlatform('windows'))">Windows</HostOS>

external/Java.Interop

src/Mono.Android/Java.Interop/TypeManager.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ internal static IJavaPeerable CreateInstance (IntPtr handle, JniHandleOwnership
267267
{
268268
Type? type = null;
269269
IntPtr class_ptr = JNIEnv.GetObjectClass (handle);
270-
string class_name = GetClassName (class_ptr);
270+
string? class_name = GetClassName (class_ptr);
271271
lock (TypeManagerMapDictionaries.AccessLock) {
272272
while (class_ptr != IntPtr.Zero && !TypeManagerMapDictionaries.JniToManaged.TryGetValue (class_name, out type)) {
273273

@@ -279,23 +279,33 @@ internal static IJavaPeerable CreateInstance (IntPtr handle, JniHandleOwnership
279279

280280
IntPtr super_class_ptr = JNIEnv.GetSuperclass (class_ptr);
281281
JNIEnv.DeleteLocalRef (class_ptr);
282+
class_name = null;
282283
class_ptr = super_class_ptr;
283-
class_name = GetClassName (class_ptr);
284+
if (class_ptr != IntPtr.Zero) {
285+
class_name = GetClassName (class_ptr);
286+
}
284287
}
285288
}
286289

287-
JNIEnv.DeleteLocalRef (class_ptr);
290+
if (class_ptr != IntPtr.Zero) {
291+
JNIEnv.DeleteLocalRef (class_ptr);
292+
class_ptr = IntPtr.Zero;
293+
}
294+
295+
if (targetType != null &&
296+
(type == null ||
297+
!targetType.IsAssignableFrom (type))) {
298+
type = targetType;
299+
}
288300

289301
if (type == null) {
302+
class_name = JNIEnv.GetClassNameFromInstance (handle);
290303
JNIEnv.DeleteRef (handle, transfer);
291304
throw new NotSupportedException (
292-
FormattableString.Invariant ($"Internal error finding wrapper class for '{JNIEnv.GetClassNameFromInstance (handle)}'. (Where is the Java.Lang.Object wrapper?!)"),
305+
FormattableString.Invariant ($"Internal error finding wrapper class for '{class_name}'. (Where is the Java.Lang.Object wrapper?!)"),
293306
CreateJavaLocationException ());
294307
}
295308

296-
if (targetType != null && !targetType.IsAssignableFrom (type))
297-
type = targetType;
298-
299309
if (type.IsInterface || type.IsAbstract) {
300310
var invokerType = JavaObjectExtensions.GetInvokerType (type);
301311
if (invokerType == null)

src/Xamarin.Android.Build.Tasks/Tasks/GenerateCompressedAssembliesNativeSourceFiles.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void GenerateCompressedAssemblySources ()
7474

7575
void Generate (IDictionary<string, CompressedAssemblyInfo> dict)
7676
{
77-
var composer = new CompressedAssembliesNativeAssemblyGenerator (dict);
77+
var composer = new CompressedAssembliesNativeAssemblyGenerator (Log, dict);
7878
LLVMIR.LlvmIrModule compressedAssemblies = composer.Construct ();
7979

8080
foreach (string abi in SupportedAbis) {

src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ void SaveResource (string resource, string filename, string destDir, Func<string
570570

571571
void WriteTypeMappings (List<JavaType> types, TypeDefinitionCache cache)
572572
{
573-
var tmg = new TypeMapGenerator ((string message) => Log.LogDebugMessage (message), SupportedAbis);
573+
var tmg = new TypeMapGenerator (Log, SupportedAbis);
574574
if (!tmg.Generate (Debug, SkipJniAddNativeMethodRegistrationAttributeScan, types, cache, TypemapOutputDirectory, GenerateNativeAssembly, out ApplicationConfigTaskState appConfState)) {
575575
throw new XamarinAndroidException (4308, Properties.Resources.XA4308);
576576
}

src/Xamarin.Android.Build.Tasks/Tasks/GenerateJniRemappingNativeCode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public override bool RunTask ()
5454

5555
void GenerateEmpty ()
5656
{
57-
Generate (new JniRemappingAssemblyGenerator (), typeReplacementsCount: 0);
57+
Generate (new JniRemappingAssemblyGenerator (Log), typeReplacementsCount: 0);
5858
}
5959

6060
void Generate ()
@@ -74,7 +74,7 @@ void Generate ()
7474
}
7575
}
7676

77-
Generate (new JniRemappingAssemblyGenerator (typeReplacements, methodReplacements), typeReplacements.Count);
77+
Generate (new JniRemappingAssemblyGenerator (Log, typeReplacements, methodReplacements), typeReplacements.Count);
7878
}
7979

8080
void Generate (JniRemappingAssemblyGenerator jniRemappingComposer, int typeReplacementsCount)

src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,13 @@ void AddEnvironment ()
386386

387387
if (enableMarshalMethods) {
388388
marshalMethodsAsmGen = new MarshalMethodsNativeAssemblyGenerator (
389+
Log,
389390
assemblyCount,
390391
uniqueAssemblyNames,
391-
marshalMethodsState?.MarshalMethods,
392-
Log
392+
marshalMethodsState?.MarshalMethods
393393
);
394394
} else {
395-
marshalMethodsAsmGen = new MarshalMethodsNativeAssemblyGenerator (assemblyCount, uniqueAssemblyNames);
395+
marshalMethodsAsmGen = new MarshalMethodsNativeAssemblyGenerator (Log, assemblyCount, uniqueAssemblyNames);
396396
}
397397
LLVMIR.LlvmIrModule marshalMethodsModule = marshalMethodsAsmGen.Construct ();
398398

src/Xamarin.Android.Build.Tasks/Tasks/JavaCompileToolTask.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ private void GenerateResponseFile ()
9090
file.Replace (@"\", @"\\").Normalize (NormalizationForm.FormC)));
9191
}
9292
}
93+
Log.LogDebugMessage ($"javac response file contents: {TemporarySourceListFile}");
94+
foreach (var line in File.ReadLines (TemporarySourceListFile)) {
95+
Log.LogDebugMessage ($" {line}");
96+
}
9397
}
9498
}
9599
}

src/Xamarin.Android.Build.Tasks/Tasks/R8.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using Microsoft.Build.Framework;
23
using Microsoft.Build.Utilities;
34
using System.Collections.Generic;
@@ -82,16 +83,15 @@ protected override CommandLineBuilder GetCommandLineBuilder ()
8283

8384
if (EnableShrinking) {
8485
if (!string.IsNullOrEmpty (AcwMapFile)) {
85-
var acwLines = File.ReadAllLines (AcwMapFile);
86+
var acwMap = MonoAndroidHelper.LoadMapFile (BuildEngine4, Path.GetFullPath (AcwMapFile), StringComparer.OrdinalIgnoreCase);
87+
var javaTypes = new List<string> (acwMap.Values.Count);
88+
foreach (var v in acwMap.Values) {
89+
javaTypes.Add (v);
90+
}
91+
javaTypes.Sort (StringComparer.Ordinal);
8692
using (var appcfg = File.CreateText (ProguardGeneratedApplicationConfiguration)) {
87-
for (int i = 0; i + 2 < acwLines.Length; i += 3) {
88-
try {
89-
var line = acwLines [i + 2];
90-
var java = line.Substring (line.IndexOf (';') + 1);
91-
appcfg.WriteLine ("-keep class " + java + " { *; }");
92-
} catch {
93-
// skip invalid lines
94-
}
93+
foreach (var java in javaTypes) {
94+
appcfg.WriteLine ($"-keep class {java} {{ *; }}");
9595
}
9696
}
9797
}

src/Xamarin.Android.Build.Tasks/Utilities/ApplicationConfigNativeAssemblyGenerator.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Java.Interop.Tools.TypeNameMappings;
77
using Microsoft.Build.Framework;
88
using Microsoft.Build.Utilities;
9+
using Microsoft.Android.Build.Tasks;
910
using Xamarin.Android.Tasks.LLVMIR;
1011

1112
namespace Xamarin.Android.Tasks
@@ -135,7 +136,6 @@ sealed class XamarinAndroidBundledAssembly
135136

136137
SortedDictionary <string, string>? environmentVariables;
137138
SortedDictionary <string, string>? systemProperties;
138-
TaskLoggingHelper log;
139139
StructureInstance? application_config;
140140
List<StructureInstance<DSOCacheEntry>>? dsoCache;
141141
List<StructureInstance<XamarinAndroidBundledAssembly>>? xamarinAndroidBundledAssemblies;
@@ -172,6 +172,7 @@ sealed class XamarinAndroidBundledAssembly
172172
public bool MarshalMethodsEnabled { get; set; }
173173

174174
public ApplicationConfigNativeAssemblyGenerator (IDictionary<string, string> environmentVariables, IDictionary<string, string> systemProperties, TaskLoggingHelper log)
175+
: base (log)
175176
{
176177
if (environmentVariables != null) {
177178
this.environmentVariables = new SortedDictionary<string, string> (environmentVariables, StringComparer.Ordinal);
@@ -180,8 +181,6 @@ public ApplicationConfigNativeAssemblyGenerator (IDictionary<string, string> env
180181
if (systemProperties != null) {
181182
this.systemProperties = new SortedDictionary<string, string> (systemProperties, StringComparer.Ordinal);
182183
}
183-
184-
this.log = log;
185184
}
186185

187186
protected override void Construct (LlvmIrModule module)
@@ -322,7 +321,7 @@ List<StructureInstance<DSOCacheEntry>> InitDSOCache ()
322321
continue;
323322
}
324323

325-
dsos.Add ((name, $"dsoName{dsos.Count.ToString (CultureInfo.InvariantCulture)}", ELFHelper.IsEmptyAOTLibrary (log, item.ItemSpec)));
324+
dsos.Add ((name, $"dsoName{dsos.Count.ToString (CultureInfo.InvariantCulture)}", ELFHelper.IsEmptyAOTLibrary (Log, item.ItemSpec)));
326325
}
327326

328327
var dsoCache = new List<StructureInstance<DSOCacheEntry>> ();

0 commit comments

Comments
 (0)