-
-
Notifications
You must be signed in to change notification settings - Fork 701
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
reflections works on Android? #127
Comments
same question here |
Hy,
Unfortunately it didn't work. When I test it in my unit-tests it works. Do you have any idea why it doesn't work? |
I made a few tests and couldn't get it working. My assumption is that it cannot work on Android due to the way classes are loaded, which is different than on a standard JVM setup. |
Do you know any workarounds? |
I switched to using Gradle at build time to do what I needed, but I didn't find any workaround to use reflections. Would be interested if someone finds one, though. |
@christophetd , not sure if that what you've ment, but one solution/workaround is to generate xml on build time, then let Reflections collect it on bootstrap. see here |
@ronmamo Considering this is still open, is there any specific gradle config that can be used to generate the classes at compile time using Reflections().save(). My current way doesn't work and i'm struggling to get it to play ball, any chance of some pointers/example gradle configuration? |
@ronmamo, thank you for the Reflections library. I have tried to integrate it into my Android project using several sources of information and I am running into the same problem. I also have to admit I am not a gradle (or maven) expert so this may be more difficult for me to understand. Your answer on generating a xml file on build and letting Reflections collecting it on "bootstrap" seems to be the way to go, however I seem unable to find the way to actually do this. Your link explains the general possibility and the reflections-maven repository gives a maven example. With the help of stackoverflow, I have tried to convert the maven example to grade. But it does not actually work. What does "at boostrap" actually mean specifically as refering to project / java files? Where do I insert
Does this need to go into a special file or can I use this at any point in my code (this is what I am currently doing)? From several stackoverflow posts and your git readme files, I have come up with this for now: build.gradle (Module:app):
build.gradle (Project: MyProject):
And later on in my code (this class is reached at some point through user input, not loaded on app start):
This generates the following exception since "reflections" is not instantiated and has the value of "null": I understand that the generated .xml file resides on the computer where the build is happening, and I am not sure if this is also transferred to the android device so my guess is that is why this fails. But at what point does my Java code have access to this file before the apk is transferred and run on my android device? I have tried googling this in many different ways from different angles but I cannot seem to find a solution to make reflections work in Android. I understand the principle explained here and it seems better to generate the information in an xml file at build time to have the class information available at runtime. But how can I set this up properly? Thank you, |
Anyone succeed in executing Reflections on Android ? (via Gradle or not) I'm using the last version of Reflections library : 0.9.11 Here is what I added in my app/build.gradle in order to generate the json file:
The json file is created into the ...app/build/intermediates/classes/a/debug/META-INF/reflections/ folder but doesn't contain the scanned classes. Here is the generated json file content:
With the default Scanner, it should work @ronmamo right ? Thank you. |
Finally, I got it working (the gradle task part) but at runtime the Reflections library doesn't work, because of Android dex format, I guess. |
Has anyone been able to get this working? |
I am looking for something that can run on android, sad. |
+1 |
My use case is not specific to Android. However, there is a plugin that can be used to generate the XML file at compile time: https://github.com/manosbatsis/gradle-reflections-plugin I changed the default params in the build script via
and also ended up having to not use the default Reflections.collect() since for some reason this entire project is just super inconsistent for me. Instead I manually parsed the file via
Not sure if this will help anyone, but perhaps. |
How did you get the gradle plugin working with the android plugin? Android plugin is not compatible with the java plugin, so you can't access the 'classes' and 'jar' tasks. |
Sadly i have no experience in android builds. That said, any contribution to manosbatsis/gradle-reflections-plugin#5 is welcome if it can be useful. |
It works if you downgrade to 0.9.11 |
Are u sure ? |
version 0.9.11 compiled fine ! package com.jira;
} |
Hi guys,
I wanted to know if this library works on Android.
Thank you in advance
The text was updated successfully, but these errors were encountered: