Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassNotFoundException: com.otaliastudios.firestore.FirestoreMapMetadataImpl #11

Closed
DanielAsher opened this issue May 27, 2020 · 8 comments · Fixed by #12
Closed

ClassNotFoundException: com.otaliastudios.firestore.FirestoreMapMetadataImpl #11

DanielAsher opened this issue May 27, 2020 · 8 comments · Fixed by #12

Comments

@DanielAsher
Copy link

Hi,

thanks for this great project. It makes firestore so much nicer to work with.

I'm getting a java.lang.ClassNotFoundException: com.otaliastudios.firestore.FirestoreMapMetadataImpl error occasionally and I've searched the source and kapt generated files but couldn't find any such file or class.

Here is a summary stack trace:

java.lang.ClassNotFoundException: com.otaliastudios.firestore.FirestoreMapMetadataImpl
	 at java.lang.Class.classForName(Native Method)
	 at java.lang.Class.forName(Class.java:453)
	 at java.lang.Class.forName(Class.java:378)
	 at com.otaliastudios.firestore.FirestoreDocument$Companion.metadataProvider$firestore_release(FirestoreDocument.kt:5)
	 at com.otaliastudios.firestore.FirestoreMap.set(FirestoreMap.kt:9)
	 at com.otaliastudios.firestore.FirestoreMap.set(FirestoreMap.kt:6)

Should this class be found, or is this a client-side coding error?

Cheers,

Daniel

@natario1
Copy link
Owner

It should definitely be found. However, if it was totally missing, you'd get this error very frequently. Not sure what's going on.

Does this maybe happen only on builds with proguard on?

@DanielAsher
Copy link
Author

DanielAsher commented May 28, 2020

Hi Mattia,

thanks for the speedy response. Much appreciated.

This issue seems to affect debug builds.

Once the build has succeeded I'm unable to find the file FirestoreMapMetadataImpl.kt in our
app/build/generated/source/kapt/stagingDebug/com/otaliastudios/firestore folder with only the BR.java file present

I built the demo project, and I also can't find FirestoreMapMetadataImpl.kt in
demo/build/generated/source/kapt/debug/com/otalistudios/firestore/demo

otaliastudios firestore kapt generated classes

I noticed that demo/proguard-rules.pro do not contain any rules.

It would be great to get to the bottom of this issue, and perhaps include some advice on proguard in the README. Should the *MetadataImpl files be added to proguard?

Very much appreciate any help, as we'd love to use this library!

@natario1
Copy link
Owner

Could you share the model class that you are using? The @FirestoreClass that's causing this issue. Or if you don't know which one, you can post all of them. I am thinking that maybe we don't currently support the way you're using it.

@DanielAsher
Copy link
Author

DanielAsher commented May 28, 2020

I'm dynamically creating some properties. This seems to work fine, mostly e.g. this[newSessionIndexKey] = newSession

It would be great to understand whether FirestoreMapMetadataImpl should be created by the kapt annotation processor, and therefore whether the error is spurious, or correct.

The error is created at com.nusic.mashup.service.firebase.User$SessionHistory.add

I doubt this, but I thought I'd ask whether using the optional generic type FirestoreMap<Any?> and FirestoreMap<Event?> instead of FirestoreMap<Any> and FirestoreMap<Event> could cause this?

    @FirestoreClass
    class EventHistory : FirestoreMap<Any>() {

        var lastEventOrdinal: Int by this

        init {
            lastEventOrdinal = 0
        }

        fun add(event: Event, user: User) {
            val now = Timestamp.now()
            if (user.lastSessionEnd.seconds + 600 < now.seconds) {
                createNewSessionAndAdd(event, user, now)
            }
            else {
                val sessionIndexKey = getSessionIndexKey(user.lastSessionIndex, user.lastSessionStart)
                when (val session = this[sessionIndexKey] as? SessionHistory) {
                    null    -> {
                        createNewSessionAndAdd(event, user, now)
                    }
                    session -> {
                        user.lastSessionEnd = now
                        lastEventOrdinal += 1
                        session.add(event, lastEventOrdinal)
                    }
                }
            }
        }

        private fun createNewSessionAndAdd(event: Event,
                                           user: User,
                                           now: Timestamp) {
            val newSession = SessionHistory()
            lastEventOrdinal = 0
            newSession.add(event, 0)
            user.lastSessionStart = now
            user.lastSessionEnd = now
            user.lastSessionIndex += 1
            val newSessionIndexKey = getSessionIndexKey(user.lastSessionIndex, now)
            this[newSessionIndexKey] = newSession
        }

        private fun getSessionIndexKey(sessionIndex: Int, timestamp: Timestamp): String {
            val sessionIndexString = "$sessionIndex".padStart(4, '0')
            val dateTime = SimpleDateFormat.getDateTimeInstance().format(timestamp.toDate())
            return "Session $sessionIndexString - $dateTime"
        }
    }
    @FirestoreClass
    class SessionHistory : FirestoreMap<Event>() {
        fun add(event: Event, eventOrdinal: Int) {
            val time = SimpleDateFormat.getTimeInstance().format(Date())
            val eventKey = "${"$eventOrdinal".padStart(4, '0')}: ${event.kind} - $time"
            this[eventKey] = event
        }
    }

@natario1
Copy link
Owner

It would be great to understand whether FirestoreMapMetadataImpl should be created by the kapt annotation processor, and therefore whether the error is spurious, or correct.

I was wrong saying that it should be created. It should not, so if it isn't, that's correct.

I'd ask whether using the optional generic type FirestoreMap<Any?> and FirestoreMap<Event?> instead of FirestoreMap and FirestoreMap could cause this?

It shouldn't make any difference. Does the error appear any time you call add()? The demo app model has a similar structure, but it doesn't seem to show this issue.

@DanielAsher
Copy link
Author

DanielAsher commented Jun 6, 2020

The error occurs only on some user devices/os so it's hard to nail down.

I'll try to share more insights as the crashes come in.

@natario1
Copy link
Owner

natario1 commented Sep 8, 2020

@DanielAsher do you have more information by any chance?

natario1 added a commit that referenced this issue Sep 8, 2020
@natario1 natario1 mentioned this issue Sep 8, 2020
natario1 added a commit that referenced this issue Sep 9, 2020
* Update dependencies, Gradle, Kotlin to 1.4.0, AGP to 4.0.1

* Add explicit API mode

* Better build checks

* Refactor

* Update docs

* Catch exception #11

* Release v0.7.0
@DanielAsher
Copy link
Author

I think this commit: c1f2d3d in this PR #17 fixes the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants