0

I have an Android Project and an Android Library. If i import the library into the project with a reference there is no problem on runtime. If i add the resulted jar from the Android Library and trying to run again the app, i get this error:

07-15 17:56:35.415: W/System.err(3457): java.lang.NoClassDefFoundError: packagename.here.R$layout

I don't understand why in the second situation this error is thrown. I should be able to import a jar of an Android Library, right? In the jar there is a method that shows a webview on the main ui thread. Confused. In this method the code breaks when trying to create the webView:

public static Dialog showWebView(final Activity context) {
        Dialog callAlert = new Dialog(context,
                android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);


        WebView webView = (WebView) context.findViewById(R.id.wb_webview);
        System.out.println("webview: " + webView);

        callAlert.requestWindowFeature(Window.FEATURE_NO_TITLE);
        Window window = callAlert.getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        callAlert.setCanceledOnTouchOutside(true);
        callAlert.setContentView(webView);

        return callAlert;
    }
Gabi Radu
  • 1,107
  • 2
  • 16
  • 35
  • 1
    You cannot package resources into jar. But i guess its possible with the new gradle system i came across a post on stackoverflow. I don't have the link. But you need to reference library projects in your android project – Raghunandan Jul 15 '14 at 16:08
  • The closest link i found now http://stackoverflow.com/questions/17063826/how-to-create-jar-for-android-library-project – Raghunandan Jul 15 '14 at 16:10
  • taking a look now. thx – Gabi Radu Jul 15 '14 at 16:11
  • 1
    http://stackoverflow.com/questions/19307341/android-library-gradle-release-jar – Raghunandan Jul 15 '14 at 16:13
  • This is difficult. So , an android library jar cannot outside reference it's resources. Bummer! Trying to use everything from source code and not use resources... I looked into the android studio and gradle. From studio you can export a libray in a file .aar. This contains sources and resources. The big big problem for me is, that this .aar file can be read only from another gradle android project, For instance Eclipse projects understand nothing out of it.I don't want to give the sources of the app as an android library, so creating one single jar is the only choice. – Gabi Radu Jul 16 '14 at 08:06
  • apart from that i do not have any other workaounds sorry – Raghunandan Jul 16 '14 at 08:25
  • i know, hopefully this will change in future updates of android tools. thank you for your replies – Gabi Radu Jul 16 '14 at 08:26
  • well its not so hard referencing a library project then doing the workaorunds in the links posted – Raghunandan Jul 16 '14 at 08:28

0 Answers0