I am trying to use https://github.com/Redth/Xamarin.Android.Xposed in Xamarin but the final result is rejected by Xposed, saying: "cannot load module" .. "the xposed api classes are compiled into the module's apk". The xposed-api.jar file is currently a EmbeddedJar, which is what causes that error. The xposed-api.jar file is made available during run-time by Xposed already.
From the xamarin docs.
InputJar – Does not embed the .jar into the resulting Bindings Library .DLL. Your Bindings Library .DLL will have a dependency on this .jar at runtime.
InputJar seems like it will solve my issue with it being compiled into the resulting apk. However, it can't compile into an apk at all. It gives me errors in the generated java file such as.
JAVAC0000: error: package de.robv.android.xposed does not exist
de.robv.android.xposed.IXposedHookLoadPackage 0
Then for ReferenceJar..
ReferenceJar – Specifies a reference .jar: a reference .jar is a .jar that one of your bound .jar or .AAR files depends on. This reference .jar is used only to satisfy compile-time dependencies. When you use this build action, C# bindings are not created for the reference .jar and it is not embedded in the resulting Bindings Library .DLL.
Great, it will provide it during compile-time.. however, no bindings will be generated so I can't use it.
I also tried combining these by creating 2 identical libraries with one having InputJar and the other ReferenceJar, but that did not work at all.
How can I achieve what I am trying to do?
To sum it up, I need to add xposed-api.jar as a library just like how android.jar of the Android framework is added. You can use the classes and compile properly, without the classes being compiled into the apk.
OK, The trick is actually "AndroidExternalJavaLibrary".
Imagine you have a Jar binding project XPosedAPI, and an Android project XposedSample.
The structure would be:
XPosedAPI
|-- Jar
|-- api-82.jar (InputJar)
XposedSample
|-- Jar
|-- api-82.jar (AndroidExternalJavaLibrary)
You see, the trick is you have to put the same jar file for each project.
For the Jar binding project, it has to be "InputJar" - that's used to generate the C# binding dll.
For the project that using the Jar bindng dll, the jar has to be "AndroidExternalJavaLibrary". This ensures the javac compile process.
There was an easier way, the Java.Interop.DoNotPackageAttribute.
You just put the below line on one of these projects (just put it on XPosedAPI project would be enough), and it works:
[assembly: Java.Interop.DoNotPackage("api-82.jar")]
However, this attribute is marked as "deprecated", although it's easier.
I figured out this, because I'm trying to do the same thing - write a xposed module in C#.
The Xamarin.Android.Xposed project looks nice, but in fact it won't work, and there are much more problems to be fixed besides the jar binding issue.
I think I'm getting closer, and I may publish it in a few days if I can fix all the bugs remained.
If you're interested, watch my project: https://github.com/UlyssesWu/XamarinPosed
Related
I have a external .jar library that I need to import to my project, I have followed the official Binding a .JAR guide and added the .jar as a "EmbeddedJar".
It seems to work fine and I can use the library, but I have now noticed that some minor classes did not get bindings created correctly and the methods/fields are not accessible. I don't get any errors, the expected fields/methods just don't exist. But I do see them when inspecting the .Class object.
What can I try to make sure all classes gets converted correctly? Or, worst case, is it possible add these manually somehow?
I am trying to build Xamarin Android binding libraries for two different RFID hand held scanner SDKs (from two different companies), and then reference them in a Xamarin.Android project. So the end goal is to have one application that can run on Device A or Device B and depending on the device manufacturer it will use a different implementation of a "scanner" interface. If I try to reference both of the resulting dlls from the Xamarin.Android project, then I get the following error:
Program type already present: com.hsm.barcode.DecodeOptions
Looking in the jars using JD-GUI as suggested in the Microsoft Docs I can see the problem is that both of the jars have a com.hsm.barcode package:
What is the best way to workaround this issue?
Note that if I use only one of the dlls then I have no issues.
What I have tried:
Using a single Xamarin Android binding library project for both jars - this gave exactly the same result
Renaming all of the classes in the jar to eliminate duplicate class names like this: <attr path="/api/package[#name='com.hsm.barcode']/class[#name='DecodeOptions']" name="name">DecodeOptions2</attr>. When I do this, in reflector I can see that the class name has indeed changed, but I still get the build error when building the Xamarin.Android project
Renaming the namespace in one of the projects: <attr path="/api/package[#name='com.hsm.barcode']" name="name">com.hsm.barcode2</attr>. Again, I can see the updated namespace in reflector but still I get the same "Program type already present" error when building the Xamarin.Android project
Similarly I have tried removing both the namespace and the duplicate classes using remove-node but seen similar results
This leads me to believe that this isn't necessarily an issue with the binding process but rather a more Android related problem. I have found some similar Android questions where people mention that you can use exclude module in gradle to remove dependencies [1] [2], but a) there seems to be no concrete answer that this is the right approach in this case and b) as I have been able to find gradle is not a tool that is used as part of the Xamarin/Visual Studio process.
My final desperate attempt to get something working was to unzip one of the jar files, remove all the .class files that are causing issues, then rezip and use this in the Android binding library and then reference this dll in my Xamarin.Android project. This seems to work (the project builds and runs) but I'm not sure it is the correct/safest/most stable solution.
To summarize, the question is: if you have two jars with duplicated namespaces/packages and you want to use both of these Jars in a Xamarin.Android project how can you avoid the resulting Program type already present: com.hsm.barcode.DecodeOptions error message.
I am building a DLL using visual studio, which involves installing the following libraries :
GLM
GLFW
GLEW
I linked those libraries to visual studio using the following method :
specifying Additional Include Directories in the project property page
specifying Additional Dependencies in the project property page
specifying Additional Library Directories in the project property page
Of course GLM is a header only Library, which means that I am only required to specify the Additional Include Directories for GLM. And my dll built perfectly fine.
But the real problem occurs when using the library in a test project. I linked my test project to my library using the method mentioned above, but when I tried to build the test project, it produces the following results :
Cannot open include file <GLFW/glfw3.h>
And the same goes for glew. It seems that these libraries are not found when the library is being used by another test project. How can I fix this? Any help would be highly appreciated.
Set the Additional Include Directories correctly for all projects. The compiler doesn't magically inherit settings from a project which happens to have it's output linked into another project. So you have to provide it the correct include path for any source file it sees. To spare yourself from having hardcoded paths to include directories you could use a property sheet common for both projects. Or you could tackle the problem in code and make use of the PIMPL idiom (eventually as simple as e.g. forward declaring some GL types and using a unique_ptr to them in public classes) so the headers of your project never expose any of the external include files.
I'm trying to follow this guide to build a binding library based off an AAR. I've added the .aar under the Jars folder in a new Java Bindings Library project. I set the build action to LibraryProjectZip. When I try to build I get errors telling me The type or namespace name 'BasicWebViewClient' does not exist', however, this file is in the original project. When I browse the .aar, it's not there. Anyone know why the class wouldn't be included?
Thanks
Just trying the simplest thing to use ActionBar Sherlock in an Android app using IntelliJ 12.
I've read in other post and blogs and people keep dowloading ABS' source and mavenizing it ( complaining ABS on maven is too old). It turns out on maven we can get 4.3.1 now.
Therefore, I am trying to avoid mavenizing ABS again.
So, I created a blank Android app project with a simple Hello, World activity.
Compiled and ran it, just to be sure.
Then, I went to the Project Structure and added the ABS library via Maven (com.actionbarsherlock:actionbarsherlock:4.3.1).
Added it to the Module that represents my app.
Made sure to mark the library as "Provided" in the Module Dependencies.
The whole thing compiles and run.
Of course, as soon as I extend the main activity from SherlockActivity the app crashes. Expected...
So, I open the AndroidManifest.xml and add android:theme="" to the application tag.
To my surprise and pain, #style/Theme.Sherlock... does not auto-complete, and the compiler complains with the dreaded error:
Error: No resource found that matches the given name (at 'theme' with
value '#style/Theme.Sherlock')
So, my question is what did I miss?
Is there a way to ask IntelliJ to load the resources from ABS?
Thanks.
Adding ActionBarShelock as a library (plain jar) will not work, you have to configure it as a Library module in IntelliJ IDEA and then set your main module to depend on it. See this tutorial.