Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to test Android native Java code in Qt project?
Forum Updated to NodeBB v4.3 + New Features

How to test Android native Java code in Qt project?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 2 Posters 86 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fuck qt
    wrote last edited by
    #1

    I got a project with some native java code in ./android/src/<package name>/XXX.java and imported it in ./CMakeLists.txt. Now I can run it in my android device.
    Now I wonder how to test the native code. It seems to be difficult to open the ./android directory because there are some qt defined variables in the top-level build.gradle. How do you do that? Are there some open source projects to refenence? Thank you!

    1 Reply Last reply
    0
    • D Offline
      D Offline
      danish777
      wrote last edited by
      #2

      You can test native Java code in a Qt Android project by creating a separate Android Studio project for unit testing.

      Here’s a general approach:

      Copy the ./android/src/<package> Java files into a standalone Android Studio project.

      Mock any Qt or JNI dependencies if needed.

      Use JUnit or Robolectric for testing.

      Once verified, integrate back into the Qt project.

      This way, you avoid issues with Qt’s custom Gradle setup and can test Java logic independently.

      For reference, check out Qt Android Extras or Qt's QtAndroid class to understand how native bindings are typically handled.

      F 1 Reply Last reply
      0
      • D danish777

        You can test native Java code in a Qt Android project by creating a separate Android Studio project for unit testing.

        Here’s a general approach:

        Copy the ./android/src/<package> Java files into a standalone Android Studio project.

        Mock any Qt or JNI dependencies if needed.

        Use JUnit or Robolectric for testing.

        Once verified, integrate back into the Qt project.

        This way, you avoid issues with Qt’s custom Gradle setup and can test Java logic independently.

        For reference, check out Qt Android Extras or Qt's QtAndroid class to understand how native bindings are typically handled.

        F Offline
        F Offline
        fuck qt
        wrote last edited by
        #3

        @danish777 Thank you! But I noticed that the same code appear twice in two git repository. (or may be the sub Android Studio project is a temporary one so does not need a repository?) And additionally, the gradle files is not identity so
        reproducibility might be a problem. Is this the commonly used approch in Qt for Android projects?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved