java.lang.NoSuchMethodException: <init>
java.lang.NoSuchMethodException: <init>
我检查了调试版本中的所有内容,一切正常,但是当我生成 Signed Apk 时,出现此错误:
java.lang.NoSuchMethodException: <init> [interface org.simpleframework.xml.core.Contact, interface org.simpleframework.xml.Attribute, class org.simpleframework.xml.stream.Format]
java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [interface org.simpleframework.xml.core.Contact, interface org.simpleframework.xml.Attribute, class org.simpleframework.xml.stream.Format]
at retrofit2.converter.simplexml.SimpleXmlRequestBodyConverter.convert(SimpleXmlRequestBodyConverter.java:43)
at retrofit2.converter.simplexml.SimpleXmlRequestBodyConverter.convert(SimpleXmlRequestBodyConverter.java:26)
at retrofit2.ParameterHandler$Body.apply(ParameterHandler.java:297)
at retrofit2.ServiceMethod.toRequest(ServiceMethod.java:109)
at retrofit2.OkHttpCall.createRawCall(OkHttpCall.java:178)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:162)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:171)
at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.request(OperatorSubscribeOn.java:109)
at rx.Subscriber.setProducer(Subscriber.java:211)
at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.setProducer(OperatorSubscribeOn.java:105)
at rx.Subscriber.setProducer(Subscriber.java:205)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:152)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:138)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10256)
at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100)
at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker.call(CachedThreadScheduler.java:230)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access1(ScheduledThreadPoolExecutor.java:152)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NoSuchMethodException: <init> [interface org.simpleframework.xml.core.Contact, interface org.simpleframework.xml.Attribute, class org.simpleframework.xml.stream.Format]
at java.lang.Class.getConstructor(Class.java:531)
at java.lang.Class.getConstructor(Class.java:495)
at org.simpleframework.xml.core.LabelExtractor$LabelBuilder.getConstructor(LabelExtractor.java:426)
如果我做对了,那就是 ProGuard 问题,但我不知道如何修复它。有什么建议吗?
好的,我找到了解决方案,这段代码在Proguard.rules:
-keep public class org.simpleframework.**{ *; }
-keep class org.simpleframework.xml.**{ *; }
-keep class org.simpleframework.xml.core.**{ *; }
-keep class org.simpleframework.xml.util.**{ *; }
作为 上的一点:
指定
可能就足够了
-keep class org.simpleframework.xml.**{ *; }
没有原始答案中的其余 3 行。
根据 ProGuard manual:
**
matches any part of a class name, possibly containing any number of package separators. For example, **.Test
matches all Test classes in all packages except the root package. Or, com.example.**
matches all classes in "com.example" and in its subpackages.
建议的解决方案可能不会涵盖同一组案例,因为它不包含 public 类 在 -keep public class org.simpleframework.**{ *; }
(来自原始答案)。
但是,在提供的堆栈跟踪的第一行中,只有 类 来自 org.simpleframework.xml...
包,而不是来自更高级别的包。
遇到类似问题:
java.lang.NoSuchMethodException: <init> [
interface org.simpleframework.xml.core.Contact,
interface org.simpleframework.xml.ElementMap,
class org.simpleframework.xml.stream.Format]
我通过向 ProGuard 规则添加 一行 行解决了这个问题。
我检查了调试版本中的所有内容,一切正常,但是当我生成 Signed Apk 时,出现此错误:
java.lang.NoSuchMethodException: <init> [interface org.simpleframework.xml.core.Contact, interface org.simpleframework.xml.Attribute, class org.simpleframework.xml.stream.Format]
java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [interface org.simpleframework.xml.core.Contact, interface org.simpleframework.xml.Attribute, class org.simpleframework.xml.stream.Format]
at retrofit2.converter.simplexml.SimpleXmlRequestBodyConverter.convert(SimpleXmlRequestBodyConverter.java:43)
at retrofit2.converter.simplexml.SimpleXmlRequestBodyConverter.convert(SimpleXmlRequestBodyConverter.java:26)
at retrofit2.ParameterHandler$Body.apply(ParameterHandler.java:297)
at retrofit2.ServiceMethod.toRequest(ServiceMethod.java:109)
at retrofit2.OkHttpCall.createRawCall(OkHttpCall.java:178)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:162)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:171)
at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.request(OperatorSubscribeOn.java:109)
at rx.Subscriber.setProducer(Subscriber.java:211)
at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.setProducer(OperatorSubscribeOn.java:105)
at rx.Subscriber.setProducer(Subscriber.java:205)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:152)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:138)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10256)
at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100)
at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker.call(CachedThreadScheduler.java:230)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access1(ScheduledThreadPoolExecutor.java:152)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NoSuchMethodException: <init> [interface org.simpleframework.xml.core.Contact, interface org.simpleframework.xml.Attribute, class org.simpleframework.xml.stream.Format]
at java.lang.Class.getConstructor(Class.java:531)
at java.lang.Class.getConstructor(Class.java:495)
at org.simpleframework.xml.core.LabelExtractor$LabelBuilder.getConstructor(LabelExtractor.java:426)
如果我做对了,那就是 ProGuard 问题,但我不知道如何修复它。有什么建议吗?
好的,我找到了解决方案,这段代码在Proguard.rules:
-keep public class org.simpleframework.**{ *; }
-keep class org.simpleframework.xml.**{ *; }
-keep class org.simpleframework.xml.core.**{ *; }
-keep class org.simpleframework.xml.util.**{ *; }
作为
指定
-keep class org.simpleframework.xml.**{ *; }
没有原始答案中的其余 3 行。
根据 ProGuard manual:
**
matches any part of a class name, possibly containing any number of package separators. For example,**.Test
matches all Test classes in all packages except the root package. Or,com.example.**
matches all classes in "com.example" and in its subpackages.
建议的解决方案可能不会涵盖同一组案例,因为它不包含 public 类 在 -keep public class org.simpleframework.**{ *; }
(来自原始答案)。
但是,在提供的堆栈跟踪的第一行中,只有 类 来自 org.simpleframework.xml...
包,而不是来自更高级别的包。
遇到类似问题:
java.lang.NoSuchMethodException: <init> [
interface org.simpleframework.xml.core.Contact,
interface org.simpleframework.xml.ElementMap,
class org.simpleframework.xml.stream.Format]
我通过向 ProGuard 规则添加 一行 行解决了这个问题。