How to include Android binding dependencies and avoid ClassNotFoundExceptions
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- ドキュメント
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- android, csharp
- 領域
- documentation, mobile
調査の方向性
Facebook サンプルの build.gradle.kts と Sample.csproj から始め、リンクされている Java Dependency Verification と Resolving Java Dependencies のドキュメントを読んでください。サンプルをビルドして、XA4241 と XA4242 の依存関係出力を確認してください。Maven アーティファクトの宣言方法、報告された依存関係の評価方法、ClassNotFoundExceptions なしでデプロイを検証する方法が文書化されていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Handling transitive dependencies is common challenge with .NET for Android and Android Native Library Interop binding projects when attempting to bind a Maven artifact. This story is further complicated by the fact that .NET for Android binds and redistributes AndroidX and other support libraries via NuGet packages, and MAUI projects depend on a handful of these libraries.
Starting in .NET 9 there are a few build items that can be used to help validate your Java dependency tree which are outlined in the Java Dependency Verification and Resolving Java Dependencies docs.
We can look at the Facebook sample in this repo for an example on how to use these items with Native Library Interop. Here's a quick overview of how the various pieces fit together.
- In your
build.gradle.ktsfile, declare the Maven artifact(s) you are interested in binding: https://github.com/CommunityToolkit/Maui.NativeLibraryInterop/blob/e91dadd35f0c4ceb333034c3fd7b3c6ceebf4c94/facebook/android/native/mauifacebook/build.gradle.kts#L31 - In your application project, add the same Maven artifact(s) as an
@(AndroidMavenLibrary)item. Set the%(Bind)metadata to false; we do not want to bind this artifact again. We are only including this reference to opt-in to the Java dependency verification system mentioned above to figure out which artifact dependencies we will need to bring into the app:
<AndroidMavenLibrary Include="com.facebook.android:facebook-android-sdk" Version="17.0.2" Bind="false" />
- Build your application project, and you should see a list of unfulfilled dependencies:
error XA4241: Java dependency 'com.facebook.android:facebook-core:17.0.2' is not satisfied.
error XA4241: Java dependency 'com.facebook.android:facebook-common:17.0.2' is not satisfied.
error XA4241: Java dependency 'com.facebook.android:facebook-login:17.0.2' is not satisfied.
error XA4241: Java dependency 'com.facebook.android:facebook-share:17.0.2' is not satisfied.
error XA4241: Java dependency 'com.facebook.android:facebook-applinks:17.0.2' is not satisfied.
error XA4241: Java dependency 'com.facebook.android:facebook-messenger:17.0.2' is not satisfied.
error XA4241: Java dependency 'com.facebook.android:facebook-gamingservices:17.0.2' is not satisfied.
error XA4242: Java dependency 'org.jetbrains.kotlin:kotlin-stdlib:1.5.10' is not satisfied. Microsoft maintains the NuGet package 'Xamarin.Kotlin.StdLib' that could fulfill this dependency.
- It's recommended that you include all of the dependencies listed in this output in your application project. However, given the scope of what you are trying to bind, you can try to reason about which of these dependencies you could safely exclude. In the case of the Facebookj sample, I replaced the
facebook-android-sdkdependency with the first dependency listed above (facebook-core) and rebuilt:
https://github.com/CommunityToolkit/Maui.NativeLibraryInterop/blob/e91dadd35f0c4ceb333034c3fd7b3c6ceebf4c94/facebook/sample/Sample.csproj#L65
error XA4241: Java dependency 'com.facebook.android:facebook-bolts:17.0.2' is not satisfied.
error XA4242: Java dependency 'androidx.annotation:annotation:1.1.0' is not satisfied. Microsoft maintains the NuGet package 'Xamarin.AndroidX.Annotation' that could fulfill this dependency.
error XA4242: Java dependency 'androidx.legacy:legacy-support-core-utils:1.0.0' is not satisfied. Microsoft maintains the NuGet package 'Xamarin.AndroidX.Legacy.Support.Core.Utils' that could fulfill this dependency.
error XA4242: Java dependency 'com.android.installreferrer:installreferrer:1.0' is not satisfied. Microsoft maintains the NuGet package 'Xamarin.Google.Android.InstallReferrer' that could fulfill this dependency.
error XA4242: Java dependency 'androidx.core:core-ktx:1.3.2' is not satisfied. Microsoft maintains the NuGet package 'Xamarin.AndroidX.Core.Core.Ktx' that could fulfill this dependency.
error XA4242: Java dependency 'org.jetbrains.kotlin:kotlin-stdlib:1.5.10' is not satisfied. Microsoft maintains the NuGet package 'Xamarin.Kotlin.StdLib' that could fulfill this dependency.
- After adding the full set of dependencies you should be able to deploy and run the application on an emulator or device. If you are attempting to only include a subset you may encounter a crash at runtime and likely need to return to the list from step 3 and start adding back any dependencies that were excluded.
The live Facebook sample code demonstrates the end result of this iterative process, and contains a trimmed down list of dependencies that were initially presented. These were the only dependencies required to light up the small code path I was trying to bind. This solution is not perfect and can still lead to unexpected behavior due to the complexity and size of some Maven artifacts.
We should continue to build out better documentation around these challenges and potential solutions. We're also hoping to continue to make improvements to this area of the .NET for Android binding experience in the future.
Please feel free to also use this issue to provide feedback on how this process interacts with Native Library Interop.
- 主要言語
- C#
- スター
- 249
- フォーク
- 48
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
CommunityToolkit/Maui.NativeLibraryInterop のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
CommunityToolkit/Maui.NativeLibraryInterop#107 · コメント 8 件 · リアクション 1 件 ·
-
Android dependenciesオープン
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
CommunityToolkit/Maui.NativeLibraryInterop#106 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
CommunityToolkit/Maui.NativeLibraryInterop#105 · コメント 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 3/5 3〜5日 初心者へのやさしさ 30/100
CommunityToolkit/Maui.NativeLibraryInterop#101 · コメント 3 件 · リアクション 4 件 ·
CommunityToolkit/Maui.NativeLibraryInterop の issue をすべて見る
似ている issue
-
area-ai untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
dotnet/extensions#7790 ·
メンテナーはふだん 1 日以内に返信
-
P2 testing
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
area-Infrastructure-coreclr os-ios os-maccatalyst os-tvos untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dotnet/runtime#134766 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
0 - Backlog Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
BrighterCommand/Brighter#4444 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信