无法在Xamarin中绑定jar,找不到包 [英] Cannot bind jar in xamarin, No packages found

查看:134
本文介绍了无法在Xamarin中绑定jar,找不到包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绑定到xamarin android项目中的一个非常简单的jar文件,但是我得到了警告:

I am trying to bind to a very simple jar file in a xamarin android project, but I am getting the warning:

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.2.jar添加到相同的绑定项目中,则可以完美访问它,就像从xamarin绑定jar的文档(

if I add the picasso-2.5.2.jar to the same bindings project, it is accessible perfectly, just as in the documentation for binding a jar from xamarin (http://developer.xamarin.com/guides/android/advanced_topics/java_integration_overview/binding-a-java-library/binding-a-jar/)

jar中的代码非常简单:

the code in the jar is extremely simple:

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;
    }
}

推荐答案

问题是该类不是公共的.我将代码更改为:

Problem was that the class was not public. I changed the code to be:

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进行了重建,并且一切正常.

change the file name to match the class name, rebuilt using JDK6 and it all worked.

请注意,用于构建该库的JDK版本不应高于Xamarin使用的JDK版本,否则您可能会遇到问题.

Note that the JDK version used to build the library should not be higher than that used by Xamarin or you may get issues.

这篇关于无法在Xamarin中绑定jar,找不到包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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