Duplicate files copied in APK META-INF/license.txt

本文介绍了如何解决在Android项目中因引入spring for Android依赖导致的重复文件错误问题,提供了具体的Gradle配置示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在尝试使用AndroidAnnotations框架的REST API时,在导入spring for Android包后仅编译的话不会报错,但是当运行时无法编译通过,并报一下错误:

[java]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;">Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.  
  2. > com.android.build.api.transform.TransformException:   
  3.             com.android.builder.packaging.DuplicateFileException:   
  4.             Duplicate files copied in APK META-INF/license.txt  
  5.     File1: C:\Users\sea\.gradle\caches\modules-2\files-2.1\org.springframework.android  
  6.             \spring-android-rest-template\1.0.1.RELEASE\e132d929bd181941f79b0d63edafb8a86ae6fd33  
  7.             \spring-android-rest-template-1.0.1.RELEASE.jar  
  8.     File2: C:\Users\sea\.gradle\caches\modules-2\files-2.1\org.springframework.android  
  9.             \spring-android-core\1.0.1.RELEASE\e68f0e8e4b636ee30c4de58953be38d9b72a5e3b  
  10.             \spring-android-core-1.0.1.RELEASE.jar</span>  
解决办法是在Model的build.gradle中添加一下内容:

[java]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. android {  
  2.   
  3.     packagingOptions {  
  4.     exclude 'META-INF/LICENSE.txt'  
  5.     }  
  6.   
  7. }  
与之类似的,可以把完整的加进去

[java]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. android {  
  2.       
  3.   
  4.     packagingOptions {  
  5.         exclude 'META-INF/DEPENDENCIES.txt'  
  6.         exclude 'META-INF/LICENSE.txt'  
  7.         exclude 'META-INF/NOTICE.txt'  
  8.         exclude 'META-INF/NOTICE'  
  9.         exclude 'META-INF/LICENSE'  
  10.         exclude 'META-INF/DEPENDENCIES'  
  11.         exclude 'META-INF/notice.txt'  
  12.         exclude 'META-INF/license.txt'  
  13.         exclude 'META-INF/dependencies.txt'  
  14.         exclude 'META-INF/LGPL2.1'  
  15.     }  
  16. }  

按照stackoverflow上回答的问题原因是:

[python]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. Almost all OS licence include the obligation to "include a copy of the licence" into your project.   
  2. So this means, that you have to include a copy of all OS licences you use into you projects.   
  3. By "excluding" them in gradle, you violate the licences.  
build.gradle(app):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.ezviz.sdk:ezuikit:2.2.1' 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" } 依据上述依赖解决rebuild project后的报错:Duplicate class org.MediaPlayer.PlayM4.Player$PRIVATE_RENDER found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.Player$PTZ_PARAM found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.Player$SESSION_INFO found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.Player$SRTRANS_ELEMENT found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.Player$SRTRANS_PARAM found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.Player$TEM_FLAG found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerAdditionalCB found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerAudioDataCB found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerDecodeCB found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerDecodeCBEx found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerDisplayCB found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerDisplayCBEx found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerEncTypeChgCB found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerEncryptTypeCB found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerFECDisplayCB found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerFileRefCB found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerHSDetectCB found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerIVSDrawFunCB found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerPlayEndCB found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerPreRecordCB found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerPreRecordCBEx found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.PlayerCallBack$PlayerRunTimeInfoCB found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.SurfaceCallBack found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Duplicate class org.MediaPlayer.PlayM4.TimeStruct found in modules jetified-ezviz-sdk-4.9.1.1-runtime (com.ezviz.sdk:ezviz-sdk:4.9.1.1) and jetified-ezviz-sdk-5.20-runtime (io.github.ezviz-open:ezviz-sdk:5.20) Go to the documentation to learn how to Fix dependency resolution errors.
最新发布
06-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值