在另一个项目中使用 Android 库项目 Activity [英] Using an Android library project Activity within another project
问题描述
我有一个 Android 库项目,我想在另一个 Android 项目中使用它.
I have an Android library project that I would like to use from within another Android project.
该库在其 AndroidManifest 中声明了一个 Activity.当我在第二个项目中尝试以下操作时:
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);
我收到以下异常:
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" />
但是还是不行
推荐答案
我相信你必须包括
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:
在清单文件中声明库组件
在应用项目的manifest文件中,必须添加应用程序将使用的所有组件的声明是从库项目导入.例如,您必须声明任何
、
、
、
等等在,以及
、
和类似元素.
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 库项目 Activity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!