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

Add android sample #33

Closed
wants to merge 17 commits into from
Closed
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
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
- uses: actions/checkout@v1
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
- name: Install Workloads
run: dotnet workload install android android-aot wasm-tools --no-cache --disable-parallel --skip-manifest-update --source "https://aka.ms/dotnet6/nuget/index.json" --source "https://api.nuget.org/v3/index.json" --source "https://pkgs.dev.azure.com/azure-public/vside/_packaging/xamarin-impl/nuget/v3/index.json"
- name: Build Release
run: dotnet build --configuration Release
- name: Test Release
Expand Down
8 changes: 8 additions & 0 deletions NodeEditor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ ProjectSection(SolutionItems) = preProject
build\Avalonia.Controls.PanAndZoom.props = build\Avalonia.Controls.PanAndZoom.props
build\ReactiveUI.props = build\ReactiveUI.props
build\Avalonia.Skia.props = build\Avalonia.Skia.props
build\Avalonia.Android.props = build\Avalonia.Android.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_build", "build\build\_build.csproj", "{0737F4A8-E674-4518-A362-0A78D03F8165}"
Expand All @@ -72,6 +73,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NodeEditor.Base", "samples\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NodeEditor.Web", "samples\NodeEditor.Web\NodeEditor.Web.csproj", "{FE2664AE-527E-4044-A53E-6D4523857F98}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NodeEditor.Android", "samples\NodeEditor.Android\NodeEditor.Android.csproj", "{6C48DAEB-611A-4A58-89C1-5A8737E218EE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -118,6 +121,10 @@ Global
{FE2664AE-527E-4044-A53E-6D4523857F98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE2664AE-527E-4044-A53E-6D4523857F98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE2664AE-527E-4044-A53E-6D4523857F98}.Release|Any CPU.Build.0 = Release|Any CPU
{6C48DAEB-611A-4A58-89C1-5A8737E218EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C48DAEB-611A-4A58-89C1-5A8737E218EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C48DAEB-611A-4A58-89C1-5A8737E218EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C48DAEB-611A-4A58-89C1-5A8737E218EE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{861D1DD2-FDE9-492E-AEF6-E00F92F61EBD} = {02D6D6DC-21FA-435F-9526-E6F635127483}
Expand All @@ -133,5 +140,6 @@ Global
{EE456454-F26E-4905-8889-5660272C4EC4} = {02D6D6DC-21FA-435F-9526-E6F635127483}
{1AC073FC-6F01-4F5B-AE78-17EE10F74D37} = {EA2546EB-E043-4411-92D2-96AF60E6EC70}
{FE2664AE-527E-4044-A53E-6D4523857F98} = {EA2546EB-E043-4411-92D2-96AF60E6EC70}
{6C48DAEB-611A-4A58-89C1-5A8737E218EE} = {EA2546EB-E043-4411-92D2-96AF60E6EC70}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions build/Avalonia.Android.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.Android" Version="0.10.999-cibuild0018647-beta" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.Desktop.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="0.10.12" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.999-cibuild0018647-beta" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.Diagnostics.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.12" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.999-cibuild0018647-beta" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.ReactiveUI.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.12" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.999-cibuild0018647-beta" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.Skia.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.Skia" Version="0.10.12" />
<PackageReference Include="Avalonia.Skia" Version="0.10.999-cibuild0018647-beta" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.Web.Blazor.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.Web.Blazor" Version="0.10.12" />
<PackageReference Include="Avalonia.Web.Blazor" Version="0.10.999-cibuild0018647-beta" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.12" />
<PackageReference Include="Avalonia" Version="0.10.999-cibuild0018647-beta" />
</ItemGroup>
</Project>
47 changes: 47 additions & 0 deletions samples/NodeEditor.Android/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Android.App;
using Android.Content.PM;
using Android.OS;
using Avalonia;
using Avalonia.Android;
using NodeEditorDemo;
using NodeEditorDemo.ViewModels;
using NodeEditorDemo.Views;

namespace NodeEditor.Android
{
[Activity(Label = "NodeEditor",
MainLauncher = true,
Icon = "@drawable/icon",
LaunchMode = LaunchMode.SingleInstance,
ScreenOrientation = ScreenOrientation.Landscape)]
public class MainBaseActivity : AvaloniaActivity
{
static MainBaseActivity()
{
App.EnableInputOutput = true;
}

protected override void OnCreate(Bundle savedInstanceState)
{
if (Avalonia.Application.Current == null)
{
AppBuilder.Configure<App>()
.UseAndroid()
.SetupWithoutStarting();
}

base.OnCreate(savedInstanceState);

var mainView = new MainView
{
DataContext = new MainWindowViewModel
{
IsEditMode = true,
IsToolboxVisible = false
}
};

Content = mainView;
}
}
}
34 changes: 34 additions & 0 deletions samples/NodeEditor.Android/NodeEditor.Android.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-android</TargetFramework>
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<ApplicationId>com.NodeEditor.Android</ApplicationId>
<ApplicationVersion>1</ApplicationVersion>
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<AndroidPackageFormat>apk</AndroidPackageFormat>
<MSBuildEnableWorkloadResolver>true</MSBuildEnableWorkloadResolver>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release' and '$(TF_BUILD)' == ''">
<DebugSymbols>True</DebugSymbols>
<RunAOTCompilation>True</RunAOTCompilation>
<EnableLLVM>True</EnableLLVM>
<!--<AndroidEnableProfiledAot>True</AndroidEnableProfiledAot>-->
</PropertyGroup>

<ItemGroup>
<None Remove="Assets\AboutAssets.txt" />
</ItemGroup>


<Import Project="..\..\build\Avalonia.props" />
<Import Project="..\..\build\Avalonia.Android.props" />

<ItemGroup>
<ProjectReference Include="..\NodeEditor.Base\NodeEditor.Base.csproj" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions samples/NodeEditor.Android/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:label="NodeEditor.Android" android:icon="@drawable/Icon" android:hardwareAccelerated="true"></application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net6.0-android\publish\android-arm\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net6.0-android</TargetFramework>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>android-arm</RuntimeIdentifier>
<PublishSingleFile>false</PublishSingleFile>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>
</Project>
50 changes: 50 additions & 0 deletions samples/NodeEditor.Android/Resources/AboutResources.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Images, layout descriptions, binary blobs and string dictionaries can be included
in your application as resource files. Various Android APIs are designed to
operate on the resource IDs instead of dealing with images, strings or binary blobs
directly.

For example, a sample Android app that contains a user interface layout (main.xml),
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
would keep its resources in the "Resources" directory of the application:

Resources/
drawable-hdpi/
icon.png

drawable-ldpi/
icon.png

drawable-mdpi/
icon.png

layout/
main.xml

values/
strings.xml

In order to get the build system to recognize Android resources, set the build action to
"AndroidResource". The native Android APIs do not operate directly with filenames, but
instead operate on resource IDs. When you compile an Android application that uses resources,
the build system will package the resources for distribution and generate a class called
"Resource" that contains the tokens for each one of the resources included. For example,
for the above Resources layout, this is what the Resource class would expose:

public class Resource {
public class drawable {
public const int icon = 0x123;
}

public class layout {
public const int main = 0x456;
}

public class strings {
public const int first_string = 0xabc;
public const int second_string = 0xbcd;
}
}

You would then use R.drawable.icon to reference the drawable/icon.png file, or Resource.layout.main
to reference the layout/main.xml file, or Resource.strings.first_string to reference the first
string in the dictionary file values/strings.xml.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions samples/NodeEditor.Android/Resources/values/Strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>
<string name="ApplicationName">NodeEditor.Android</string>
</resources>