zendesk / belvedere

An image picker library for Android
Apache License 2.0
145 stars 23 forks source link

Resource discrepancy causing crash on ImageStreamUI #52

Closed wrparrish closed 6 years ago

wrparrish commented 6 years ago

Hello!

I'm getting a crash whenever trying to use the ImageStream feature of belvedere.

The crash message is as follows: java.lang.NoSuchFieldError: No static field image_stream_toolbar_container

When using the 2.0.0 sources linked on the project page, the following line in the ImageStream UI class at line 150 fails to compile correctly.

   this.toolbarContainer = view.findViewById(R.id.image_stream_toolbar_container);

This can be reproduced by just creating a new project with belvedere being the only dependency, and then trying to interact with the image stream.

The following code is a drop in example / activity


class MainActivity : AppCompatActivity(), ImageStream.Listener {
    override fun onDismissed() {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onVisible() {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onMediaSelected(mediaResults: MutableList<MediaResult>?) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onMediaDeselected(mediaResults: MutableList<MediaResult>?) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    lateinit var imageStream: ImageStream

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        setSupportActionBar(toolbar)
         imageStream = BelvedereUi.install(this)

        fab.setOnClickListener { _ ->

            imageStream.addListener(this@MainActivity)

            BelvedereUi
                    .imageStream(this@MainActivity)
                    .withCameraIntent()
                    .withDocumentIntent("*/*", true)
                    .showPopup(this@MainActivity)

        }
    }
}
schlan commented 6 years ago

Hey, I tried to reproduce the error with the code you provided but wasn't able to. As you suggested I created a new AS project and pulled in Belvedere v2. Can you maybe provide me with your sample project for recreation?

There's a view with the id image_stream_toolbar_container https://github.com/zendesk/belvedere/blob/f39f36d763be38dd9a05d82db006ccfc368785af/belvedere/src/main/res/layout/belvedere_image_stream_toolbar.xml#L5

wrparrish commented 6 years ago

Sure! https://github.com/wrparrish/belvedere-test

Its important to mention, that everything works fine when i forked your repo. When i run the sample app there, and it compiles with the local bundled versions of belvedere and belvedere-core, i have no issue.

Its only when pulling in the dependency from maven.

schlan commented 6 years ago

I think I found the bug. The id image_stream_toolbar_container is only defined for devices targeting API < 21. As a workaround, you can set your minSdk to 19 and it should stop crashing.

I'll push a fix in a bit. Thanks for reporting this issue. :+1:

wrparrish commented 6 years ago

Appreciate your prompt investigation!

On a side note, i recently integrated your Suas implementation in favor of a sort of ad-hoc version of redux i had been using. So far the experience has been outstanding, so thank you and your team for the effort put into that library as well.

Will drop to 19 for now, and keep an eye out for the next release.
Thanks!

schlan commented 6 years ago

I merged a PR with a fix for this issue. The CI deployed a new snapshot with the latest changes. Feel free to check it out.

wrparrish commented 6 years ago

Awesome, everything is working great on my end!
Thank you for looking into this.