e-mre
e-mre

Reputation: 3363

Opening activity in a library as the main activity

I am trying to build two different versions of my application. A free and a priced version. Searching through the net I see the recommended way is to use libraries. So I turned my project into a library project by opening project properties and ticking "Is Library" option and creating a separate application project. I also selected the library project as a reference in the "properties >> project references" page in the application project.

The application project contains no activities. I am trying to open the main activity defined in the library project as my application project's main activity. I know I have to declare the activities in my application's manifest that are in the library project.

Here is the manifest file of my application project:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.emret.myapplication.free"
    android:versionCode="1"
    android:versionName="1.0" >

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.emret.myapplication.MainActivity"
        android:label="My application" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>

Here is the manifest file in my library project:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.emret.myapplication"
    android:versionCode="1"
    android:versionName="1.0" >

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="Resimler ve Sesler" 
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>

The following exception is thrown as soon as I run the application project: 12-17 14:05:25.249: E/AndroidRuntime(1027): Caused by: java.lang.ClassNotFoundException: com.emret.myapplication.MainActivity

What am I missing?

Upvotes: 0

Views: 1558

Answers (1)

Torben
Torben

Reputation: 3913

It seems that your library project does not get exported into the APK file. The last time I encountered this kind of a situation myself, the reason was because I had added the library project via "Properties -> Java Build Path -> Projects".

The situation was corrected once I removed it from the Java build path and added is an Android library via "Properties -> Android -> Add..."

Upvotes: 2

Related Questions