Search code examples
androidbuild.gradleandroid-librarygradle-plugin

Why is my android library making an extra apk when used in another project?


I have created a simple android library. The problem is, whenever it is used in any project, and an apk is generated for the project, two different instances of the apk are installed.

enter image description here

Like in the example above, Once I add the library in the project and run it, two diffrent apks are installed.

I know the problem is with the library. You can access the libray here.

Below is the gradle file of my library

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

ext {
    bintrayRepo = 'KenyanCounties' // Repo name in bintray dashboard
    bintrayName = 'studios.luxurious.kenya47counties' // package name of the bintray repo

    publishedGroupId = 'com.martinmbae.kenyan.47counties'   // this is the ID we want to see in implementation line
    libraryName = 'kenyacountieslibrary'     // this is the module name of library
    artifact = 'library'        // this is the artifact we want to see in implementation line

    libraryDescription = 'An android library that displays all kenyan libraries for selection. Each library countains a name, county number and a flag' // description of library

    siteUrl = 'https://github.com/MartinMbae/Sample'    // git repo url
    gitUrl = 'https://github.com/MartinMbae/Sample.git' // git repo vcs url

    libraryVersion = '1.0.1'      // library version

    developerId = 'martinmbae'                // This is your bintray username
    developerName = 'Martin Mbae'              // Developer's name
    developerEmail = '[email protected]'                // Developer's email

    licenseName = 'The Apache Software License, Version 2.0'  // for example, The Apache Software License, Version 2.0
    licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'   // for example, http://www.apache.org/licenses/LICENSE-2.0.txt
    allLicenses = ["Apache-2.0"]    // array of licenses, for example, ["Apache-2.0"]
}



    android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

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

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
apply from: 'publish.gradle'
//apply from: 'bintray.gradle'

Solution

  • I think you need to check your manifest file

    I think you have added <intent-filter> in more than one activity

    Make sure <intent-filter> added in just your main or default activity like this

    SAMPLE CODE

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.asknilesh.demo">
    <uses-permission android:name="android.permission.INTERNET"/>
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".HomeActivity">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>