简体   繁体   中英

Cannot bind jar in xamarin, No packages found

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.

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/ )

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM