VectorChildFinder icon indicating copy to clipboard operation
VectorChildFinder copied to clipboard

Can't use this anymore?

Open AndroidDeveloperLB opened this issue 2 years ago • 9 comments

I tried to add this dependency, and I got this error when trying to build&run:

e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
    class com.devs.vectorchildfinder.VectorDrawableCommon, unresolved supertypes: android.support.v4.graphics.drawable.TintAwareDrawable
Adding -Xextended-compiler-checks argument might provide additional information.

Any way to fix this?

VectorDrawableChangerTest.zip

https://github.com/devendroid/VectorChildFinder/files/11108955/studio64_2023-03-30_10-26-26.zip

AndroidDeveloperLB avatar Mar 30 '23 07:03 AndroidDeveloperLB

This can be done through Java reflection. First reflect call VectorDrawable.getTargetByName or VectorDrawableCompat.getTargetByName method to get VFullPath: Object path = ReflectUtil.invoke(vectorDrawable, "getTargetByName", new Class[]{String.class}, new Object[]{pathName}); Then Reflect calls the VFullPath.setFillColor method to set the color: ReflectUtil.invoke(path, "setFillColor", new Class[]{int.class}, new Object[]{color});

micstart avatar Jun 07 '23 13:06 micstart

@micstart You can't use reflection on VectorDrawable, which the VectorDrawableCompat generates. It will crash because it's blocked.

AndroidDeveloperLB avatar Jun 07 '23 13:06 AndroidDeveloperLB

@micstart You can't use reflection on VectorDrawable, which the VectorDrawableCompat generates. It will crash because it's blocked.

You can see VectorImage also use reflection.

micstart avatar Jun 07 '23 13:06 micstart

@micstart If you check its code, it uses reflection on the VectorDrawableCompat itself, similar to here on this library. Not on VectorDrawable. It does it nicely though.

Here it's safer, does it directly, and allows you to modify it. In any case, I've made a fork for it and published it, together with some other features: https://github.com/AndroidDeveloperLB/VectorChildFinder

Here's the proof that what you've mentioned uses reflection on VectorDrawableCompat:

    private fun createDrawable(
        context: Context,
        @DrawableRes vectorResId: Int
    ): VectorDrawableCompat? {
        try {
            @SuppressLint("ResourceType") val parser: XmlPullParser =
                context.resources.getXml(vectorResId)
            val attrs = Xml.asAttributeSet(parser)
            var type: Int
            while (parser.next().also { type = it } != 2 && type != 1) {
            }
            if (type != 2) {
                throw XmlPullParserException("No start tag found")
            }
            return VectorDrawableCompat.createFromXmlInner(context.resources, parser, attrs, null)
        } catch (var6: XmlPullParserException) {
            Log.e("VectorDrawableCompat", "parser error", var6)
        } catch (var7: IOException) {
            Log.e("VectorDrawableCompat", "parser error", var7)
        }
        return null
    }

AndroidDeveloperLB avatar Jun 07 '23 15:06 AndroidDeveloperLB

Hello, please check the latest code changes. Reflection has been removed and you can now continue using the library. Use the latest version https://github.com/devendroid/VectorChildFinder/releases/tag/1.0.1

devmike01 avatar Sep 19 '23 13:09 devmike01

@devmike01 Thank you. Can you please compare to the fork I've made, which has a few extra features, such as more finding functions, iterations (including deep iteration), and clicking ? I don't remember if I used reflection though.

AndroidDeveloperLB avatar Sep 19 '23 14:09 AndroidDeveloperLB

Your source code is a zip file. Could you put it on a public remote repository so that I can take a look? Thanks.

devmike01 avatar Sep 19 '23 14:09 devmike01

@devmike01 I can't find the ZIP file. I've provided a repository, which is public: https://github.com/AndroidDeveloperLB/VectorChildFinder You can't access it?

AndroidDeveloperLB avatar Sep 19 '23 14:09 AndroidDeveloperLB

I have seen the source code. Would take a look at it. Thanks

devmike01 avatar Sep 20 '23 17:09 devmike01