IllegalAccessError仅在AsyncTask函数执行期间在Android 9上发生
在Android 9上有什么事情要做吗?其他所有版本都可以。
在生产应用程序上看到错误。
我已经尝试将所有内容公开化,并使用同一包。版本9上仍然存在此错误。
new TestTask(this, "test", true).execute(value);
public class TestTask extends AsyncTask<String, Void, String> {
private String param1;
private boolean param2;
private String number;
private WeakReference<Context> appReference;
TestTask(Context context, String param1, boolean param2) {
this.appReference = new WeakReference<>(context);
this.param1 = param1;
this.param2 = param2;
}
@Override
public String doInBackground(String... values) {
try {
number = values[0];
if(param2)
performVib();
ResponseEvent response = new TestSnmp(param1).set(number);
if( appReference.get()!=null && m_debugMode) {
Toast.makeText(appReference.get(), "Response: " + response, Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
public void onPostExecute(String result) {
super.onPostExecute(result);
try {
if( appReference.get()!=null ) {
Toast.makeText(appReference.get(), "Some text", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
这是堆栈:
java.lang.RuntimeException:
at android.os.AsyncTask$3.done (AsyncTask.java:354)
at java.util.concurrent.FutureTask.finishCompletion (FutureTask.java:383)
at java.util.concurrent.FutureTask.setException (FutureTask.java:252)
at java.util.concurrent.FutureTask.run (FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run (AsyncTask.java:245)
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)
Caused by: java.lang.IllegalAccessError:
at xxx.TestTask.doInBackground (TestTask.java)
at xxx.TestTask.doInBackground (TestTask.java)
at android.os.AsyncTask$2.call (AsyncTask.java:333)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run (AsyncTask.java:245)
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)
答案 0 :(得分:0)
我将构造器从BboxSend更改为TestTask,并在Android 9上运行了代码。
答案 1 :(得分:0)
我发现问题出在Proguard。
我在proguard-rules.pro中添加了这一行: -keep org.snmp4j类。** {*;} 看来现在可以了!