Android Studio builds two applications for the same project simultaenously

泄露秘密 提交于 2019-12-12 09:47:35

问题


I'm making an app using Android Studio v0.5.9, which has a library project as a dependency. But, every time I run the project two apks having the same name and icon, are deployed to my device. The first apk(app) contains my main module, whereas, the second one is the library project itself. However, when I run the same project from Eclipse, only one apk is deployed and it works perfectly.

Here are some screenshots of the problem -

First App(My module) -

Second App(library project) -

top-level build.gradle file -

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

main module build.gradle file -

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.3'
    defaultConfig {
        packageName 'com.Swap.Rooms'
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName '1.0'
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:19.0.1'
    compile 'com.android.support:appcompat-v7:19.0.1'
    compile 'com.android.support:appcompat-v7:19.+'
    compile project(':lib')
}

library project build.gradle file -

apply plugin: 'android-library'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        packageName "com.jfeinstein.jazzyviewpager"
        minSdkVersion 4
        targetSdkVersion 17
    }

    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:+'
    compile files('libs/nineoldandroids-2.4.0.jar')
}

settings.gradle -

include ':app'
include ':lib'

Please help me to fix this. Thanks in advance!!


回答1:


Maybe this will be helpful for others.

Gradle is doing manifest merge for library projects as well. So issue was to keep AndroidManifes.xml unchanged from library. It had application node for demo purposes and this node was successfully merged to main AndroidManifest.xml.

I'm going to submit issue to Google since I think it should prevent or warn about such situation.




回答2:


Eugen Martynov answer is correct but i decided to reiterate what he said in layman's terms.

Go through your libraries and check their AndroidManifest.xml. One of them should have an <application> tag in it. Remove the tag and the double app problem will be solved.




回答3:


The specific element in the ApplicationManifest.xml, that affects creating multiple launcher icons is the <intent-filter> containing <category android:name="android.intent.category.LAUNCHER"/>. Removing this <intent-filter> will give you control over the number of launcher icons. You can read a bit more elaborate SO answer here.



来源:https://stackoverflow.com/questions/24106654/android-studio-builds-two-applications-for-the-same-project-simultaenously

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!