Thursday, April 11, 2013

[android help] External library jar incomplete

android - External library jar incomplete - Stack Overflow



















I'm trying to add an external jar library to my Android project. It compiles and downloads to my device correctly but I'm getting the following logcat:



04-11 08:17:16.849: E/AndroidRuntime(16053): FATAL EXCEPTION: main
04-11 08:17:16.849: E/AndroidRuntime(16053): java.lang.NoClassDefFoundError: org.puredata.android.service.R$raw
04-11 08:17:16.849: E/AndroidRuntime(16053): at org.puredata.android.service.PdService.onCreate(PdService.java:184)
04-11 08:17:16.849: E/AndroidRuntime(16053): at android.app.ActivityThread.handleCreateService(ActivityThread.java:1951)
04-11 08:17:16.849: E/AndroidRuntime(16053): at android.app.ActivityThread.access$2500(ActivityThread.java:117)
04-11 08:17:16.849: E/AndroidRuntime(16053): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
04-11 08:17:16.849: E/AndroidRuntime(16053): at android.os.Handler.dispatchMessage(Handler.java:99)
04-11 08:17:16.849: E/AndroidRuntime(16053): at android.os.Looper.loop(Looper.java:130)


The problem seems to be that the R class isn't included in the library compilation. Through this question I arrived here where this confusing text states



Important change: We have changed the way Library Projects generate and package R classes:



  • The R class is not packaged in the jar output of Library Projects anymore.

  • Library Project do not generate the R class for Library Projects they depend on. Only main application projects generates the Library R classes alongside their own.

    This means that library projects cannot import the R class from another library project they depend on. This is not necessary anyway, as their own R class includes all the necessary resources. Note that app projects can still import the R classes from referenced Library Projects, but again, this is not needed as their own R classes include all the resources





So, I'm kind of stuck. How do I/Can I force a library to include its needed resources? If not, how can I use the R class in a library which I want to make available without sharing my project code?
























Android library projects are different from normal libraries. For versions of Android before API level 14, you cannot compile them into standalone jar files and include into your projects. Instead, you need to include them as library projects with your own Android project. That means that you need to have the full source code of the library project. Without it, you cannot use it as a library project.


When you include it as a library project into your own Android project and compile your project, the build tools will combine the resource definitions (R classes) from the library projects and your own projects and create one R class. You will then have access to resources from both your own project and library projects.


Starting with API level 14 library projects can be compiled into standalone jars and you can find the info on how to do this on google's developer's documentation site. Have a read through Android Library Projects documentation for more information.























default






.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...