gogoWebsite

Solve NoSuchFieldError

Updated to 1 day ago
Let’s first describe the situation of this problem.
     A third-party aar is integrated into the project.  Configure aar, compile and package tests are completely fine.  I was a little excited all the way.  Another project next also needs this function, which is not simple.  Compile and package test according to the configuration of the previous project.  What's the situation!  !  !  !
 java.lang.NoSuchFieldError: No static field xxxx of type I in class xxx/xxx/R$id; or its superclasses (declaration of '$id' appears in /data/app/-1/split_lib_slice_3_apk.apk)
                                                                            at com.xxx.xxx.xxxx.onClick(Unknown Source)
                                                                            at android.view.View.performClick(View.java:5714)
                                                                            at android.view.View$PerformClick.run(View.java:22594)
                                                                            at android.os.Handler.handleCallback(Handler.java:739)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                            at android.os.Looper.loop(Looper.java:148)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:7325)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Fuck!Fuck!!Fuck!!!
What is the reason for this? An inexplicable question. What is even more tangled is that it is completely normal in another project. In this project, it will crash as long as you click the button. shit! ! ! After two days of confusion, the problem still needs to be solved slowly. There is no problem confusing the configuration and packaging. Suddenly I found the error message Unknown Source. Resource not found. So I started searching for controls with id xxx in the aar project. Finally found in an XML. Then what? See where this control is referenced. Find the corresponding activity and see findviewbyid() in it. Isn't this true? Why can't I find it? So I searched for R file traversal and searched for this control. What? ? ? Why not? No wonder it can't be found. At this point, the problem finally came out. It turns out that the id of the control is not registered on the r file. But how did this cause it?
Find the xml where the control is located, and then double shift. Enter the name of the xml. My God! It turns out that it is the same as the layout in another aar. Try changing your name quickly. These days, there is such a high probability of giving a duplicate name. . .
Why! ! I'm tired, record it.