如何调用打包在外部.jar库中的Activity?

时间:2015-11-20 18:03:43

标签: android frameworks shared-libraries

我正在尝试构建一个开发人员可以在自己的应用程序中使用的.jar库。我的库中有3个视图(活动),我希望开发人员能够在他们的应用程序中显示如下:

// Developer's activity
public class MainActivity extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            // This method returns an intent which calls 
            // an activity packaged in my .jar file
            startActivity(EvelynsLibrary.showView(this));

        }
    }

主库类EvelynsLibrary有一个静态'showView'方法,它接受一个活动(获取上下文),根据上下文和我的.jar中捆绑的Activity创建一个intent,并返回一个Intent,开发人员可以使用startActivity进行演示。

不确定是否需要,但我还将外部活动添加到调用应用的AndroidManifest.xml文件中,如下所示:

<activity
        android:name="com.evelyn.EvelynsActivity"
        android:label="Evelyn"
        android:configChanges="orientation|screenSize"
        android:screenOrientation="fullSensor">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

我收到以下错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.evelyn.EvelynsActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030002

这是我的整个错误(Logcat)输出:

11-19 02:52:30.760      597-642/? E/NetdConnector﹕ NDC Command {276 softap fwreload wlan0 STA} took too long (895ms)
11-19 02:52:35.245      597-644/? E/ConnectivityService﹕ Unexpected mtu value: android.net.wifi.WifiStateTracker@42bf90a8
11-19 12:05:26.209      597-642/? E/NetdConnector﹕ NDC Command {457 softap fwreload wlan0 STA} took too long (917ms)
11-19 12:05:30.793      597-644/? E/ConnectivityService﹕ Unexpected mtu value: android.net.wifi.WifiStateTracker@42bf90a8
11-19 12:05:34.167    1083-1354/? E/ActivityThread﹕ Failed to find provider info for com.google.android.wearable.settings
11-19 12:05:38.191    1083-1354/? E/ActivityThread﹕ Failed to find provider info for com.google.android.wearable.settings
11-19 12:08:56.234    2162-2162/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
11-19 12:08:56.274    2162-2162/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
11-19 23:18:00.632   1083-11946/? E/ActivityThread﹕ Failed to find provider info for com.google.android.wearable.settings
11-19 23:18:03.515   1083-11946/? E/ActivityThread﹕ Failed to find provider info for com.google.android.wearable.settings
11-19 23:36:43.087      597-644/? E/ConnectivityService﹕ Unexpected mtu value: android.net.wifi.WifiStateTracker@42bf90a8
11-20 01:03:10.368  13822-13822/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
11-20 01:03:10.488  13822-13822/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
11-20 01:03:17.034  13822-13822/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
11-20 01:04:16.552  13822-13822/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
11-20 01:05:18.422  13822-13822/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider

11-20 01:13:00.193  14643-14643/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
11-20 01:13:25.428  14643-14643/? E/ActivityThread﹕ Activity com.choiceofgames.diabolical.Diabolical has leaked ServiceConnection com.anjlab.android.iab.v3.BillingProcessor$1@42b11268 that was originally bound here
    android.app.ServiceConnectionLeaked: Activity com.choiceofgames.diabolical.Diabolical has leaked ServiceConnection com.anjlab.android.iab.v3.BillingProcessor$1@42b11268 that was originally bound here
            at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:979)
            at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:873)
            at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1561)
            at android.app.ContextImpl.bindService(ContextImpl.java:1544)
            at android.content.ContextWrapper.bindService(ContextWrapper.java:517)
            at com.anjlab.android.iab.v3.BillingProcessor.bindPlayServices(BillingProcessor.java:102)
            at com.anjlab.android.iab.v3.BillingProcessor.<init>(BillingProcessor.java:95)
            at com.choiceofgames.choicescript.Billing.<init>(Billing.java:57)
            at com.choiceofgames.choicescript.ChoiceScriptActivity.onCreate(ChoiceScriptActivity.java:191)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
11-20 01:13:27.760  14643-14643/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
11-20 01:13:57.899  14643-14643/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
11-20 01:14:27.999  14643-14643/? E/ActivityThread﹕ Failed to find provider info for 

11-20 01:36:32.631  14643-14643/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
11-20 01:37:02.740  14643-14643/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
11-20 01:37:32.830  14643-14643/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
11-20 01:38:02.949  14643-14643/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
11-20 01:38:33.058  14643-14643/? E/ActivityThread﹕ Failed to find provider info for 
11-20 11:13:03.752      597-642/? E/NetdConnector﹕ NDC Command {639 softap fwreload wlan0 STA} took too long (995ms)
11-20 11:13:08.276      597-644/? E/ConnectivityService﹕ Unexpected mtu value: android.net.wifi.WifiStateTracker@42bf90a8
11-20 11:13:11.629   1083-18466/? E/ActivityThread﹕ Failed to find provider info for com.google.android.wearable.settings
11-20 11:13:15.303   1083-18466/? E/ActivityThread﹕ Failed to find provider info for com.google.android.wearable.settings
11-20 12:19:22.863      597-612/? E/WindowManager﹕ Starting window AppWindowToken{43a69c40 token=Token{42d66640 ActivityRecord{42840e90 u0 com.example.myExampleApp/.MyActivity t26}}} timed out
11-20 12:19:42.102  25049-25049/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.myExampleApp, PID: 25049
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myExampleApp/com.example.myExampleApp.MyActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at android.content.ComponentName.<init>(ComponentName.java:77)
            at android.content.Intent.<init>(Intent.java:3813)
            at com.evelyn.EvelynsLibrary.showView(EvelynsLibrary.java:22)
            at com.example.myExampleApp.MyActivity.onCreate(MyActivity.java:17)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
11-20 12:42:19.597      833-833/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid parameter app
11-20 12:42:19.597      833-833/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
11-20 12:42:20.377      833-833/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid parameter app
11-20 12:42:20.377      833-833/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
11-20 12:42:20.698  26094-26100/com.example.myExampleApp E/jdwp﹕ Failed sending reply to debugger: Broken pipe
11-20 12:42:30.687      597-612/? E/WindowManager﹕ Starting window AppWindowToken{43f4bd98 token=Token{4311d8e8 ActivityRecord{42cefb90 u0 com.example.myExampleApp/.MyActivity t27}}} timed out
11-20 12:48:28.456    1083-1569/? E/PlayLoggerImpl﹕ Service was disconnected.  Will try caching.
11-20 12:49:00.297  26565-26581/? E/libEGL﹕ validate_display:254 error 3008 (EGL_BAD_DISPLAY)
11-20 12:49:00.358  26565-26584/? E/OMXMaster﹕ A component of name 'OMX.qcom.audio.decoder.aac' already exists, ignoring this one.
11-20 12:51:29.873      833-833/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid parameter app
11-20 12:51:29.873      833-833/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
11-20 12:51:30.624      833-833/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid parameter app
11-20 12:51:30.624      833-833/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
11-20 12:51:32.996  26719-26719/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.myapp, PID: 26719
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.MyExampleStartActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.myapp/com.evelyn.EvelynsActivity}; have you declared this activity in your AndroidManifest.xml?
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.myapp/com.evelyn.EvelynsActivity}; have you declared this activity in your AndroidManifest.xml?
            at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
            at android.app.Activity.startActivityForResult(Activity.java:3424)
            at android.app.Activity.startActivityForResult(Activity.java:3385)
            at android.app.Activity.startActivity(Activity.java:3627)
            at android.app.Activity.startActivity(Activity.java:3595)
            at com.example.myapp.MyExampleStartActivity.onCreate(MyExampleStartActivity.java:17)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
11-20 12:51:33.977  10994-10994/? E/chromium﹕ [ERROR:layer_tree_host_impl.cc(2121)] Forcing zero-copy tile initialization as worker context is missing
11-20 12:51:38.232      833-841/? E/DataBuffer﹕ Internal data leak within a DataBuffer object detected!  Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: com.google.android.gms.common.data.DataHolder@4283e910)
11-20 12:51:38.232      833-841/? E/DataBuffer﹕ Internal data leak within a DataBuffer object detected!  Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: com.google.android.gms.common.data.DataHolder@4289b088)
11-20 12:51:38.232      833-841/? E/DataBuffer﹕ Internal data leak within a DataBuffer object detected!  Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: com.google.android.gms.common.data.DataHolder@42816e80)
11-20 12:51:38.232      833-841/? E/DataBuffer﹕ Internal data leak within a DataBuffer object detected!  Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: com.google.android.gms.common.data.DataHolder@42a4b5b8)

11-20 12:53:44.995      833-833/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid parameter app
11-20 12:53:44.995      833-833/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
11-20 12:53:45.786      833-833/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid parameter app
11-20 12:53:45.786      833-833/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
11-20 12:53:47.988      597-610/? E/qcom_sensors_hal﹕ hal_process_time_resp: Resetting rollover count from 0 to 1
11-20 12:53:48.138  27195-27195/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.myapp, PID: 27195
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.evelyn.EvelynsActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030002
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030002
            at android.content.res.Resources.getValue(Resources.java:1123)
            at android.content.res.Resources.loadXmlResourceParser(Resources.java:2309)
            at android.content.res.Resources.getLayout(Resources.java:939)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
            at android.app.Activity.setContentView(Activity.java:1929)
            at com.evelyn.EvelynsActivity.setLayout(MainActivity.java:34)
            at com.evelyn.EvelynsActivity.onCreate(MainActivity.java:146)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
11-20 12:54:02.352      597-633/? E/InputDispatcher﹕ channel '42877b50 com.example.myapp/com.example.myapp.MyExampleStartActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
11-20 12:54:05.135      597-610/? E/qcom_sensors_hal﹕ hal_process_time_resp: Resetting rollover count from 0 to 1
11-20 12:54:05.275  27304-27304/com.example.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.myapp, PID: 27304
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.evelyn.EvelynsActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030002
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030002
            at android.content.res.Resources.getValue(Resources.java:1123)
            at android.content.res.Resources.loadXmlResourceParser(Resources.java:2309)
            at android.content.res.Resources.getLayout(Resources.java:939)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
            at android.app.Activity.setContentView(Activity.java:1929)
            at com.evelyn.EvelynsActivity.setLayout(MainActivity.java:34)
            at com.evelyn.EvelynsActivity.onCreate(MainActivity.java:146)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)

问题:我哪里错了?如何实现这一点并允许开发人员调用我的.jars活动?

1 个答案:

答案 0 :(得分:1)

你应该创建一个Android库项目而不是jar