Reputation: 42642
I have
<action android:name="android.intent.action.MAIN" />
and <category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
and <category android:name="android.intent.category.LAUNCHER" />
While I'm using Eclipse to build & run single main project with multiple library projects, only 1 app will be installed.
However, if I migrate to Android Studio to build & run single main project with multiple library projects, multiple apps will be installed,
depending on how many projects (regardless main project or library projects) define <action android:name="android.intent.action.MAIN" />
and <category android:name="android.intent.category.LAUNCHER" />
I was wondering, is there any configuration I had done wrong in Android Studio, which causes multiple app to be installed, when I build & run the projects?
Currently, my only workaround is to remove those lines (<action android:name="android.intent.action.MAIN" />
and <category android:name="android.intent.category.LAUNCHER" />
) from all library projects' AndroidManifest.xml
. Is that common & correct way, to import project libraries in Android Studio? As in Eclipse, those lines don't install extra apps into my device.
This is how my Project Structure looks like
As you can see the first folder icon, looks different than rest of the folder icons. I guess that indicate, the first folder icon is main project, the others are library projects.
If there is only 1 main project, how come there can be multiple apps being installed?
Upvotes: 5
Views: 995
Reputation: 710
There's another hackish way.
Look up at your merged AndroidManifest.xml. It should be located at:
<your_project>/build/intermediates/manifests/full/<debugOrRelease>/AndroidManifest.xml
Search for the LAUNCHER <activity>
tag. In your case you should have more than 1 LAUNCHER <activity>
tags. My case looks like this:
<activity
android:name="com.stockhut.SplashScreenActivity"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" >
</action>
<category android:name="android.intent.category.LAUNCHER" >
</category>
</intent-filter>
</activity>
...
<activity
android:name="com.todddavies.components.progressbar.main"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In my case, com.todddavies.components.progressbar.main
is a library project with a sample project that has been declared as LAUNCHER. The correct LAUNCHER should be com.stockhut.SplashScreenActivity
.
Open AndroidManifest.xml in your main project, add the following:
<activity
android:name="com.todddavies.components.progressbar.main"
android:label="@string/app_name" tools:node="remove" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Take note on the Marker tools:node="remove"
. According to Android Manifest Merger Documentation:
A marker is a special attribute, in the tools namespace, used to express a specific decision for how to resolve conflicts.
Therefore an <activity>
tag with the marker tools:node="remove"
will tell Gradle to remove itself when there's a conflict. In other words, we are somehow "forcing a conflict". It is a little hackish, but it works.
You can always verify your merged AndroidManifest.xml in the abovementioned path.
Upvotes: 4
Reputation: 38223
In Eclipse only the AndroidManifest.xml
from main app project is used. In Android Studio (and Gradle build system) all the manifests are merged together.
The following lines inside an <activity>
element in your manifest indicate that that activity should be shown in the launcher menu. If you do not wish this, remove those lines.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
All of this is intended behavior.
Upvotes: 7
Reputation: 3376
In Android studio their can be only one project at a time that can be added. If you have library with project then you have to either add whole code inside you project or you can create jar for your library project and add them into your project.
There is another option of gradle in Android studio. If we want to use any library in project we can add their dependency in "build.gradle" file of Project.
I am attaching a screen shot of "build.gradle" file please refer to it.
Now , As far as Library Projects are concerned , (if it is not contributing to your project) The Best Approach is that in Android manifest you should set only your defined activity as a launcher activity ,As In Most cases libraries AndroidManifest.xml Often contain some sample Activity (which should be removed), or Activity which you need to subclass , There should be minimal defined things in the library project (negligible) most of the things should be in your Manifest including all permission.
Also it is define on android developer site
"a filter with "android.intent.action.MAIN" and "android.intent.category.LAUNCHER" settings advertises an activity as one that initiates an application — that is, as one that should be displayed in the application launcher. The icon and label set in the filter are therefore the ones displayed in the launcher."
you can refer the link also... http://developer.android.com/guide/topics/manifest/manifest-intro.html
Upvotes: 1