[SOLVED] AndroidHarnessFragment import is not seen

Hello
I’ve begun to study JME3. More concretely, I’ve tried to use AndroidStudio as IDE and tried to write an android application. But when I try to import AndroidHarnessFragment, the import colours grey and red.

build.gradle

plugins {
    id 'com.android.application'
}

android {
    compileSdk 30

    defaultConfig {
        applicationId "org.lunapark.dev.jmonkey3template"
        minSdk 29
        targetSdk 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation "org.jmonkeyengine:jme3-core:3.4.0-stable"
    implementation "org.jmonkeyengine:jme3-desktop:3.4.0-stable"
    implementation "org.jmonkeyengine:jme3-lwjgl:3.4.0-stable"
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

How to make AndroidHarnessFragment import correctly? I’m trying

import com.jme3.app.AndroidHarnessFragment;

Android Studio Arctic Fox | 2020.3.1 Patch 3
Build #AI-203.7717.56.2031.7784292, built on October 1, 2021
Runtime version: 11.0.10+0-b96-7249189 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 4.15.0-162-generic
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 8
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: Batch Scripts Support, CMD Support, com.codota.csp.intellij, org.jetbrains.kotlin
Current Desktop: ubuntu:GNOME

Remove those

and

add this :

    implementation "org.jmonkeyengine:jme3-android-native:3.4.0-stable"

Sync gradle, clean project and rebuild.

For jme3 quick start examples on android check these projects :

3 Likes

Thanks a lot! You’ve made my day :sunny:

2 Likes

@MikitaSaladukha I don’t think the android harness fragment might work with android apps, since it extend android.app.Fragment and not androidx.fragment.app.Fragment.

It will work, but less efficient, android core team adds a compatibility behavior through androidx in appcompat package to handle different things for different android versions, deprecate un-relevant listeners and add the Lifecycles and LifecycleOwners in which you can create your own components and register them to a lifecycle owner and there is more …

Oh, I was getting errors Using android.app.Fragment.

Open a new forum thread describing your problems, or better search the forum first to avoid duplication.

actually android.app.Fragment is deprecated in android API level 28, thats why I was getting errors.

2 Likes

Yeah, it is, but you shouldn’t get errors so far that inhibit you from running the game, what kind of errors you get ? or do you mean warnings ?

Well I made a class MainFragment, which extends AndroidHarnessFragment, and i got an error saying required type androidx.fragment.app.Fragment, found MainFragment

1 Like

You are using getSupportFragmentManager() which will work only with androidx.fragment.app.Fragment, if you want to use AndroidHarness then use getFragmentManager() from your android Appcompat activity, here is an example :

oh alright!