More than one file was found with OS independent path 'META-INF/proguard/androidx-annotations.pro'

本文介绍了解决在Android开发中遇到的重复依赖库错误的方法。当遇到‘MorethanonefilewasfoundwithOSindependentpath‘META-INF/proguard/androidx-annotations.pro’’错误时,可以通过检查并删除重复的依赖库来解决。

今天写安卓的时候碰到一个这样的错误
More than one file was found with OS independent path ‘META-INF/proguard/androidx-annotations.pro’

解决办法:检查自己添加的依赖库是否有重复的删掉即可

android { aaptOptions { cruncherEnabled = false additionalParameters '--warn-manifest-validation' } } android { packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/license.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/notice.txt' exclude 'META-INF/ASL2.0' } }把上面的代码整合进下面的代码apply plugin: 'com.android.application' android { compileSdkVersion 34 defaultConfig { applicationId "com.hik.netsdk.SimpleDemo" minSdkVersion 21 targetSdkVersion 34 versionCode 11 versionName "3.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true multiDexEnabled true ndk { abiFilters "armeabi-v7a","arm64-v8a" } configurations.all { resolutionStrategy { // 强制使用统一版本的 OkHttp force 'com.squareup.okhttp3:okhttp:4.9.1' // 解决可能的冲突 eachDependency { details -> if (details.requested.group == 'com.squareup.okhttp3') { details.useVersion '4.9.1' } } } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } sourceSets { main { res.srcDirs = [ 'src/main/res', 'src/main/res/layout/DevMgtUI', 'src/main/res/layout/BusinessUI' ] jniLibs.srcDirs = ['libs'] } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } buildToolsVersion = '28.0.3' } dependencies { // implementation files('libs/HCNetSDK.jar') // implementation files('libs/PlayerSDK_hcnetsdk.jar') // implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'com.google.android.material:material:1.5.0' // 替代 design implementation 'androidx.constraintlayout:constraintlayout:2.1.3' implementation 'androidx.legacy:legacy-support-v4:1.0.0' // 替代 support-v4 // testImplementation 'junit:junit:4.12' // androidTestImplementation 'androidx.test:runner:1.4.0' // androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' implementation 'io.github.ezviz-open:ezviz-sdk:5.20' // implementation 'com.ezviz.sdk:ezuikit:2.2.1' // implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) // implementation files('libs/ERTC_Android_SDK_1.5.0.1.aar') // 添加必要支持库 implementation 'com.google.code.gson:gson:2.8.5' // 海康SDK - 确保已添加 // implementation files('libs/hikvision-sdk.jar') implementation 'com.squareup.okhttp3:okhttp:4.9.1' implementation "androidx.media3:media3-exoplayer:1.3.1" implementation "androidx.media3:media3-exoplayer-hls:1.3.1" implementation "androidx.media3:media3-ui:1.3.1" implementation "androidx.media3:media3-datasource-okhttp:1.3.1" coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4' // 确保添加了基础库 implementation "androidx.media3:media3-common:1.3.1" }
最新发布
06-23
<think>我们将两个配置块整合到现有的android配置块中。注意:现有的android块中已经有一些配置,我们需要将aaptOptions和packagingOptions添加到其中,注意不要重复定义android块。现有代码中已经有一个android块,我们只需要将两个新的配置块(aaptOptions和packagingOptions)添加到android块内,与现有的compileSdkVersion、defaultConfig等并列。具体步骤:1.android块内,与defaultConfig、buildTypes等同一级别,添加aaptOptions和packagingOptions。2.注意格式,确保每个配置块正确闭合。修改后的android块将包含:compileSdkVersiondefaultConfigbuildTypessourceSetscompileOptionsbuildToolsVersionaaptOptions//新增packagingOptions//新增注意:aaptOptions和packagingOptions都是android块中的配置项,与defaultConfig等是平级的。我们按照要求将两个配置块整合进去。</think>我将把您提供的 `aaptOptions` 和 `packagingOptions` 整合到现有的 Android 应用构建配置中。以下是完整的 `build.gradle` 文件: ```groovy apply plugin: 'com.android.application' android { compileSdkVersion 34 defaultConfig { applicationId "com.hik.netsdk.SimpleDemo" minSdkVersion 21 targetSdkVersion 34 versionCode 11 versionName "3.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true multiDexEnabled true ndk { abiFilters "armeabi-v7a","arm64-v8a" } configurations.all { resolutionStrategy { // 强制使用统一版本的 OkHttp force 'com.squareup.okhttp3:okhttp:4.9.1' // 解决可能的冲突 eachDependency { details -> if (details.requested.group == 'com.squareup.okhttp3') { details.useVersion '4.9.1' } } } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } sourceSets { main { res.srcDirs = [ 'src/main/res', 'src/main/res/layout/DevMgtUI', 'src/main/res/layout/BusinessUI' ] jniLibs.srcDirs = ['libs'] } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } // 添加的 aaptOptions 配置 aaptOptions { cruncherEnabled = false // 禁用 PNG 压缩检查 additionalParameters '--warn-manifest-validation' // 启用清单验证警告 } // 添加的 packagingOptions 配置 packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/license.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/notice.txt' exclude 'META-INF/ASL2.0' } buildToolsVersion = '28.0.3' } dependencies { implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'com.google.android.material:material:1.5.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.3' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'io.github.ezviz-open:ezviz-sdk:5.20' implementation 'com.google.code.gson:gson:2.8.5' implementation 'com.squareup.okhttp3:okhttp:4.9.1' implementation "androidx.media3:media3-exoplayer:1.3.1" implementation "androidx.media3:media3-exoplayer-hls:1.3.1" implementation "androidx.media3:media3-ui:1.3.1" implementation "androidx.media3:media3-datasource-okhttp:1.3.1" coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4' implementation "androidx.media3:media3-common:1.3.1" } ``` ### 配置说明 1. **aaptOptions 配置**: ```groovy aaptOptions { cruncherEnabled = false // 禁用 PNG 压缩检查 additionalParameters '--warn-manifest-validation' // 启用清单验证警告 } ``` - `cruncherEnabled = false`:禁用 PNG 压缩检查,可以加快构建速度,特别是当项目中有大量 PNG 图片时 - `additionalParameters '--warn-manifest-validation'`:启用 AndroidManifest.xml 文件的验证警告,帮助发现潜在问题 2. **packagingOptions 配置**: ```groovy packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/LICENSE' // ... 其他排除项 } ``` - 这些排除规则解决了依赖库之间的冲突问题,防止多个库包含相同的许可证文件导致构建失败 - 特别适用于包含多个第三方库(如海康SDK、EZVIZ SDK等)的项目 ### 其他优化建议 1. **升级依赖版本**: ```groovy dependencies { implementation 'androidx.appcompat:appcompat:1.6.1' // 升级到最新稳定版 implementation 'com.google.android.material:material:1.11.0' // 其他依赖... } ``` 2. **启用构建缓存**(在 gradle.properties 中): ```properties org.gradle.caching=true android.enableBuildCache=true ``` 3. **配置 Dex 选项**: ```groovy android { dexOptions { preDexLibraries true // 预编译库以加快构建速度 javaMaxHeapSize "4g" // 增加内存分配 } } ``` 4. **启用 Jetifier**(如果需要支持旧版支持库): ```properties # gradle.properties android.enableJetifier=true ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值