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

Re-fix macOS host + linux-bionic-arm64 target cross-compile #10

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
19 changes: 14 additions & 5 deletions DotNet/libdotnet.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@
</PropertyGroup>

<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith('linux-bionic'))">
<LinkStandardCPlusPlusLibrary>true</LinkStandardCPlusPlusLibrary>
<CppCompilerAndLinker>$(_NdkBinDir)/$(_NdkClangPrefix)clang++</CppCompilerAndLinker>
<ObjCopyName>$(_NdkBinDir)/llvm-objcopy</ObjCopyName>
</PropertyGroup>

<ItemGroup Condition="$(RuntimeIdentifier.StartsWith('linux-bionic'))">
<LinkerArg Include="-Wl,--defsym,_init=__libc_init" />
<LinkerArg Include="-Wl,--defsym,_fini=__libc_fini" />
<LinkerArg Include="-L &quot;$(_NdkSysrootDir)&quot;" />
<NativeSystemLibrary Include="c" />
<LinkerArg Include="-Wl,--undefined-version" />
</ItemGroup>

<Target Name="_ValidateEnvironment"
Expand All @@ -32,4 +28,17 @@
Text="NDK 'sysroot' dir `$(_NdkSysrootDir)` does not exist. You're on your own."
/>
</Target>

<Target Name="_CopyLibcppShared"
AfterTargets="Publish">
<PropertyGroup>
<_JniLibsDir>../Native/app/src/main/jniLibs/arm64-v8a</_JniLibsDir>
</PropertyGroup>
<MakeDir Directories="../Native/app/src/main/jniLibs/arm64-v8a" />
<ItemGroup>
<_Source Include="$(_NdkSysrootDir)\libc++_shared.so" />
<_Target Include="$(_JniLibsDir)\libc++_shared.so" />
</ItemGroup>
<Copy SourceFiles="@(_Source)" DestinationFiles="@(_Target)" />
</Target>
</Project>
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@

A .NET 8, NativeAOT example on Android.

## Getting started

Configure your environment: the following environment variables are required:

* `ANDROID_NDK_HOME`: The path to an Android NDK installation.
* `ANDROID_HOME`: The path to an Android SDK installation.

Build the project:

```console
dotnet build
dotnet publish DotNet/libdotnet.csproj
(cd Native && ./gradlew assembleRelease)
```

Install the app:

```console
$ANDROID_HOME/platform-tools/adb install Native/app/build/outputs/apk/release/app-release.apk
```

Run the app:

```console
$ANDROID_HOME/platform-tools/adb shell am start com.jonathanpeppers.nativeaot/android.app.NativeActivity
```

## Example using SkiaSharp

This sample has a C++ Android Studio project:
Expand Down