为什么我的 android 库在另一个项目中使用时会生成一个额外的 apk?
Why is my android library making an extra apk when used in another project?
我创建了一个简单的 android 库。问题是,无论何时在任何项目中使用它,并为该项目生成一个 apk,都会安装两个不同的 apk 实例。
就像上面的例子一样,一旦我在项目中添加库并 运行 它,就会安装两个不同的 apk。
我知道问题出在图书馆。 You can access the libray here.
下面是我图书馆的gradle文件
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 = 'martinmbae.codemaster@gmail.com' // 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'
我认为您需要检查清单文件
我想你在不止一个activity
中添加了<intent-filter>
确保 <intent-filter>
像这样添加到您的主要或默认 activity 中
示例代码
<?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>
问题是除了主应用程序中的启动器之外,您的库还在其清单中声明了一个启动器 Activity
:
<activity android:name=".activities.Kenya47Counties">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
如果您将其从图书馆的 AndroidManifest.xml
中删除,您的问题应该会消失。
我创建了一个简单的 android 库。问题是,无论何时在任何项目中使用它,并为该项目生成一个 apk,都会安装两个不同的 apk 实例。
就像上面的例子一样,一旦我在项目中添加库并 运行 它,就会安装两个不同的 apk。
我知道问题出在图书馆。 You can access the libray here.
下面是我图书馆的gradle文件
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 = 'martinmbae.codemaster@gmail.com' // 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'
我认为您需要检查清单文件
我想你在不止一个activity
中添加了<intent-filter>
确保 <intent-filter>
像这样添加到您的主要或默认 activity 中
示例代码
<?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>
问题是除了主应用程序中的启动器之外,您的库还在其清单中声明了一个启动器 Activity
:
<activity android:name=".activities.Kenya47Counties">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
如果您将其从图书馆的 AndroidManifest.xml
中删除,您的问题应该会消失。