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

Develop for android java issues



  • Hi everyone,
    I'm currently working on an mobile app for android.
    I did all the setup, as described (installed jdk and ndk / android sdk).
    Qt Creator recognizes my mobile correctly, when its connected to the development pc.
    When I wanted to deploy the app in my mobile (running android 4.4.2), the process threw up several errors,
    all of them related to java.

    "java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
    at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)...".

    Followed by more than 100 lines of errors "at...".
    By the way, openSSL is not set up (it was marked as optional).

    Hope there is someone to help me, thanks



  • @Phips04 said in Develop for android java issues:

    I didn't remember that version 8 is the recommended one, installed 15.

    Yes, it is no clearly defined ==> https://doc.qt.io/qt-5/android-building.html.
    JDK 8, still recommended for best compatibility, but starting with Qt 5.15 JDK 11 could be used.

    Side note: if you search on internet java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7, all matches you will found will clearly detail the issue. The gradle version is not compatible with the selected JDK.
    For Qt 5.15, the used gradle version is 5.6.4 (just check in <QT_DIR>/5.15.0/android/src/3rdparty/gradle/gradle/wrapper/gradle-wrapper.properties)


  • Lifetime Qt Champion

    @Phips04 said in Develop for android java issues:

    running android 4.4.2

    Android 4.4.2?! Do you really have to use such an old version?
    What Qt version do you use?
    To build for Android 4.4 you need Qt 5.12 or older.
    See https://doc.qt.io/archives/qt-5.13/android.html and https://doc.qt.io/qt-5.12/android.html



  • @Phips04 said in Develop for android java issues:

    When I wanted to deploy the app in my mobile (running android 4.4.2), the process threw up several errors,
    all of them related to java.

    I think your Android version is too old, according to Qt wiki, Android API level 18 (Android 4.3) is required and API 21 (Android 5.0) is recommended.



  • My mobile is a samsung galaxy S3 Neo running android 4.4.2, and I'm using QT 5.15.1.
    However it told me, that the build process failed because of java. I just copied the details:

    java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
    at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)
    at org.codehaus.groovy.reflection.GroovyClassValueFactory.<clinit>(GroovyClassValueFactory.java:35)
    at org.codehaus.groovy.reflection.ClassInfo.<clinit>(ClassInfo.java:109)
    at org.codehaus.groovy.reflection.ReflectionCache.getCachedClass(ReflectionCache.java:95)
    at org.codehaus.groovy.reflection.ReflectionCache.<clinit>(ReflectionCache.java:39)
    at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.registerMethods(MetaClassRegistryImpl.java:209)
    at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:107)
    at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:85)
    at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:36)
    at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:86)
    at groovy.lang.GroovyObjectSupport.getDefaultMetaClass(GroovyObjectSupport.java:59)
    at groovy.lang.GroovyObjectSupport.<init>(GroovyObjectSupport.java:32)
    at org.gradle.internal.extensibility.DefaultExtraPropertiesExtension.<init>(DefaultExtraPropertiesExtension.java:29)
    at org.gradle.internal.extensibility.DefaultConvention.<init>(DefaultConvention.java:48)
    at org.gradle.api.internal.plugins.DefaultConvention.<init>(DefaultConvention.java:28)
    at org.gradle.internal.extensibility.ExtensibleDynamicObject.<init>(ExtensibleDynamicObject.java:60)
    at org.gradle.internal.instantiation.MixInExtensibleDynamicObject.<init>(MixInExtensibleDynamicObject.java:34)
    at org.gradle.initialization.DefaultSettings_Decorated.getAsDynamicObject(Unknown Source)
    at org.gradle.initialization.SettingsFactory.createSettings(SettingsFactory.java:58)
    at org.gradle.initialization.ScriptEvaluatingSettingsProcessor.process(ScriptEvaluatingSettingsProcessor.java:61)
    at org.gradle.initialization.PropertiesLoadingSettingsProcessor.process(PropertiesLoadingSettingsProcessor.java:38)
    at org.gradle.initialization.SettingsEvaluatedCallbackFiringSettingsProcessor.process(SettingsEvaluatedCallbackFiringSettingsProcessor.java:34)
    at org.gradle.initialization.RootBuildCacheControllerSettingsProcessor.process(RootBuildCacheControllerSettingsProcessor.java:36)
    at org.gradle.initialization.BuildOperationSettingsProcessor$2.call(BuildOperationSettingsProcessor.java:50)
    at org.gradle.initialization.BuildOperationSettingsProcessor$2.call(BuildOperationSettingsProcessor.java:47)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.initialization.BuildOperationSettingsProcessor.process(BuildOperationSettingsProcessor.java:47)
    at org.gradle.initialization.DefaultSettingsLoader.findSettingsAndLoadIfAppropriate(DefaultSettingsLoader.java:104)
    at org.gradle.initialization.DefaultSettingsLoader.findAndLoadSettings(DefaultSettingsLoader.java:45)
    at org.gradle.initialization.SettingsAttachingSettingsLoader.findAndLoadSettings(SettingsAttachingSettingsLoader.java:35)
    at org.gradle.internal.composite.CommandLineIncludedBuildSettingsLoader.findAndLoadSettings(CommandLineIncludedBuildSettingsLoader.java:34)
    at org.gradle.internal.composite.ChildBuildRegisteringSettingsLoader.findAndLoadSettings(ChildBuildRegisteringSettingsLoader.java:47)
    at org.gradle.internal.composite.CompositeBuildSettingsLoader.findAndLoadSettings(CompositeBuildSettingsLoader.java:35)
    at org.gradle.initialization.DefaultSettingsPreparer.prepareSettings(DefaultSettingsPreparer.java:36)
    at org.gradle.initialization.BuildOperatingFiringSettingsPreparer$LoadBuild.doLoadBuild(BuildOperatingFiringSettingsPreparer.java:59)
    at org.gradle.initialization.BuildOperatingFiringSettingsPreparer$LoadBuild.run(BuildOperatingFiringSettingsPreparer.java:54)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.initialization.BuildOperatingFiringSettingsPreparer.prepareSettings(BuildOperatingFiringSettingsPreparer.java:42)
    at org.gradle.initialization.DefaultGradleLauncher.prepareSettings(DefaultGradleLauncher.java:190)
    at org.gradle.initialization.DefaultGradleLauncher.doClassicBuildStages(DefaultGradleLauncher.java:134)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:126)
    at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:106)
    at org.gradle.internal.invocation.GradleBuildController$1.execute(GradleBuildController.java:60)
    at org.gradle.internal.invocation.GradleBuildController$1.execute(GradleBuildController.java:57)
    at org.gradle.internal.invocation.GradleBuildController$3.create(GradleBuildController.java:85)
    at org.gradle.internal.invocation.GradleBuildController$3.create(GradleBuildController.java:78)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:189)
    at org.gradle.internal.work.StopShieldingWorkerLeaseService.withLocks(StopShieldingWorkerLeaseService.java:40)
    at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:78)
    at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:57)
    at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:31)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.BuildOutcomeReportingBuildActionRunner.run(BuildOutcomeReportingBuildActionRunner.java:63)
    at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
    at org.gradle.launcher.exec.BuildCompletionNotifyingBuildActionRunner.run(BuildCompletionNotifyingBuildActionRunner.java:39)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.call(RunAsBuildOperationBuildActionRunner.java:51)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.call(RunAsBuildOperationBuildActionRunner.java:45)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:45)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:50)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:47)
    at org.gradle.composite.internal.DefaultRootBuildState.run(DefaultRootBuildState.java:78)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:31)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:42)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:28)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:78)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:52)
    at org.gradle.tooling.internal.provider.SubscribableBuildActionExecuter.execute(SubscribableBuildActionExecuter.java:59)
    at org.gradle.tooling.internal.provider.SubscribableBuildActionExecuter.execute(SubscribableBuildActionExecuter.java:36)
    at org.gradle.tooling.internal.provider.SessionScopeBuildActionExecuter.execute(SessionScopeBuildActionExecuter.java:68)
    at org.gradle.tooling.internal.provider.SessionScopeBuildActionExecuter.execute(SessionScopeBuildActionExecuter.java:38)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:37)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:26)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:60)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:32)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:55)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:41)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:48)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:32)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:56)
    at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:212)
    at org.gradle.launcher.cli.DefaultCommandLineActionFactory$ParseAndBuildAction.execute(DefaultCommandLineActionFactory.java:404)
    at org.gradle.launcher.cli.DefaultCommandLineActionFactory$ParseAndBuildAction.execute(DefaultCommandLineActionFactory.java:376)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:38)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:23)
    at org.gradle.launcher.cli.DefaultCommandLineActionFactory$WithLogging.execute(DefaultCommandLineActionFactory.java:369)
    at org.gradle.launcher.Main.doAction(Main.java:35)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:60)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:31)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:31)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:108)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
    FAILURE: Build failed with an exception.

    • What went wrong:
      Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
    • 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
      BUILD FAILED in 2s

    I'm not sure, but maybe its not android itself being responsible for the problems.


  • Lifetime Qt Champion

    @Phips04 said in Develop for android java issues:

    I'm not sure, but maybe its not android itself being responsible for the problems.

    Did you read the post from @jsulm ?



  • This post is deleted!

  • Moderators

    @Phips04 It does not matter at all what device you attach to your PC,

    what does matter is what minimal android version you set inside your manifest. Did you change it there ?


  • Lifetime Qt Champion

    This post is deleted!


  • @J-Hilk Which file is that?

    Do you mean the *.pro file?



  • @Phips04 said in Develop for android java issues:

    Do you mean the *.pro file?

    No, the Android manifest ==> AndroidManifest.xml
    Double click on it in QtCreator to start the editor:
    11469230-f742-477d-b2a4-dac3c72d3219-image.png



  • QTAndroid.jpg

    This is how it actually looks like, the option to set the sdk is disabled.
    I made sure, that the sdk's I want to use are installed. (Sry I'm new to qt)



  • @Phips04 Did you check QtCreator Android configuration?

    In Tools/Option/Devices, select tab "Android":
    9acabd97-323f-4a6a-8f1e-36521c90789c-image.png



  • Java and android settings are ok, in the android settings there is no "ndk-bundle". But the second entry exists, as I mentioned OpenSSL is not set



  • @Phips04 said in Develop for android java issues:

    in the android settings there is no "ndk-bundle"

    This is your problem, ndk-bundle is mandatory for Qt!

    Extract from the Qt documentation:
    Use the sdkmanager command line tool to update the packages list and then install the essential packages:

    cd <ANDROID_SDK_ROOT>/tools/bin/
    ./sdkmanager --update
    ./sdkmanager --install "platform-tools" "platforms;android-29" "build-tools;29.0.2" "ndk-bundle"
    


  • Ok, I did it, but the cmd line reported some errors, and there was no effect in qt creator.
    QTAndroid2.jpg



  • @Phips04 This seems to be a well know issue with Android:

    You can try:

    cd <ANDROID_SDK_ROOT>\tools\bin\
    sdkmanager --sdk_root="<ANDROID_SDK_ROOT>" --update
    sdkmanager --sdk_root="<ANDROID_SDK_ROOT>" --install "platform-tools" "platforms;android-29" "build-tools;29.0.2" "ndk-bundle"
    


  • It worked this way, the bundle is installed now, but I still can't change the minimal android version


  • Moderators

    @Phips04 do it by hand than, open the android manifest.xml in a text editor
    and change the version there
    2fb9ec48-f65e-4d1d-97a4-2689c7454849-image.png



  • The .xml can be evaluated and I set the entries. Min sdk is 21 (android 5) and target is 27 (android 8.1). The error still is the same



  • @Phips04 said in Develop for android java issues:

    It worked this way, the bundle is installed now, but I still can't change the minimal android version

    What do you mean with "you can't"? Is the dropdown combobox grayed out or is the list empty?
    Do you have restart Qt Creator after updating SDK root?



  • Yes the combobox was grayed (I set the entries in the xml file via text editor, now I can edit the boxes) and I restarted Qt creator.



  • @Phips04 I know how have written "Java settings are ok", but which JDK version are you using?

    AFAIK, gradle do NOT work with JDK > 11, and recommended version is still JDK 8.



  • I meant qt Creator says Java settings are ok.
    I didn't remember that version 8 is the recommended one, installed 15.
    I will replace it by 8 now



  • @Phips04 said in Develop for android java issues:

    I didn't remember that version 8 is the recommended one, installed 15.

    Yes, it is no clearly defined ==> https://doc.qt.io/qt-5/android-building.html.
    JDK 8, still recommended for best compatibility, but starting with Qt 5.15 JDK 11 could be used.

    Side note: if you search on internet java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7, all matches you will found will clearly detail the issue. The gradle version is not compatible with the selected JDK.
    For Qt 5.15, the used gradle version is 5.6.4 (just check in <QT_DIR>/5.15.0/android/src/3rdparty/gradle/gradle/wrapper/gradle-wrapper.properties)



  • Ok, now finally it works. This is my very basic UI for testing

    QTAndroid4.jpg

    This is the sourcecode:

    import QtQuick 2.15
    import QtQuick.Window 2.15

    Window {
    Rectangle {
    id: rectangle
    color: "#09a4cc"
    anchors.fill: parent

        Rectangle {
            id: rectangle1
            x: 220
            y: 117
            width: 200
            height: 200
            color: "#4facfe"
            radius: height / 2
            gradient: Gradient {
                GradientStop {
                    position: 0
                    color: "#4facfe"
                }
    
                GradientStop {
                    position: 1
                    color: "#00f2fe"
                }
            }
        }
    }
    

    }

    What it shows is simply a white screen.๐Ÿ™„



  • @Phips04 I think you have to set property visible to true of top Window:

    import QtQuick 2.15
    import QtQuick.Window 2.15
    
    Window {
        visible: true // ==> default value is false!
        Rectangle {
            id: rectangle
            color: "#09a4cc"
            anchors.fill: parent
          ...
       }
    }
    


  • Ok, QT creator does not recongnize the property, but it compiles, and now it works the way it should,
    thanks for your help๐Ÿ‘



  • @Phips04 Your welcome


Log in to reply