Skip to content

[mono] Add Android app sample using mono runtime #3944

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

Merged
merged 18 commits into from
Dec 14, 2020

Conversation

mdh1418
Copy link
Member

@mdh1418 mdh1418 commented Oct 30, 2020

Summary

This PR looks to port over the Android sample from dotnet/runtime to highlight the concept of building applications on top of the mono runtime.
There are several dependencies such as Android SDK, Android NDK, an Android emulator required to run the sample with dotnet publish.

The sample will depend on a NuGet Package containing the files that build the app and embed the mono runtime into the app, and the code that will build that package can be found here dotnet/runtime#43216

Currently, it is rebased off of #3931 and will be updated after the iOS sample is merged.


// it's not part of the BCL but runtime needs it for native-to-managed callbacks in AOT
// To be replaced with NativeCallableAttribute
public class MonoPInvokeCallbackAttribute : Attribute
Copy link
Member

@EgorBo EgorBo Oct 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably can get rid of it using Function Pointers for callbacks actually but I'm not sure, last time I checked - callbacks still needed it on Mono.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it's not needed for JIT (which is the only option for Android atm)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works after removing this block as well as the attributes. Does this still qualify as showing how the embedded mono runtime allows for C# and C to call each other with just the function pointers and Dllimport?

JNIEnv* jniEnv = GetJniEnv();

jclass mainActivity = (*jniEnv)->FindClass (jniEnv, "net/dot/MainActivity");
jmethodID getAge = (*jniEnv)->GetStaticMethodID(jniEnv, mainActivity, "getAge", "()I");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: FindClass won't work for Activity in non-UI thread afair.

@mdh1418
Copy link
Member Author

mdh1418 commented Nov 4, 2020

@adegeo Can the check run dotnet publish for these mono-samples rather than dotnet build

"dotnet build `"$projectFile`"" | Out-File ".\run.bat"
?

@mdh1418 mdh1418 force-pushed the mdhwang/add_android_sample branch 6 times, most recently from 7b7fcb2 to fc1cab5 Compare November 18, 2020 17:36
@mdh1418 mdh1418 force-pushed the mdhwang/add_android_sample branch 7 times, most recently from 6ec2dc0 to 7eca2bb Compare November 19, 2020 21:54
@mdh1418 mdh1418 force-pushed the mdhwang/add_android_sample branch from 7eca2bb to 664557b Compare November 20, 2020 15:34
@adegeo
Copy link
Contributor

adegeo commented Dec 11, 2020

@mdh1418

@adegeo Andy De George FTE Can the check run dotnet publish for these mono-samples rather than dotnet build

"dotnet build `"$projectFile`"" | Out-File ".\run.bat"

?

I just updated the script to allow custom commands. Add the snippets.5000.json file to the same folder as the AndroidSampleApp.csproj file with this content:

{
    "host": "custom",
    "command": "dotnet publish \"$projectFile\""
}

I'm not sure if you need to pull in the latest from master or not.

@mdh1418
Copy link
Member Author

mdh1418 commented Dec 14, 2020

Thanks @adegeo! I think the problems for these mono samples was the github actions runner being windows-latest. I don't think the support to build mono on Windows is there yet, so I opted to add a MacOS lane to verify that the samples build properly via dotnet publish. The related change #3953 would only run for PRs with changes to the mono sample.

@mdh1418 mdh1418 merged commit 8eb8eca into dotnet:master Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants