Android Studio 2.x com.android.tools.fd.runtime.IncrementalChange $change

Problem background:

The project was running ok before, but after reinstalling the 64bit system and installing Android studio 2.1, the previous functions of the project cannot be operated. So, seeing how there is a $change in the log, I have never written this stuff. Take a look at the break point, when you reach the following line of code
Field[] fields = clazz.getDeclaredFields();

fields have an additional attribute $change. So far the problem has been located.

Solution

Method 1

is caused by the addition of the Instant Run feature, so you can turn off this feature (it is enabled by default). Closing method: Settings> Build, Execution, Deployment> Instant Run> Enable Instant Run to hot swap code /resource changes on deploy(default enabled) (cancel this option)

Method 2

Field[] fields = objClass.getFields();
for (Field field : fields) {         
    if(field.isSynthetic()){
          continue;
    }
    //add your code here
}

This method adds for and a judgment. The Field.isSynthetic() method returns true when judging that the current attribute is compiled and inserted.

Summary The solution of

method 1 will not change the existing code, and the risk is small, but the instant compilation feature of Studio cannot be used.
Method 2 I think it is a better solution, which can completely solve the problem and can also use new features

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326511744&siteId=291194637