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)

最佳答案

我将构造函数从“ Bbox发送”更改为“测试任务”,并在Android 9上运行了代码。

08-25 04:38