Search code examples
androiddebuggingandroid-custom-view

Cannot debug a CustomView in Android Studio


I cannot debug a custom view. "No executable code found at line" message shown. Also on a MainActivity the debug works fine and stop on setText method, but in my custom view not. The debug cannot in to my custom view method. And on the other methods did not stop, like onDraw. How can I fix it?

I have tried to clean, rebuild and restart project. Instant run is disabled. The Android Studio 3.4.1 version.

buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

        debug {
            debuggable true
            minifyEnabled false
        }
    }

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val pipsTextView = findViewById<PipsTextView>(R.id.pips_text_view)
        pipsTextView.setText("1123.23444", 5, 2, 3, -1)
    }
}

override fun setText(value: String, pipSize: Int, prePipSize: Int, floatingPipSize: Int, direction: Int) {
        this.pipSize = pipSize
        this.prePipSize = prePipSize
        this.floatingPipSize = floatingPipSize
        this.direction = if (direction < 0) DOWN else if (direction == 0) NEUTRAL else UP
        preparePipValues(value)
        invalidate()
    }

I expect the debug will work.


Solution

  • Based on this question, the following steps may help you:

    1. If you are using Maven dependencies, go to Maven Projects -> refresh
    2. If that does not work, Try top menu --> Build --> Rebuild Project
    3. If that still doesn't work, try top menu --> File --> Invalidate Cache/Restart
    4. If that still doesn't work, then $CATALINA_BASE/bin/catalina.sh stop, then start

    After this, usually it covers 99% of the problems. Otherwise, Probably you will have to examine some other possibilities.