Question

I have a lib.apk that is sent by server and received by my application and then saved on sdcard.now I want run activities of inside my library but when I try do it, it gives me error do you define activity in manifest. I added activity tag to manifest of my lib but it still didn't work. Can anyone give any idea?

manifest file of my lib

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.lib"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.lib.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
    </application>

</manifest>

logcat error

11-20 05:16:49.918: W/System.err(6721): java.lang.reflect.InvocationTargetException
11-20 05:16:49.938: W/System.err(6721):     at java.lang.reflect.Method.invokeNative(Native Method)
11-20 05:16:49.948: W/System.err(6721):     at java.lang.reflect.Method.invoke(Method.java:511)
11-20 05:16:49.948: W/System.err(6721):     at com.example.myapp2.MainActivity.onCreate(MainActivity.java:29)
11-20 05:16:49.948: W/System.err(6721):     at android.app.Activity.performCreate(Activity.java:5104)
11-20 05:16:49.948: W/System.err(6721):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-20 05:16:49.948: W/System.err(6721):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11-20 05:16:49.958: W/System.err(6721):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
11-20 05:16:49.958: W/System.err(6721):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-20 05:16:49.958: W/System.err(6721):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
11-20 05:16:49.958: W/System.err(6721):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-20 05:16:49.969: W/System.err(6721):     at android.os.Looper.loop(Looper.java:137)
11-20 05:16:49.969: W/System.err(6721):     at android.app.ActivityThread.main(ActivityThread.java:5041)
11-20 05:16:49.969: W/System.err(6721):     at java.lang.reflect.Method.invokeNative(Native Method)
11-20 05:16:49.969: W/System.err(6721):     at java.lang.reflect.Method.invoke(Method.java:511)
11-20 05:16:49.969: W/System.err(6721):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-20 05:16:49.978: W/System.err(6721):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-20 05:16:49.978: W/System.err(6721):     at dalvik.system.NativeStart.main(Native Method)
11-20 05:16:49.978: W/System.err(6721): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.myapp2/com.example.lib.MainActivity}; have you declared this activity in your AndroidManifest.xml?
11-20 05:16:49.988: W/System.err(6721):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
11-20 05:16:50.000: W/System.err(6721):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
11-20 05:16:50.008: W/System.err(6721):     at android.app.Activity.startActivityForResult(Activity.java:3370)
11-20 05:16:50.008: W/System.err(6721):     at android.app.Activity.startActivityForResult(Activity.java:3331)
11-20 05:16:50.008: W/System.err(6721):     at android.app.Activity.startActivity(Activity.java:3566)
11-20 05:16:50.019: W/System.err(6721):     at android.app.Activity.startActivity(Activity.java:3534)
11-20 05:16:50.028: W/System.err(6721):     at com.example.lib.Main.onCreate(Main.java:32)
Was it helpful?

Solution

You cannot run activties that have not been installed on the phone. Just having an APK on the SD-card is not enough. This APK will need to be installed on the device.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top