简体   繁体   中英

Android rename: unable to find explicit activity class

I have a live wallpaper based off of some open source code that I heavily modified. As the last item, I right clicked on it in Eclipse to change the package name and all was well with the world. The wallpaper works right. The settings menu works right. But when I try to click an item in the settings menu to launch another activity, I get:

 10-10 16:16:56.215: E/AndroidRuntime(13825): FATAL EXCEPTION: main
 10-10 16:16:56.215: E/AndroidRuntime(13825): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.nightscapecreations.orionkeysfree/ffvideolivewallpaper.frankandrobot.com.extLinkNC}; have you declared this activity in your AndroidManifest.xml?

Here is the manifest file:

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

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

    <!-- Tell the system this app requires OpenGL ES 2.0. -->
    <uses-feature android:glEsVersion="0x00020000" android:required="true" />

    <uses-feature android:name="android.software.live_wallpaper" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <service
            android:name="ffvideolivewallpaper.frankandrobot.com.VideoLiveWallpaper"
            android:label="@string/wallpaper"
            android:permission="android.permission.BIND_WALLPAPER" >
            <intent-filter>
                <action android:name="android.service.wallpaper.WallpaperService" />
            </intent-filter>

            <meta-data
                android:name="android.service.wallpaper"
                android:resource="@xml/wallpaper" />
        </service>

        <activity
            android:name="ffvideolivewallpaper.frankandrobot.com.VideoLiveWallpaper"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name="ffvideolivewallpaper.frankandrobot.com.VideoWallpaperSettings"
            android:exported="true"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name="ffvideolivewallpaper.frankandrobot.com.About"
            android:exported="true"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name="ffvideolivewallpaper.frankandrobot.com.License"
            android:exported="true"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name="ffvideolivewallpaper.frankandrobot.com.SelectVideo"
            android:exported="true"
            android:label="@string/app_name" >
        </activity>

        <activity
            android:name="ffvideolivewallpaper.frankandrobot.com.extLinkNC"
            android:exported="true"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name="ffvideolivewallpaper.frankandrobot.com.extLinkZazzle"
            android:exported="true"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name="ffvideolivewallpaper.frankandrobot.com.extLinkFacebook"
            android:exported="true"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name="ffvideolivewallpaper.frankandrobot.com.extLinkGooglePlus"
            android:exported="true"
            android:label="@string/app_name" >
        </activity>
    </application>

</manifest>

Here is the About activity, as an example, which was confirmed working before this change:

package ffvideolivewallpaper.frankandrobot.com;

import android.app.Activity;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;
import android.content.Intent;
import android.view.View;
import com.nightscapecreations.anim1.R;

public class About extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about);
        TextView t = (TextView) findViewById(R.id.about_box);
        t.setMovementMethod(LinkMovementMethod.getInstance());
    }

    public void showLicense(View view) {
    startActivity(new Intent(About.this, License.class));
    }
}

ffvideolivewallpaper.frankandrobot.com was the old package name. Eclipse added the prefix to the android:name for all activities during the package name change. What I don't understand is that if this is incorrect then why does the wallpaper work at all since the service name is qualified the exact same way?




EDIT

Dunamis made an excellent catch. The original name was ffvideolivewallpaper.frankandrobot.com, but it's been through several name changes since then. One such name was com.nightscapecreations.orionkeysfree. It looks like there was still a reference to that old name which I totally missed in the settings xml file. Example:

<PreferenceCategory android:title="Links and Information" >
        <PreferenceScreen android:title="Visit Nightscape Creations"
            android:summary="See more live wallpapers, get free static wallpapers, and learn about NC by visiting us online." >
            <intent
                android:targetClass="ffvideolivewallpaper.frankandrobot.com.extLinkNC"
                android:targetPackage="com.nightscapecreations.orionkeysfree" />
        </PreferenceScreen>

However, this still does not work. I tried every combination of fully qualified name and simple dot notation ".extLinkFacebook" between this file and the manifest file, but without success. Here is the error I'm receiving now with both names fully qualified:

10-11 08:19:43.176: E/AndroidRuntime(25204): FATAL EXCEPTION: main
10-11 08:19:43.176: E/AndroidRuntime(25204): android.content.ActivityNotFoundException: Unable to find explicit activity class {ffvideolivewallpaper.frankandrobot.com/ffvideolivewallpaper.frankandrobot.com.extLinkFacebook}; have you declared this activity in your AndroidManifest.xml?

Here is the settings file for reference:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

    <PreferenceCategory android:title="Wallpaper Settings">
        <ffvideolivewallpaper.frankandrobot.com.PrefsSlider
            android:key="fps"
            android:title="Framerate"
            android:summary="Set the target framerate.  Lower framerates will decrease resource usage.  Requires wallpaper restart to take effect."
            android:layout_width="fill_parent"
            android:defaultValue="30"
            android:orientation="vertical" />

<!--        <ListPreference -->
<!--                android:enabled="true" -->
<!--                android:key="resolution" -->
<!--                android:title="Resolution" -->
<!--                android:summary="Ultra resolution may decrease framerate.  Only recommended for high end devices." -->
<!--                android:entries="@array/prefs_resolutionEntries" -->
<!--                android:entryValues="@array/prefs_resolutionValues" -->
<!--                android:defaultValue="512" /> -->

<!--        <ListPreference -->
<!--                android:enabled="true" -->
<!--                android:key="frameTonality" -->
<!--                android:title="Filters" -->
<!--                android:summary="Various effects and filters can be applied to the animation" -->
<!--                android:entries="@array/prefs_tonalityEntries" -->
<!--                android:entryValues="@array/prefs_tonalityValues" -->
<!--                android:defaultValue="1" /> -->
    </PreferenceCategory>



    <PreferenceCategory android:title="Links and Information" >
        <PreferenceScreen android:title="Visit Nightscape Creations"
            android:summary="See more live wallpapers, get free static wallpapers, and learn about NC by visiting us online." >
            <intent
                android:targetClass="ffvideolivewallpaper.frankandrobot.com.extLinkNC"
                android:targetPackage="ffvideolivewallpaper.frankandrobot.com" />
        </PreferenceScreen>

        <PreferenceScreen
            android:title="@string/prefsProductsHeading"
            android:summary="@string/prefsProductsSummary" >
            <intent
                android:targetClass="ffvideolivewallpaper.frankandrobot.com.extLinkZazzle"
                android:targetPackage="ffvideolivewallpaper.frankandrobot.com" />
        </PreferenceScreen>

        <PreferenceScreen android:title="Like on Facebook" >
            <intent
                android:targetClass="ffvideolivewallpaper.frankandrobot.com.extLinkFacebook"
                android:targetPackage="ffvideolivewallpaper.frankandrobot.com" />
        </PreferenceScreen>

        <PreferenceScreen android:title="Like on Google+" >
            <intent
                android:targetClass="ffvideolivewallpaper.frankandrobot.com.extLinkGooglePlus"
                android:targetPackage="ffvideolivewallpaper.frankandrobot.com" />
        </PreferenceScreen>
    </PreferenceCategory>



    <PreferenceCategory android:title="About" >
        <PreferenceScreen android:title="About" >
            <intent
                android:targetClass="ffvideolivewallpaper.frankandrobot.com.About"
                android:targetPackage="ffvideolivewallpaper.frankandrobot.com" />
        </PreferenceScreen>
    </PreferenceCategory>

</PreferenceScreen>

Shortly after adding the bounty I found a workaround for this problem. I'm still not sure what the original issue was, though.

To resolve this I renamed the ffvideolivewallpaper.frankandrobot.com package, which contained all the code, to match that of the manifest. I had hesitated to do this as it required an update to the video.c file to change all "ffvideolivewallpaper_frankandrobot_com" references in native calls to "com_nightscapecreations_anim1" and the last time I had tried that I hosed the app so bad I had to return to a backup copy. However, after doing so today, and then search/replacing through the app to find all other references, I was able to get it to work.

I would still like to know the answer to the above question as it stands, though. It would be much easier to create new apps off this base in the future if I could just leave the main package name alone instead of bothering with a search/replace. If no one knows, though, I will just mark this as the answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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