admin管理员组

文章数量:1125111

I need to create remote worker on a separate thread. I'm following this answer for things I need to do and I'm stuck at declaring dependencies.

I need to add implementation "androidx.work:work-multiprocess:$work_version" somewhere. How do I do that in .NET Android project?

I'm using Xamarin.AndroidX.Work.Runtime 2.10.0.1 package to work with workers.

here's the application section in my manifest

<application android:allowBackup="true" android:icon="@mipmap/appicon" android:label="@string/app_name" android:supportsRtl="true">
    <provider
     android:name="androidx.startup.InitializationProvider"
     android:authorities="${applicationId}.androidx-startup"
     android:exported="false"
     tools:node="merge" >
      <meta-data
          android:name="androidx.work.WorkManagerInitializer"
          android:value="androidx.startup"
          tools:node="remove" />
    </provider>
    <service
    android:name="androidx.work.multiprocess.RemoteWorkManagerService"
    tools:replace="android:process"
    android:process=":ffmpegWorker"/>

    <service
        android:name="androidx.work.impl.background.systemjob.SystemJobService"
        tools:replace="android:process"
        android:process=":ffmpegWorker"/>

  </application>

In my MainActivity RemoteWorkManager.GetInstance(BaseContext) throws the following error:

Java.Lang.IllegalStateException: Invalid multiprocess configuration. Define an 'implementation' dependency on :work:work-multiprocess library

   var inputData = new Data.Builder()
       .PutString(nameof(_fifoFilename), _fifoFilename)
       .Build();

   var ffmpegWorker = OneTimeWorkRequest.Builder.From<FfmpegWorker>()
       .SetInputData(inputData)
       .Build();

   try
   {
       if (!WorkManager.IsInitialized)
       {
           var configuration = new Configuration.Builder()
               .SetDefaultProcessName(":ffmpegWorker")
               .Build();
           WorkManager.Initialize(BaseContext, configuration);
       }
       var manager = RemoteWorkManager.GetInstance(BaseContext);
       manager.Enqueue(ffmpegWorker);

   }
   catch (Exception e)
   {
   }

I need to create remote worker on a separate thread. I'm following this answer for things I need to do and I'm stuck at declaring dependencies.

I need to add implementation "androidx.work:work-multiprocess:$work_version" somewhere. How do I do that in .NET Android project?

I'm using Xamarin.AndroidX.Work.Runtime 2.10.0.1 package to work with workers.

here's the application section in my manifest

<application android:allowBackup="true" android:icon="@mipmap/appicon" android:label="@string/app_name" android:supportsRtl="true">
    <provider
     android:name="androidx.startup.InitializationProvider"
     android:authorities="${applicationId}.androidx-startup"
     android:exported="false"
     tools:node="merge" >
      <meta-data
          android:name="androidx.work.WorkManagerInitializer"
          android:value="androidx.startup"
          tools:node="remove" />
    </provider>
    <service
    android:name="androidx.work.multiprocess.RemoteWorkManagerService"
    tools:replace="android:process"
    android:process=":ffmpegWorker"/>

    <service
        android:name="androidx.work.impl.background.systemjob.SystemJobService"
        tools:replace="android:process"
        android:process=":ffmpegWorker"/>

  </application>

In my MainActivity RemoteWorkManager.GetInstance(BaseContext) throws the following error:

Java.Lang.IllegalStateException: Invalid multiprocess configuration. Define an 'implementation' dependency on :work:work-multiprocess library

   var inputData = new Data.Builder()
       .PutString(nameof(_fifoFilename), _fifoFilename)
       .Build();

   var ffmpegWorker = OneTimeWorkRequest.Builder.From<FfmpegWorker>()
       .SetInputData(inputData)
       .Build();

   try
   {
       if (!WorkManager.IsInitialized)
       {
           var configuration = new Configuration.Builder()
               .SetDefaultProcessName(":ffmpegWorker")
               .Build();
           WorkManager.Initialize(BaseContext, configuration);
       }
       var manager = RemoteWorkManager.GetInstance(BaseContext);
       manager.Enqueue(ffmpegWorker);

   }
   catch (Exception e)
   {
   }
Share Improve this question edited 2 days ago Pavlo Holotiuk asked 2 days ago Pavlo HolotiukPavlo Holotiuk 2672 silver badges10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The proper solution would be to ask owners of Xamarin.AndroidX.Work.Runtime to include this package in their binding library which I have done. They will need to add bindings for classes used in that java package. (or I will have to create my own binding library)

I found a workaround for adding java dependencies but it has not fixed the problem of its classes not being supported in aforementioned nuget but maybe it will help somebody:

  1. Download java library (aar and pom).

  2. Open pom file and delete everything that is already referenced through referenced nuget packages (I had Xamarin.AndroidX.Work.Runtime which already had all references so I deleted all). It's important as nested references cannot be found by analyzer and duplicating references will lead to ambigous definition error later.

  3. Put .aar and .pom files to project directory.

  4. Add <AndroidLibrary Include="yourfilename.aar" Manifest="yourfilename.pom" /> to your csproj file.

  5. Add suggested in the errors nuget packages that for some reason are still required despite removing them from dependencies. (or repeat the process for java libraries if there are no nugets available)

  6. Next, I received a lot of errors about some class not implementing abstract members. It's probably related to binding library I'm using being outdated. Double click the error and replace virtual with override in required methods. (Not sure where the changes are being saved. They aren't reflected in git and reset every time you change something in csproj)

After all this, the project is compiled and runs. I no longer receive an exception requesting to add a dependency.

本文标签: cHow to declare java implementation dependency in net androidStack Overflow