Incorrect variable names in overridden methods

后端 未结 2 1395
情话喂你
情话喂你 2020-12-10 12:00

When I let Android Studio generate override method it will generate the method with strange parameter names.

For instance according to documentation onCheckedChanged

2条回答
  •  余生分开走
    2020-12-10 12:08

    It is related to the compileSdkVersion which is defined in your build.gradle file. You should install Sources for Android SDK for the API you used as compileSdkVersion. So try to install sources version equal to compileSdkVersion in SDK Manager.

    I've set the compileSdkVersion 28 in build.gradle file. Here is the result before and after installing sources version 28 (Notice: You should restart AndroidStudio after that):

    Before:

    val textWatcher = object: TextWatcher {
    
        override fun afterTextChanged(p0: Editable?) {
        }
    
        override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
        }
    
        override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
        }
    }
    

    After:

    val textWatcher = object: TextWatcher {
    
        override fun afterTextChanged(s: Editable?) {
        }
    
        override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
        }
    
        override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
        }
    }
    

    UPDATE: 10/23/2018

    The problem about AppCompat-v28 libraries such as RecyclerView class, comes from their aar artifacts. If you use version 27.1.1 libraries, the issue will gone. It doesn't matter what distribution of version 28 you are using (Such as 28.0.0, 28.0.0-alpha1, 28.0.0-alpha3, 28.0.0-rc1, 28.0.0-rc2, etc.) In all of version 28 distributions, the parameter names for abstract methods are obfuscated.

    public abstract static class Adapter {
    
        public Adapter() {
        }
    
        @NonNull
        public abstract VH onCreateViewHolder(@NonNull ViewGroup var1, int var2);
    
        public abstract void onBindViewHolder(@NonNull VH var1, int var2);
    
        ...
    }
    

    So it seems that there is no way to solve, until it would be fixed in the next distributions.

提交回复
热议问题