Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio installs an APK for each module

I have an project, build with Gradle in Android Studio v 0.3.2. My project has dependencies to two other modules(android library). The project structure is well defined with build.gradle files. The problem is... when i run the project on an Android device, i get installed 3 apk's on my device. One is the main project(the only right one) and the other two are from the imported modules(theese two i don't want to get installed). How can i achieve this? Or what i'm doing wrong?

Project Structure:

  • MyLibModule
  • MainProject
  • MainProject->libraries->MyOtherModule

Where MyLibModule is at the same path as the Main project, because i also need this module in a other project.

Just to be clear: The whole project build's OK, all dependencies are OK, but why do i get 3 APK's on my device?

like image 286
Primoz990 Avatar asked Nov 25 '13 15:11

Primoz990


Video Answer


2 Answers

After a whole day struggling with this problem, i located the cause of this strange behaviour. The problem was the manifest of library module. Before i switched to Android studio i used Eclipse. And i had a testActivity declared in the manifest of the library project. Removing all test activities from the manifest's of my library modules solved the problem. Now Android Studio installs only the MainProject apk.

Some code: The manifest of MyLibModule:

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

    <uses-sdk android:minSdkVersion="7"/>
    <application>
        <activity
            android:name=".TestActivity"
            android:label="@string/app_name">
        </activity>
    </application>
</manifest>

Changed to:

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

    <uses-sdk android:minSdkVersion="7"/>
    <application>
    </application>
</manifest>

....And the same for MyOtherModule.

NOTE: the empty application node must stay in the manifest, to avoid build errors.

like image 156
Primoz990 Avatar answered Sep 20 '22 16:09

Primoz990


remove the intent-filter from your library's launch activity

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

Changed to

<application>
   <activity android:name=".MainActivity"/>
</application>
like image 36
tanshiwei Avatar answered Sep 17 '22 16:09

tanshiwei