在另一个项目中使用Android库项目活动

在另一个项目中使用Android库项目活动

本文介绍了在另一个项目中使用Android库项目活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android库项目,我想从另一个Android项目中使用。

I have an Android library project that I would like to use from within another Android project.

图书馆在其AndroidManifest声明的活动。当我尝试第二个项目中的以下内容:

The library has a Activity declared in its AndroidManifest. When I try the following within the second project:

        Intent intent = new Intent(this, ReaderActivity.class);
        startActivity(intent);

我得到以下异常:

I get the following exception:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.digitalpages.reader.demo/br.com.digitalpages.reader.demo.ReaderDemoActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {br.com.digitalpages.reader.demo/br.com.digitalpages.reader.ReaderActivity}; have you declared this activity in your AndroidManifest.xml?
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
...
 Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {br.com.digitalpages.reader.demo/br.com.digitalpages.reader.ReaderActivity}; have you declared this activity in your AndroidManifest.xml?
     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
...

我如何从其他项目打开活动?

How can I open the Activity from the another project?

编辑:通过用户的答案我添加下面一行到我的第二个项目

By users answers I added the following line into my second project

<uses-library android:name="br.com.digitalpages.reader" android:required="true" />

但它仍然不工作

But it's still doesn't works

推荐答案

我相信你必须包括在&lt;活性GT;在自己的Andr​​oidManifest.xml - 我不认为它被接走库。我没有我的那个方便的参考。

I believe you must include the <activity> in your own AndroidManifest.xml -- I don't think it gets picked up from a library. I don't have my reference for that handy.

更新:这是官方的解决方案。从商务部

Update: It's official solution. From the doc:

声明库组件清单文件中

在应用程序项目的清单文件,你必须添加  所有组件的声明,该应用程序都将使用  从库项目导入。例如,您必须声明任何  &LT;活性GT; &LT;服务&GT; &LT;接收器&GT; &LT;供应商&GT; ,等等,以及  &LT;许可&GT; &LT;使用库&GT; ,以及类似的元素

In the manifest file of the application project, you must add declarations of all components that the application will use that are imported from a library project. For example, you must declare any <activity>, <service>, <receiver>, <provider>, and so on, as well as <permission>, <uses-library>, and similar elements.

声明应由引用库组件的  完全合格的包名,在适当情况下。

Declarations should reference the library components by their fully-qualified package names, where appropriate.

这篇关于在另一个项目中使用Android库项目活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 23:02