InputJar 和 ReferenceJar 的 Xamarin 绑定库组合? [英] Xamarin binding library combination of InputJar and ReferenceJar?

查看:37
本文介绍了InputJar 和 ReferenceJar 的 Xamarin 绑定库组合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 https://github.com/Redth/Xamarin.Android.Xposed 在 Xamarin 中,但最终结果被 Xposed 拒绝,说:无法加载模块"..xposed api 类被编译到模块的 apk 中".xposed-api.jar 文件当前是一个 EmbeddedJar,这就是导致该错误的原因.xposed-api.jar 文件已在 运行时 由 Xposed 提供.

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.

来自 xamarin 文档.

InputJar – 不将 .jar 嵌入到生成的绑定库 .DLL 中.您的绑定库 .DLL 将在运行时依赖于此 .jar.

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 似乎可以解决我的问题,将它编译到生成的 apk 中.但是,它根本无法编译成 apk.它在生成的 java 文件中给了我错误,例如.

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:错误:包 de.robv.android.xposed 不存在de.robv.android.xposed.IXposedHookLoadPackage 0

JAVAC0000: error: package de.robv.android.xposed does not exist de.robv.android.xposed.IXposedHookLoadPackage 0

然后对于 ReferenceJar..

Then for ReferenceJar..

ReferenceJar – 指定引用 .jar:引用 .jar 是绑定的 .jar 或 .AAR 文件之一所依赖的 .jar.此引用 .jar 仅用于满足编译时依赖项.使用此构建操作时,不会为引用 .jar 创建 C# 绑定,也不会将其嵌入到生成的绑定库 .DLL 中.

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.

我还尝试通过创建 2 个相同的库来组合这些库,其中一个具有 InputJar,另一个具有 ReferenceJar,但这根本不起作用.

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?

综上所述,我需要像Android框架的android.jar一样添加xposed-api.jar作为库.您可以使用类并正确编译,而无需将类编译到 apk 中.

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.

推荐答案

好吧,诀窍其实是AndroidExternalJavaLibrary".

OK, The trick is actually "AndroidExternalJavaLibrary".

假设您有一个 Jar 绑定项目 XPosedAPI 和一个 Android 项目 XposedSample.

Imagine you have a Jar binding project XPosedAPI, and an Android project XposedSample.

结构为:

XPosedAPI
|-- Jar
    |-- api-82.jar (InputJar)

XposedSample
|-- Jar
    |-- api-82.jar (AndroidExternalJavaLibrary)

你看,诀窍是你必须为每个项目放置相同的 jar 文件.对于 Jar 绑定项目,它必须是InputJar";- 用于生成 C# 绑定 dll.

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.

对于使用 Jar bindng dll 的项目,jar 必须是AndroidExternalJavaLibrary".这确保了 javac 编译过程.

For the project that using the Jar bindng dll, the jar has to be "AndroidExternalJavaLibrary". This ensures the javac compile process.

有一种更简单的方法,Java.Interop.DoNotPackageAttribute.您只需将以下行放在这些项目之一上(只需将其放在 XPosedAPI 项目上就足够了),它就可以工作:

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.

我想出了这个,因为我正在尝试做同样的事情 - 用 C# 编写一个 xposed 模块.

I figured out this, because I'm trying to do the same thing - write a xposed module in C#.

Xamarin.Android.Xposed 项目看起来不错,但实际上行不通,除了jar 绑定问题还有很多问题需要解决.

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.

我想我越来越近了,如果我能修复所有遗留的错误,我可能会在几天内发布它.如果您有兴趣,请观看我的项目:https://github.com/UlyssesWu/XamarinPosed

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

这篇关于InputJar 和 ReferenceJar 的 Xamarin 绑定库组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆