Migration to Android Studio will lead to the installation of several applications for "projects with multiple projects with multiple projects"

I have

  • One main project that defines <action android:name="android.intent.action.MAIN" /> and <category android:name="android.intent.category.LAUNCHER" />
  • Several library projects, some of which define <action android:name="android.intent.action.MAIN" /> and <category android:name="android.intent.category.LAUNCHER" />

As long as I use Eclipse to create and run one main project with several library projects, only 1 application will be installed.

However, if I go to Android Studio to create and run one main project with several library projects, several applications will be installed .

depending on how many projects (regardless of the projects of the main project or library) determine <action android:name="android.intent.action.MAIN" /> and <category android:name="android.intent.category.LAUNCHER" />

I was wondering if there is some kind of configuration that I did wrong in Android Studio that forces me to install several applications when I build and run projects?

Currently, my only workaround is to remove these lines ( <action android:name="android.intent.action.MAIN" /> and <category android:name="android.intent.category.LAUNCHER" /> ) from all projects of the AndroidManifest.xml library. Is this a generic and proper way to import project libraries into Android Studio? Like in Eclipse, these lines do not install additional applications on my device.

This is what my project structure looks like

enter image description here

As you see the first icon of the folder, it looks different than the other icons in the folder. I assume this means that the first icon of the folder is the main project, the others are library projects.

If there is only one core project, how can multiple applications be installed?

+5
source share
3 answers

Eclipse uses only AndroidManifest.xml from the main application project. In Android Studio (and the Gradle build system), all manifests merge together.

The following lines inside the <activity> element in the manifest indicate that this action should be displayed on the start menu. If you do not want this, delete these lines.

 <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> 

All this is supposed behavior.

+7
source

There is another hacker way.

  • Take a look at your combined AndroidManifest.xml. It should be located at: <your_project>/build/intermediates/manifests/full/<debugOrRelease>/AndroidManifest.xml

  • Find the LAUNCHER <activity> . In your case, you should have more than 1 LAUNCHER <activity> . 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 was declared as LAUNCHER. The correct LAUNCHER should be com.stockhut.SplashScreenActivity .

  1. 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> 

    Pay attention to the tools:node="remove" marker tools:node="remove" . According to the Android manifest merge documentation :

A marker is a special attribute in the tool namespace used to express a specific decision on how to resolve conflicts.

Therefore, the <activity> with the tools:node="remove" marker tells Gradle to remove itself when there is a conflict. In other words, we somehow "force conflict." This is a bit hacky, but it works.

You can always check your combined AndroidManifest.xml in the above path.

+4
source

In Android studio, there can only be one project at a time that you can add. If you have a library with a project, you need to either add all the code inside the project, or you can create a jar for your library project and add them to your project.

Android studio has another version of gradle. If we want to use any library in the project, we can add their dependency in the "build.gradle" file of the project.

I am attaching a screenshot of the "build.gradle" file, please refer to it.

enter image description here

Now, Regarding library projects, (if this does not contribute to your project) The best approach is that in the Android manifest you should only set your specific activity as launch activity, as in most cases AndroidManifest libraries. xml Often contain some examples of actions (which should be removed) or Activity that you need for a subclass. A library project must have a minimal number of elements (insignificant). Most things should be in your manifest, including all permissions.

It is also defined on the Android developer site.

the "filter with" android.intent.action.MAIN and the Settings "android.intent.category.LAUNCHER" advertise the activity as the one that initiates the application, that is, the one that should be displayed in the application’s launch bar. Icon and label, set to therefore filters are displayed in the launcher. "

you can also link to the link ... http://developer.android.com/guide/topics/manifest/manifest-intro.html

+1
source

Source: https://habr.com/ru/post/1206041/


All Articles