Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

use Java code in Qt prolem of compilation



  • Hi All,

    I try o import java code in Qt, but I het error in compilation, I don't know in the .pro file wich code I put, espicially with ANDROID_PACKAGE_SOURCE_DIR = ?

    which file I put in this Macro ANDROID_PACKAGE_SOURCE_DIR, when I delete it the program comiles but the java code doesn't works, Thanks in adavnce

    77285999-3086-487b-b3d1-a77abf37d4f0-image.png
    H


  • Lifetime Qt Champion

    Hi,

    Did you follow Qt's documentation about it ?



  • Hello Mr @SGaist ,while using JNI I am faced a problem which is figured below,

    b34f7c9c-597e-4048-869e-9cb055636419-image.png

    Please any suggestion regarding this problem?


  • Lifetime Qt Champion

    Based on the error message, are you using an unusual charset somewhere ?



  • I don't change anything I follow projects>> Android APK>> create template, then a java directories are created, so I attempt to create a java class to do a simple tak, I've otten this problem



  • Mr @SGaist here is below my simple code
    4a8437b3-29ef-4b46-adae-6f2daf0e259a-image.png


  • Lifetime Qt Champion

    Can you provide the full error ?



  • here is the full error shown in the image below:

    7761063d-a9cb-44ea-9e8f-c66c5bdfe9df-image.png


  • Lifetime Qt Champion

    Did you check your file encoding ?



  • which file? gradlew.bat file??



  • @SGaist

    @if "%DEBUG%" == "" @echo off
    @rem ##########################################################################
    @rem
    @rem  Gradle startup script for Windows
    @rem
    @rem ##########################################################################
    
    @rem Set local scope for the variables with windows NT shell
    
    if "%OS%"=="Windows_NT" setlocal
    
    set DIRNAME=%~dp0
    if "%DIRNAME%" == "" set DIRNAME=.
    set APP_BASE_NAME=%~n0
    set APP_HOME=%DIRNAME%
    
    
    @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
    set DEFAULT_JVM_OPTS=
    
    @rem Find java.exe
    if defined JAVA_HOME goto findJavaFromJavaHome
    
    set JAVA_EXE=java.exe
    %JAVA_EXE% -version >NUL 2>&1
    if "%ERRORLEVEL%" == "0" goto init
    
    echo.
    echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
    echo.
    echo Please set the JAVA_HOME variable in your environment to match the
    echo location of your Java installation.
    
    goto fail
    
    :findJavaFromJavaHome
    set JAVA_HOME=%JAVA_HOME:"=%
    set JAVA_EXE=%JAVA_HOME%/bin/java.exe
    
    if exist "%JAVA_EXE%" goto init
    
    echo.
    echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
    echo.
    echo Please set the JAVA_HOME variable in your environment to match the
    echo location of your Java installation.
    
    goto fail
    
    :init
    @rem Get command-line arguments, handling Windows variants
    
    if not "%OS%" == "Windows_NT" goto win9xME_args
    
    :win9xME_args
    @rem Slurp the command line arguments.
    set CMD_LINE_ARGS=
    set _SKIP=2
    
    :win9xME_args_slurp
    if "x%~1" == "x" goto execute
    
    set CMD_LINE_ARGS=%*
    
    :execute
    @rem Setup the command line
    
    set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
    
    @rem Execute Gradle
    "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
    
    :end
    @rem End local scope for the variables with windows NT shell
    if "%ERRORLEVEL%"=="0" goto mainEnd
    
    :fail
    rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
    rem the _cmd.exe /c_ return code!
    if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
    exit /b 1
    
    :mainEnd
    if "%OS%"=="Windows_NT" endlocal
    
    :omega
    
    


  • Mr @SGaist please any idea? this problem persist one week, i am still blocked with my app


  • Lifetime Qt Champion

    I'd start with a default project and ensure that it builds and run properly, then add the Java parts from scratch using new files.



  • Here you could find my file .pro

    QT += quick
    QT += quickcontrols2
    QT += network
    QT += bluetooth
    QT += core
    QT += androidextras
    
    
    
    CONFIG += c++11
    
    # The following define makes your compiler emit warnings if you use
    # any Qt feature that has been marked deprecated (the exact warnings
    # depend on your compiler). Refer to the documentation for the
    # deprecated API to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    
    
    
    SOURCES += \
            bluetooth.cpp \
            main.cpp \
            wificonnection.cpp
    
    RESOURCES += qml.qrc
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =
    
    
    
    
    
    
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    HEADERS += \
        bluetooth.h \
        wificonnection.h
    
    DISTFILES += \
        android/AndroidManifest.xml \
        android/build.gradle \
        android/gradle/wrapper/gradle-wrapper.jar \
        android/gradle/wrapper/gradle-wrapper.properties \
        android/gradlew \
        android/gradlew.bat \
        android/res/values/libs.xml \
        android/src/org/JavaClass/JavaClass.java
    
    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
    
    
    
    
    


  • here is all the issue :

    Warning: QML import could not be resolved in any of the import paths: QtQuick.Extras.Private.CppUtils
    Warning: QML import could not be resolved in any of the import paths: QtQuick.Extras.Private.CppUtils
    Starting a Gradle Daemon, 2 incompatible Daemons could not be reused, use --status for details
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Unable to start the daemon process.
    This problem might be caused by incorrect configuration of the daemon.
    For example, an unrecognized jvm option is used.
    Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/5.6.4/userguide/gradle_daemon.html
    Process command line: C:\Program Files\Java\jdk1.8.0_271\bin\java.exe -Xmx2048m -Dfile.encoding -Duser.country=FR -Duser.language=fr -Duser.variant -cp C:\Users\achraf\.gradle\wrapper\dists\gradle-5.6.4-bin\bxirm19lnfz6nurbatndyydux\gradle-5.6.4\lib\gradle-launcher-5.6.4.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 5.6.4
    Please read the following process output to find out more:
    -----------------------
    Error occurred during initialization of VM
    java.nio.charset.IllegalCharsetNameException: 
    	at java.nio.charset.Charset.checkName(Charset.java:303)
    	at java.nio.charset.Charset.lookup2(Charset.java:484)
    	at java.nio.charset.Charset.lookup(Charset.java:464)
    	at java.nio.charset.Charset.defaultCharset(Charset.java:609)
    	at sun.nio.cs.StreamEncoder.forOutputStreamWriter(StreamEncoder.java:56)
    	at java.io.OutputStreamWriter.<init>(OutputStreamWriter.java:111)
    	at java.io.PrintStream.<init>(PrintStream.java:104)
    	at java.io.PrintStream.<init>(PrintStream.java:151)
    	at java.lang.System.newPrintStream(System.java:1148)
    	at java.lang.System.initializeSystemClass(System.java:1192)
    
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Get more help at https://help.gradle.org
    Building the android package failed!
      -- For more information, run this command with --verbose.
    12:42:30: Le processus "D:\Qt\5.15.2\android\bin\androiddeployqt.exe" s'est terminé avec le code 14.
    Erreur lors de la compilation/déploiement du projet untitled2 (kit : Android for armeabi-v7a,arm64-v8a,x86,x86_64 (Clang Qt 5.15.2 for Android))
    When executing step "Build Android APK"
    12:42:30: Elapsed time: 00:23.
    

  • Lifetime Qt Champion

    Looks wrong:
    @ENSAO_CHEIKH said in use Java code in Qt prolem of compilation:

    -Dfile.encoding

    there should be a value there.



  • @SGaist pkease in which file I find this -Dfile.encoding, I dont see it ?



  • @SGaist please where can I put this -Dfile encoding?


  • Lifetime Qt Champion

    Please show some patience and allow at least 24 hours to pass before bumping your own thread. This is a voluntary driven forum and people may not live in the same time zone as you.

    I currently do not have a Windows machine at hand to check your issue.

    That said:

    • did you try to apply my suggestion to start from a default project and once it's built, add the Java part ?
    • did you check your gradle related files for encoding entries ?

Log in to reply