Search code examples
androidbuildnativescript

NativeScript Build - Error executing Static Binding Generator: Class not found android.support.v4.view.ViewPager.OnPageChangeListener


I'm new to NativeScript and took over a project recently upgraded from NativeScript 4 to 6. Here is my environment detials:

  • Windows 10
  • Node v16.6.1
  • NativeScript 8.0.2
  • Android Studio 11 (with al the recommended updates to date)
  • VS Code 1.58.2

I can create a new Native script project with "tns create" and build/run it in the simulator just fine. However, when I try to run the project the build throws the following error:

java.lang.RuntimeException: Class not found android.support.v4.view.ViewPager.OnPageChangeListener
    at org.nativescript.staticbindinggenerator.Generator.getClass(Generator.java:551)
    at org.nativescript.staticbindinggenerator.Generator.getInterfacesFromCache(Generator.java:534)
    at org.nativescript.staticbindinggenerator.Generator.writeBinding(Generator.java:283)
    at org.nativescript.staticbindinggenerator.Generator.generateBinding(Generator.java:171)
    at org.nativescript.staticbindinggenerator.Generator.processRows(Generator.java:234)
    at org.nativescript.staticbindinggenerator.Generator.generateBindings(Generator.java:121)
    at org.nativescript.staticbindinggenerator.Generator.writeBindings(Generator.java:97)
    at org.nativescript.staticbindinggenerator.Main.main(Main.java:55)

Here is the run command I'm using: "tns run android --emulator"

I have tried tons of things and searches but no luck resolving this issue.


Solution

  • So I had an idea and searched with a different search engine than I normally use. I did find some ideas which helped me resolved the issue.

    I had previously searched in VSCode for variations on "android.support.v4.view.ViewPager.OnPageChangeListener", but only found the log file with the error. Then I learned you have to change the filter options of the find in file search otherwise the files you are looking for can be excluded from the search results. I also used Baregrep to confirm I was getting everything.

    I fixed the issue by replacing all occurrences of:

    android.support.v4.view.ViewPager with androidx.viewpager.widget.ViewPager

    Also you may need to install widgets:npm i tns-core-modules-widgets

    Since the files where I made the changes were all non-project files (many of them in the node_modules directory) there is probably something else that involves updating Node or NativeScript that may solve this as well.

    If someone else figures that out, I'll be watching this thread for updates, and thanks in advance!

    Fissh