无法在xamarin中绑定jar,找不到任何包
本文关键字:jar 找不到 任何包 绑定 xamarin | 更新日期: 2023-09-27 18:20:16
我正试图绑定到xamarin android项目中一个非常简单的jar文件,但我收到了警告:
JARTOXML : warning J2X9001: Couldn't load class GetCerts : java.lang.UnsupportedClassVersionError: GetCerts : Unsupported major.minor version 52.0
BINDINGSGENERATOR : warning BG8601: No packages found.
如果我将picasso-2.5.2jar添加到同一个绑定项目中,它是完全可以访问的,就像在从xamarin绑定jar的文档中一样(http://developer.xamarin.com/guides/android/advanced_topics/java_integration_overview/binding-a-java-library/binding-a-jar/)
jar中的代码非常简单:
package com.mgw;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
class GetCerts {
public static X509Certificate GetCert(byte[] bytes) throws Exception
{
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(bytes);
X509Certificate cert = (X509Certificate)certFactory.generateCertificate(in);
return cert;
}
}
问题是该类不是公共的。我把代码改成:
package com.sage;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
public class GetCerts {
public static X509Certificate GetCert(byte[] bytes) throws Exception
{
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(bytes);
X509Certificate cert = (X509Certificate)certFactory.generateCertificate(in);
return cert;
}
public static boolean DoSomething()
{
return true;
}
}
更改文件名以匹配类名,然后使用JDK6重新构建,一切都成功了。
请注意,用于构建库的JDK版本不应高于Xamarin使用的版本,否则可能会出现问题。