简体   繁体   English

外部库jar不完整

[英]External library jar incomplete

I'm trying to add an external jar library to my Android project. 我正在尝试将外部jar库添加到我的Android项目中。 It compiles and downloads to my device correctly but I'm getting the following logcat: 它正确编译并下载到我的设备,但我得到以下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. 问题似乎是R类未包含在库编译中。 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: 重要更改:我们更改了Library Projects生成和打包R类的方式:

  • The R class is not packaged in the jar output of Library Projects anymore. R类不再打包在Library Projects的jar输出中。
  • Library Project do not generate the R class for Library Projects they depend on. Library Project不为它们所依赖的库项目生成R类。 Only main application projects generates the Library R classes alongside their own. 只有主应用程序项目与它们自己一起生成Library R类。

    This means that library projects cannot import the R class from another library project they depend on. 这意味着库项目无法从他们依赖的另一个库项目中导入R类。 This is not necessary anyway, as their own R class includes all the necessary resources. 无论如何,这不是必需的,因为他们自己的R类包括所有必要的资源。 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 请注意,应用程序项目仍然可以从引用的库项目中导入R类,但同样不需要这样做,因为它们自己的R类包含所有资源

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? 如果没有,我怎样才能在我想要提供的库中使用R类而不共享我的项目代码?

Android library projects are different from normal libraries. Android库项目与普通库不同。 For versions of Android before API level 14, you cannot compile them into standalone jar files and include into your projects. 对于API级别14之前的Android版本,您无法将它们编译为独立的jar文件并包含在您的项目中。 Instead, you need to include them as library projects with your own Android project. 相反,您需要将它们作为库项目包含在您自己的Android项目中。 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. 当您将它作为库项目包含到您自己的Android项目中并编译您的项目时,构建工具将组合库项目和您自己的项目中的资源定义(R类)并创建一个R类。 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. 从API级别14开始,库项目可以编译到独立的jar中,您可以在google开发人员的文档站点上找到有关如何执行此操作的信息。 Have a read through Android Library Projects documentation for more information. 阅读Android Library Projects文档以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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