如何解决E / WM-WorkerFactory:无法实例化com.isopod.gateauth.UnifyIDAPIHandler $ ModelTrainer
所以我正在尝试使用标准的android工作库安排任务,但出现以下错误跟踪
E/WM-WorkerFactory: Could not instantiate com.isopod.gateauth.UnifyIDAPIHandler$ModelTrainer
java.lang.NoSuchMethodException: <init> [class android.content.Context,class androidx.work.WorkerParameters]
at java.lang.Class.getConstructor0(Class.java:2327)
at java.lang.Class.getDeclaredConstructor(Class.java:2166)
at androidx.work.WorkerFactory.createWorkerWithDefaultFallback(WorkerFactory.java:95)
at androidx.work.impl.WorkerWrapper.runWorker(WorkerWrapper.java:242)
at androidx.work.impl.WorkerWrapper.run(WorkerWrapper.java:136)
at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
E/WM-WorkerWrapper: Could not create Worker com.isopod.gateauth.UnifyIDAPIHandler$ModelTrainer
我正在使用标准工作库。我已经看到其他用户在尝试注入自定义初始化程序时遇到此问题,但是我相信我正在使用默认库,该库应该能够自行正确初始化
这是我在应用程序级别build.gradle中的依赖项:
dependencies {
implementation fileTree(dir: 'libs',include: ['*.jar'])
implementation 'id.unify.sdk:sdk-gaitauth:1.3.8'
implementation "androidx.work:work-runtime:2.4.0"
implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
这是我要使用的类的代码
public class ModelTrainer extends Worker {
public ModelTrainer (Context context,WorkerParameters params){
super(context,params);
}
@NonNull
@Override
public Result doWork() {
try {
if(curStatus == GaitAuthStatus.READY_TO_TRAIN) {
gaitModel.train();
curStatus = GaitAuthStatus.TRAINING;
} else if(curStatus == GaitAuthStatus.TRAINING){
gaitModel.refresh();
}
} catch (GaitModelException e) {
e.printStackTrace();
return Result.failure();
}
if(gaitModel.getStatus() == GaitModel.Status.READY){
curStatus = GaitAuthStatus.READY;
} else if(gaitModel.getStatus() == GaitModel.Status.FAILED){
return Result.failure();
}
return Result.success();
}
}
这是我开始工作的代码
WorkRequest trainModelRequest = new OneTimeWorkRequest.Builder(ModelTrainer.class).build();
WorkManager.getInstance(mainActivity.getApplicationContext()).enqueue(trainModelRequest);
mainActivity.addTextToScreen("Model training started");
还值得注意的是,我收到了一堆看起来很奇怪的消息,android studio运行日志:
W/isopod.gateaut: Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setAlpnProtocols([B)V (light greylist,reflection)
W/isopod.gateaut: Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->getAlpnSelectedProtocol()[B (light greylist,reflection)
I/org.libsodium.jni.NaCl: librarypath=/system/lib
W/pool-3-thread-1: type=1400 audit(0.0:32027): avc: denied { read } for uid=10158 name="cache" dev="dm-0" ino=31 scontext=u:r:untrusted_app:s0:c158,c256,c512,c768 tcontext=u:object_r:cache_file:s0 tclass=lnk_file permissive=0
W/pool-3-thread-1: type=1400 audit(0.0:32028): avc: denied { read } for uid=10158 name="cache" dev="dm-0" ino=31 scontext=u:r:untrusted_app:s0:c158,c768 tcontext=u:object_r:cache_file:s0 tclass=lnk_file permissive=0
I/RootBeer: LOOKING FOR BINARY: /data/local/su Absent :(
LOOKING FOR BINARY: /data/local/bin/su Absent :(
LOOKING FOR BINARY: /data/local/xbin/su Absent :(
LOOKING FOR BINARY: /sbin/su Absent :(
LOOKING FOR BINARY: /su/bin/su Absent :(
LOOKING FOR BINARY: /system/bin/su Absent :(
LOOKING FOR BINARY: /system/bin/.ext/su Absent :(
LOOKING FOR BINARY: /system/bin/failsafe/su Absent :(
LOOKING FOR BINARY: /system/sd/xbin/su Absent :(
LOOKING FOR BINARY: /system/usr/we-need-root/su Absent :(
LOOKING FOR BINARY: /system/xbin/su Absent :(
LOOKING FOR BINARY: /cachesu Absent :(
LOOKING FOR BINARY: /datasu Absent :(
LOOKING FOR BINARY: /devsu Absent :(
W/System: A resource failed to call close.
I/chatty: uid=10158(com.isopod.gateauth) FinalizerDaemon identical 1 line
W/System: A resource failed to call close.
A resource failed to call end.
W/isopod.gateaut: Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist,reflection)
W/isopod.gateaut: Accessing hidden field Lsun/misc/Unsafe;->theUnsafe:Lsun/misc/Unsafe; (light greylist,reflection)
D/ModelStore: Saved model d9d51fd3-2a9b-4af1-97f3-3d67424e8785 into storage,model data length 0 bytes
有人可以给我一些想法吗?我很困惑。我几乎遵循了android文档中的设置指南和示例,因此,如果我遇到此问题,我肯定还有很多其他问题
解决方法
可爱的u / Zhuinden在reddit上引用答案,
如果这是一个工作程序,则需要有一个使用Context,WorkerParameters和其他参数的构造函数。只是这两个。
在您的情况下,问题在于您的类是一个内部类,但是在Java中,这意味着它也引用了其父类。您需要将其定义为静态类
的确,在类定义中添加了static可以解决此问题,但是由于我想通过它传递数据,因此我将其设置为独立的公共类,并使用workmanager数据类传递参数
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。