Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpeppers committed Jan 31, 2024
1 parent bd8df92 commit 8646605
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,20 @@ A breakdown of the files inside:

`libdotnet.so` is ~1.9MB, and `libSkiaSharp.so` is ~8.5MB!

If we reduce this to a "Hello World" example:

* `hello.apk` is ~561 KB!
* `libdotnet.so` (uncompressed) is ~1.1 MB

## "Hello World" Example

See the [HelloWorld](https://github.com/jonathanpeppers/Android-NativeAOT/tree/HelloWorld) branch.

I had this managed code:

```csharp
[UnmanagedCallersOnly(EntryPoint = "ManagedAdd")]
public static int ManagedAdd(int x, int y)
{
Console.WriteLine($"ManagedAdd({x}, {y})");
return x + y;
}
public static int ManagedAdd(int x, int y) => x + y;
```

I created a C++ Android project using NativeActivity, and I called the managed
Expand All @@ -91,13 +94,14 @@ extern "C" int ManagedAdd(int x, int y);

// in native-lib.cpp
int result = ManagedAdd(1, 2);
__android_log_print (ANDROID_LOG_INFO, "Native", "ManagedAdd(1, 2) returned: %i", result);
__android_log_print (ANDROID_LOG_INFO, TAG, "ManagedAdd(1, 2) returned: %i", result);
```
Results in the message:
```log
01-29 10:41:04.363 11016 11042 I Native : ManagedAdd(1, 2) returned: 3
01-31 11:42:44.545 28239 28259 I NATIVE : Entering android_main
01-31 11:42:44.550 28239 28259 I NATIVE : ManagedAdd(1, 2) returned: 3
```

See [DotNet/README.md](DotNet/README.md) on how to build `libdotnet.so`.
Expand Down

0 comments on commit 8646605

Please sign in to comment.