当项目中依赖的第三方库越来越多时,有可能会出现两个或多个依赖库中存在同一个名称的文件。如果这样,Gradle在打包时就会提示错误。那么我们就可以根据提示,然后使用以下方法将重复的文件剔除
例如:
我这边提示错误:关键部分是: ‘META-INF/rxjava.properties’
解决:在主项目的build.gradle文件中加入packagingOptions 配置:
excldue后的内容根据错误提示来添加
PS: 如果系统提示无法删除,就看log的路径自己去删除文件(需要先关闭As)
packagingOptions {exclude 'META-INF/rxjava.properties'}
添加位置:
if (isUserModule.toBoolean()) {
apply plugin: 'com.android.library'
} else {
apply plugin: 'com.android.application'
}
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
if (isUserModule.toBoolean()) {
manifest.srcFile 'src/main/release/AndroidManifest.xml'
//release模式下排除debug文件中的所有java文件
java {
exclude 'debug/**'
}
} else {
manifest.srcFile 'src/main/debug/AndroidManifest.xml'
}
}
}
//################ 在这里添加 ##########################//
packagingOptions {exclude 'META-INF/rxjava.properties'}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
api project(':Provider')
}