1

I have some java code that works well in java but doesn't work at all in android. I have turned this code into a simple library that I thought I included all it's dependencies in the jar. However when run in android it tries to use the default android dependencies that came with the android project. I can't use an emulator because I am working with preexisting code and I just need this specific library to use the java versions of libraries. Is there a way where I can package this to include the default java libraries into the jar so that it only uses the java libraries and nothing from android?

Here is the code so far, there may be bugs in code as I have been modifying it to work as a library but the original code did work as a jar file that sent an email every time you ran the application.

public class Main {

public static void main(String User, String Pass, String host) {
    System.out.println("Starting");
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
    ExchangeCredentials credentials = new WebCredentials(User, Pass);
    service.setCredentials(credentials);
    try {
        String ewshost = (host);
        service.setUrl(new java.net.URI(ewshost));
        EmailMessage msg= new EmailMessage(service);
        msg.setSubject("Hello world!");
        msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Java API."));
        msg.getToRecipients().add(User);
        msg.send();
        System.out.println("Finished");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
}

Update: When I tried to compile this with it's prerequisite classes extracted and included in the jar this is the output I received when I tried to use my library in android.

warning: Ignoring InnerClasses attribute for an anonymous inner class (org.apache.commons.logging.impl.WeakHashtable$1) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is *not* an inner class.

Given what I can tell from fiddling around this is because the dependencies of the library I have created is conflicting with the default libraries. So I still need to somehow make it so that this library's dependencies are not seen at the top level and are strictly used just for the library.

trinityalps
  • 397
  • 4
  • 19
  • Try http://stackoverflow.com/questions/11537975/android-dx-error1-failed-to-convert-to-dalvik-format. May be the problem is that the jar you are including has a class in the java.* or javax.* namespace. – eurosecom Jun 24 '15 at 21:37
  • I have had that error before but that doesn't seem to be the issue now. I have disabled almost every library so I am almost positive the issue is what dependencies my library is trying to use. – trinityalps Jun 24 '15 at 21:48
  • Have you source java code ? Try copy java code to your eclipse or androidstudio like new project and set to library. In your android project make dependency on that java project. Then try build android project. May be builder will report some library conflict. – eurosecom Jun 25 '15 at 09:08
  • I have tried that and it doesn't notice an issue. That is essentially the same as just importing a normal library. Gradle will see a library conflict and tell you about it. So figuring out there is a problem is not the issue but actually finding a fix to it. – trinityalps Jun 25 '15 at 18:16
  • Hard to help without java code. Try remove dependency from java project one after another. You find out rather where is problem, what library is conflicted. – eurosecom Jun 26 '15 at 07:56

0 Answers0