[mono] Enable System.Runtime.Tests on Android (#36655)
authorEgor Bogatov <egorbo@gmail.com>
Tue, 19 May 2020 11:08:03 +0000 (14:08 +0300)
committerGitHub <noreply@github.com>
Tue, 19 May 2020 11:08:03 +0000 (14:08 +0300)
.config/dotnet-tools.json
src/libraries/System.Runtime/tests/System/Type/TypeTests.cs
src/mono/netcore/sample/Android/Makefile
src/mono/netcore/sample/Android/Program.csproj
tools-local/tasks/mobile.tasks/AndroidAppBuilder/ApkBuilder.cs
tools-local/tasks/mobile.tasks/AndroidAppBuilder/Templates/runtime-android.c

index fa00191..fcd0903 100644 (file)
@@ -15,7 +15,7 @@
       ]
     },
     "microsoft.dotnet.xharness.cli": {
-      "version": "1.0.0-prerelease.20264.9",
+      "version": "1.0.0-prerelease.20265.8",
       "commands": [
         "xharness"
       ]
index 7f8cd63..d45b52c 100644 (file)
@@ -688,6 +688,8 @@ namespace System.Tests
 
         [Theory]
         [MemberData(nameof(GetInterfaceMap_TestData))]
+        // Android-only, change to TestPlatforms.Android once arcade dependency is updated
+        [ActiveIssue("https://github.com/dotnet/runtime/issues/36653", TestRuntimes.Mono)]
         public void GetInterfaceMap(Type interfaceType, Type classType, Tuple<MethodInfo, MethodInfo>[] expectedMap)
         {
             InterfaceMapping actualMapping = classType.GetInterfaceMap(interfaceType);
index 32d038d..80211c3 100644 (file)
@@ -11,7 +11,7 @@ runtimepack:
        ../../../../.././build.sh Mono+Libs -os Android -arch $(MONO_ARCH) -c $(MONO_CONFIG)
 
 apk: clean appbuilder
-       $(DOTNET) publish -c Release -r android-$(MONO_ARCH) \
+       $(DOTNET) publish -c $(MONO_CONFIG) -r android-$(MONO_ARCH) \
        /p:Platform=$(MONO_ARCH) /p:DeployAndRun=true
 
 clean:
index d7516dc..406e6fa 100644 (file)
     <Message Importance="High" Text="Apk:       $(ApkBundlePath)"/>
     <Message Importance="High" Text="PackageId: $(ApkPackageId)"/>
 
+    <Exec Condition="'$(DeployAndRun)' == 'true'" Command="$(AdbTool) kill-server"/>
+    <Exec Condition="'$(DeployAndRun)' == 'true'" Command="$(AdbTool) start-server"/>
+    <Exec Condition="'$(DeployAndRun)' == 'true'" Command="$(AdbTool) logcat -c" />
     <Message Condition="'$(DeployAndRun)' == 'true'" Importance="High" Text="Uninstalling app if it exists (throws an error if it doesn't but it can be ignored):"/>
     <Exec Condition="'$(DeployAndRun)' == 'true'" Command="$(AdbTool) uninstall net.dot.HelloAndroid" ContinueOnError="WarnAndContinue" />
     <Exec Condition="'$(DeployAndRun)' == 'true'" Command="$(AdbTool) install $(ApkDir)/bin/HelloAndroid.apk" />
     <Exec Condition="'$(DeployAndRun)' == 'true'" Command="$(AdbTool) shell am instrument -w net.dot.HelloAndroid/net.dot.MonoRunner" />
+    <Exec Condition="'$(DeployAndRun)' == 'true'" Command="$(AdbTool) logcat -d -s DOTNET" />
   </Target>
 </Project>
index b252a46..409cbb5 100644 (file)
@@ -140,7 +140,8 @@ public class ApkBuilder
         File.WriteAllText(Path.Combine(OutputDir, "CMakeLists.txt"), cmakeLists);
 
         string runtimeAndroidSrc = Utils.GetEmbeddedResource("runtime-android.c")
-            .Replace("%EntryPointLibName%", Path.GetFileName(entryPointLib));
+            .Replace("%EntryPointLibName%", Path.GetFileName(entryPointLib)
+            .Replace("%RID%", GetRid(abi)));
         File.WriteAllText(Path.Combine(OutputDir, "runtime-android.c"), runtimeAndroidSrc);
         
         string cmakeGenArgs = $"-DCMAKE_TOOLCHAIN_FILE={androidToolchain} -DANDROID_ABI=\"{abi}\" -DANDROID_STL=none " + 
@@ -236,6 +237,14 @@ public class ApkBuilder
 
         return (alignedApk, packageId);
     }
+
+    private static string GetRid(string abi) => abi switch 
+        {
+            "arm64-v8a" => "android-arm64",
+            "armeabi-v7a" => "android-arm",
+            "x86_64" => "android-x64",
+            _ => "android-" + abi
+        };
     
     /// <summary>
     /// Scan android SDK for build tools (ignore preview versions)
index 8cfdaaf..4a2af6a 100644 (file)
@@ -146,7 +146,16 @@ mono_mobile_runtime_init (void)
     chdir (bundle_path);
 
     // TODO: set TRUSTED_PLATFORM_ASSEMBLIES, APP_PATHS and NATIVE_DLL_SEARCH_DIRECTORIES
-    monovm_initialize(0, NULL, NULL);
+
+    const char* appctx_keys[2];
+    appctx_keys[0] = "RUNTIME_IDENTIFIER";
+    appctx_keys[1] = "APP_CONTEXT_BASE_DIRECTORY";
+
+    const char* appctx_values[2];
+    appctx_values[0] = "%RID%";
+    appctx_values[1] = bundle_path;
+    
+    monovm_initialize(2, appctx_keys, appctx_values);
 
     mono_debug_init (MONO_DEBUG_FORMAT_MONO);
     mono_install_assembly_preload_hook (assembly_preload_hook, NULL);