jenetics/jpx

Android: Fails to parse GPX from Strava

ajchellew opened this issue · 13 comments

Downloaded GPX from Strava doesn't parse.
NYC.gpx.txt (renamed to txt for github upload)

java.lang.IllegalStateException: Current state (SPACE) not START_ELEMENT, START_ELEMENT, END_ELEMENT or ENTITY_REFERENCE
        at com.bea.xml.stream.MXParser.throwIllegalState(MXParser.java:3849)
        at com.bea.xml.stream.MXParser.getLocalName(MXParser.java:1085)
        at com.bea.xml.stream.MXParser.require(MXParser.java:1244)
        at io.jenetics.jpx.XMLStreamReaderAdapter.require(XMLStreamReaderAdapter.java:77)
        at io.jenetics.jpx.ElemReader.read(XMLReader.java:591)
        at io.jenetics.jpx.GPX$Reader.read(GPX.java:1139)
        at io.jenetics.jpx.GPX$Reader.read(GPX.java:1164)
        at io.jenetics.jpx.GPX$Reader.read(GPX.java:1178)
        at io.jenetics.jpx.GPX$Reader.read(GPX.java:1191)
        at io.jenetics.jpx.GPX.read(GPX.java:2064)

It does however work in Google Earth.
image

This is a virtual ride that includes power data. A real route without also doesn't parse but includes actual people's homes so sharing this one.

Are you using the latest version (1.6.0) of the library? I tested it on the master branch and it worked. This error seems to be fixed with #82.

Yes implementation 'io.jenetics:jpx:1.6.0'

Should have added this is on Android.

Anything I can do to provide more detailed logs?

I haven't the possibility to test it on Android. Maybe you have to change the STAX library. #76 listed a Gradle configuration which seems to work.

Yes we already included this. without the stax dependency JPX doesn't work at all.

    implementation 'stax:stax:1.2.0'
    implementation 'io.jenetics:jpx:1.6.0'

Understood its different on Android. We will have to investigate building/debugging from source.

I can reproduce the error, but couldn't fix it. The most common solution I found was:
https://stackoverflow.com/a/47371517

implementation group: 'javax.xml.stream', name: 'stax-api', version: '1.0-2'

but this is from 2008 and most probably outdated, although suggested it in 2017. However these does not help much, because there is a new error:

java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/xml/stream/XMLInputFactory;
        at io.jenetics.jpx.GPX$Reader.read(GPX.java:1133)
        at io.jenetics.jpx.GPX.read(GPX.java:1984)

@Segelzwerg - Maybe my comment here can help?

@tonsV2 sorry for not getting back to you sooner. I have to reinstall the environment and will come back to you as soon as I tested it.

@tonsV2 I actually ran into some trouble testing it. But I think it is due to I'm not being able to install Java 11 with Android Studio.

error: cannot access GPX
import io.jenetics.jpx.GPX;
                      ^
  bad class file: /home/marcel/.gradle/caches/transforms-2/files-2.1/a6bd7189bc27fd2363528ef91ed73186/jetified-jpx-2.0.0.jar(io/jenetics/jpx/GPX.class)
    class file has wrong version 55.0, should be 52.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.
apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-R'
    compileOptions {
        targetCompatibility = sourceCompatibility
        sourceCompatibility = sourceCompatibility
    }
    defaultConfig {
        applicationId "com.haas.marcel.jpx_test"
        minSdkVersion 'R'
        targetSdkVersion 'R'
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion = '29.0.3'
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.1.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'io.jenetics:jpx:2.0.0'
    implementation 'stax:stax:1.2.0'
}

@Segelzwerg - Yes, I had similar errors due to libraries compiled with Java 11.

@tonsV2 did you manage to fix them?

@Segelzwerg - The project I've been using JPX in is this. Maybe you can find some inspiration from that.

Has anyone found a solution?
better if for last v3.0.1 ?

i have tried as described in this thread, plus #76....same issues as above.

I have gradle 7.5 and I used Java 11, Java 17, Java 18 and Java 19.