Android Studio installs an APK for each module

I have a project created using Gradle in Android Studio v 0.3.2. My project has dependencies on two other modules (android library). The structure of the project is well defined using the build.gradle files. The problem is ... when I run the project on an Android device, I install 3 apk on my device. One of them is the main project (the only correct one), and the other two are imported modules (I do not want to install these two). How can I achieve this? Or what am I doing wrong?

Project Structure:

  • MyLibModule
  • Mainproject
  • MainProject-> libraries → MyOtherModule

Where MyLibModule is on the same path as the main project, because I also need this module in another project.

Just to be clear: the whole project built OK , all the dependencies are fine, but why am I getting 3 APKs on my device?

+7
android android-studio android-gradle apk
source share
3 answers

After a whole day struggling with this problem, I found the reason for this strange behavior. The problem was the manifestation of the library module. Before I switched to Android studio, I used Eclipse. And I had testActivity declared in the library project manifest. Removing all the test actions from the manifest of my library modules solved the problem. Now Android Studio installs only the MainProject APK.

Some codes: MyLibModule manifest:

<?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. An empty node application should remain in the manifest to avoid build errors.

+14
source share

remove intent filter from your library 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> 
+9
source share

This is because your libraries are defined in their build.gradle files as applications, not libraries. Find this line:

 apply plugin: 'android' 

and replace it with:

 apply plugin: 'android-library' 

You may need to make other changes to the assembly file, since not everything related to applications may be specified in the library assembly file. See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-projects for more details.

+1
source share

All Articles