jpobst / Prototype.Android.MavenBindings

Prototype of MSBuild tasks to facilitate binding of Java libraries from Maven repositories
MIT License
5 stars 3 forks source link

Intercom #5

Closed kfrancis closed 1 year ago

kfrancis commented 1 year ago

So, I've long been searching for a way to create bindings without the annoying step of interacting with maven to get the aar file, so this is AMAZING.

That being said, try creating one for intercom. The SDK Base, for example, has a very large set of runtime dependencies so it's quite tedious setting that up: https://mvnrepository.com/artifact/io.intercom.android/intercom-sdk-base/14.2.0

image

So far, the base csproj is starting to look like this and I'm curious if I'm doing this right:

<ItemGroup>
    <PackageReference Include="GoogleGson" Version="2.10.1.1" />
    <PackageReference Include="Square.OkHttp3" Version="4.10.0.1" />
    <PackageReference Include="Xamarin.AndroidX.Annotation" Version="1.6.0" />
    <PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.6.1" />
    <PackageReference Include="Xamarin.AndroidX.ConstraintLayout" Version="2.1.4.3" />
    <PackageReference Include="Xamarin.AndroidX.Core.Core.Ktx" Version="1.9.0.2" />
    <PackageReference Include="Xamarin.AndroidX.DataBinding.ViewBinding" Version="7.4.2" />
    <PackageReference Include="Xamarin.AndroidX.ExifInterface" Version="1.3.6" />
    <PackageReference Include="Xamarin.AndroidX.Fragment.Ktx" Version="1.5.6" />
    <PackageReference Include="Xamarin.AndroidX.RecyclerView" Version="1.3.0" />
    <PackageReference Include="Xamarin.AndroidX.VectorDrawable" Version="1.1.0.16" />
    <PackageReference Include="Xamarin.AndroidX.VectorDrawable.Animated" Version="1.1.0.16" />
    <PackageReference Include="Xamarin.AndroidX.WebKit" Version="1.6.1" />
    <PackageReference Include="Xamarin.Google.Android.Material" Version="1.8.0" />
    <PackageReference Include="Xamarin.Kotlin.StdLib" Version="1.8.20" />
    <PackageReference Include="Xamarin.KotlinX.Coroutines.Core" Version="1.6.4.2" />
    <PackageReference Include="XamPrototype.Android.MavenBinding.Tasks" Version="0.0.7" />
</ItemGroup>
<ItemGroup>
    <AndroidMavenLibrary Include="io.intercom.android:intercom-sdk-base" Version="14.2.0" />
    <AndroidMavenLibrary Include="io.intercom.android:intercom-sdk-ui" Version="14.2.0" />
    <AndroidMavenLibrary Include="com.squareup.okhttp3:okhttp" Version="4.9.3" Bind="false" />
    <AndroidMavenLibrary Include="org.jetbrains.kotlin:kotlin-parcelize-runtime" Version="1.8.20" Bind="false" />
    <AndroidMavenLibrary Include="org.jetbrains.kotlin:kotlin-android-extensions-runtime" Version="1.5.20" Bind="false" />
</ItemGroup>
<ItemGroup>
  <ProjectReference Include="..\Intercom.Droid.Commons\Intercom.Droid.Commons.csproj" JavaArtifact="com.intercom:android-commons" JavaVersion="2.0.0" />
  <ProjectReference Include="..\Intercom.Droid.Composer.Gallery\Intercom.Droid.Composer.Gallery.csproj" JavaArtifact="com.intercom:android-composer-gallery" JavaVersion="3.3.3" />
  <ProjectReference Include="..\Intercom.Droid.Composer\Intercom.Droid.Composer.csproj" JavaArtifact="com.intercom:android-composer" JavaVersion="3.3.3" />
</ItemGroup>

For example, if I add one that it's complaining about:

Severity    Code    Description Project File    Line    Suppression State   Priority
Error       Maven dependency 'com.google.android.flexbox:flexbox' version '3.0.0' is not satisfied. Intercom.Droid.SDK.Base C:\Users\kfrancis\.nuget\packages\xamprototype.android.mavenbinding.tasks\0.0.7\build\XamPrototype.Android.MavenBinding.Tasks.targets   28      Normal

as <AndroidMavenLibrary Include="com.google.android.flexbox:flexbox" Version="3.0.0" Bind="false" /> then I get the error:

Severity    Code    Description Project File    Line    Suppression State   Priority
Error       Cannot download artifact 'com.google.android.flexbox:flexbox'.
- com.google.android.flexbox_flexbox.jar: Response status code does not indicate success: 404 (Not Found).
- com.google.android.flexbox_flexbox.aar: Response status code does not indicate success: 404 (Not Found).  Intercom.Droid.SDK.Base C:\Users\kfrancis\.nuget\packages\xamprototype.android.mavenbinding.tasks\0.0.7\build\XamPrototype.Android.MavenBinding.Tasks.targets   22      Normal

AFAIK, that entry should be correct based on the maven information: https://mvnrepository.com/artifact/com.google.android.flexbox/flexbox/3.0.0

jpobst commented 1 year ago

It looks like that dependency is hosted in Google's Maven and not Maven Central: https://maven.google.com/web/index.html?q=flexbox#com.google.android.flexbox:flexbox:3.0.0

Try adding Repository="Google" and see if that finds it. https://github.com/jpobst/Prototype.Android.MavenBindings/wiki/MavenDownloadTask-Advanced-Scenarios#googles-maven

kfrancis commented 1 year ago

Kind of like whack-a-mole, resolve one dep and find 10 more. Still working on it. Yes, that did seem to resolve that one. Still WIP

jpobst commented 1 year ago

Thanks for this feedback (and any future feedback!). You're probably the first person to actually try this out aside from my tests. 😁

I think a future improvement could be to create a .NET Global Tool or something that you would give it the Maven artifact information and it would generate an initial .csproj prepopulated with the correct dependencies. Or it could spit out the dependency MSBuild XML that could be copy/pasted into an existing .csproj.

kfrancis commented 1 year ago

I can absolutely see how that would work, and that would be amazing.

According to the GPT, it thinks "MavenDroidBind-o-Matic" could be a viable name of such a tool. I had a good laugh.