有趣生活

当前位置:首页>科技>androidstudio新建项目不行Studio项目打包配置属性文件报错及解决方案

androidstudio新建项目不行Studio项目打包配置属性文件报错及解决方案

发布时间:2026-07-25阅读(1)

导读一、在AndroidStudio中打包时报错如下:(1)打包时报多个属性文件错误FAILURE:buildfailedwithanexception.*Wh....一、在Android Studio中打包时报错如下:

(1)

打包时报多个属性文件错误

FAILURE: build failed with an exception.

* What went wrong:

Execution failed for task :app:transformResourcesWithMergeJavaResForRelease.

> More than one file was found with OS independent path META-INF/rxjava.properties

大意是多个与操作系统无关的路径“META-INF/rxjava.properties”。rxjava.properties是rxjava依赖库的属性配置文件。

注意:这个问题是有时候引用的三方库会带有一些配置文件xxxx.properties,或者license信息导致的。

(2)解决方案:

在主项目的build.gradle文件中加入packagingOptions 配置:

packagingOptions {

exclude META-INF/rxjava.properties

}

packagingOptions 是打包时的一些配置,使用exclude 在打包时移除项目中的相关文件,不打入apk文件中。

针对引用的三方库会带有一些配置文件xxxx.properties,或者license信息,当我们打包的时候想去掉这些信息就可以使用上面的packagingOptions 配置方式。

packagingOptions 配置

(3)通用解决方案:

全部packagingOptions 配置

下面粘贴我项目中使用的全部packagingOptions 配置

packagingOptions {

exclude META-INF/ASL2.0

exclude META-INF/DEPENDENCIES.txt

exclude META-INF/LICENSE.txt

exclude META-INF/NOTICE.txt

exclude META-INF/NOTICE

exclude META-INF/LICENSE

exclude META-INF/DEPENDENCIES

exclude META-INF/notice.txt

exclude META-INF/license.txt

exclude META-INF/dependencies.txt

exclude META-INF/LGPL2.1

exclude META-INF/services/javax.annotation.processing.Processor

exclude META-INF/rxjava.properties

}

TAGS标签:  androidstudio  新建  项目  不行  studio  androidstu

Copyright © 2024 有趣生活 All Rights Reserve吉ICP备19000289号-5 TXT地图HTML地图XML地图