一 概要
项目拉取运行、aar打包提供给使用方时,可能出现各种问题。譬如:接受方集成后发现编译报错。一般情况下主要有:
1.构建、kotlin语言、插件版本不一致;
2.相应的依赖版本不一致;
3. so库的ndk不一致或者不全;(搞清楚接收方的ndk abiFilters的范围)
解决思路也是:接受方使用一致的版本(或者引用公共gradle文件依赖,或者手动改为一致),或者exclude掉冲突组件,而这需要仔细看build的警告、错误日志以及有去排除可能错误的手段。
二 案例
1.More than one file was found with OS independent path ‘META-INF/okio.kotlin_module’
这个错误发生在升级了本地组件依赖(okhttp相关)-进行打包aar时。很明显是由于本地依赖升级发生导致。
1.本地组件依赖既然是需要升级,那么回退到正常运行的版本就没有意义,只能从其他方面着手。
2.其他手段
-
清除缓存clean/rebuild/clear validate cache***——无效
-
找到该重复文件,并进行删除——无效
这里说一下定位手段:
a.double shift按键搜索该文件,点击打开
b.ctrl+鼠标左键点击文件标签即可看到该文件的树级目录(mac 是command+鼠标左键点击)。或者切换Project工程目录,点击定位即可展开目录树。
c.可以从父级文件目录删除开始
删除无效的原因在于,这是build时产生的,删除后仍旧会重生。 -
更改gradle版本——有效
-
build.gradle(project)中 提升
class path 'com.android.tools.build:gradle:3.2.1'
的版本,譬如提升到3.6.0
之类。 -
gradle-wrapper-.properties 提升distributionUrl 的gradle版本。
2. DSL element ‘android.dataBinding.enabled’ is obsolete and has been replaced with ‘android.buildFeatures.dataBinding’. It will be removed in version 7.0 of the Android Gradle plugin.
dataBinding {
enabled true
}
//所有library含project对应的build.gradle文件中,上述的语句替换如下(因为gradle插件版本不匹配了)
buildFeatures {
dataBinding true
}
3. java.lang.Error: Something went wrong while checking for version compatibility between the Compose Compiler and the Kotlin Compiler. It is possible that the versions are incompatible. Please verify your kotlin version and consult the Compose-Kotlin compatibility map located at https://developer.android.com/jetpack/androidx/releases/compose-kotlin
发生情况
引入第三方项目构建时出现kotlin与compose所使用的版本不一致。
问题①解决
1.查看compose 所使用的kotlin版本的对应关系
https://developer.android.com/jetpack/androidx/releases/compose-kotlin?hl=zh-cn
2.更改为兼容版本
android {
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.10"//这里的版本号更改为兼容版本
}
kotlinOptions {
jvmTarget = "19"
}
}
kotlin版本的位置:
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.20'
4.androidx.compose.compiler.plugins.kotlin.IncompatibleComposeRuntimeVersionException: The Compose Compiler requires the Compose Runtime to be on the class path, but none could be found. The compose compiler plugin you are using (version 1.4.3) expects a minimum runtime version of 1.0.0.
问题解决
缺少依赖,加上
https://developer.android.com/jetpack/androidx/releases/compose-runtime?hl=zh-cn
"androidx.compose.runtime:runtime:1.6.3"
denpendencies中加入以上依赖版本。
5. Incorrect package=“com.qmuiteam.qmui” found in source AndroidManifest.xml: D:\Android\AndroidStudioProjects\BasePro\qmui\src\main\AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
Recommendation: remove package=“com.qmuiteam.qmui” from the source AndroidManifest.xml: D:\Android\AndroidStudioProjects\BasePro\qmui\src\main\AndroidManifest.xml.
新加入库,不支持库中直接指定package节点,建议删除。(升级了gradle插件版本之后)
但是这会导致所有的源文件引入路径错误。
** 问题解决**
android {
compileSdk = 33
namespace = "com.qmuiteam.qmui"
//...
gradle中进行设置即可。
6.Dependency ‘androidx.activity:activity:1.8.0’ requires libraries and applications that depend on it to compile against version 34 or later of the Android APIs.
:app is currently compiled against android-33.
Recommended action: Update this project to use a newer compileSdk
of at least 34, for example 34.
Note that updating a library or application's compileSdk (which
allows newer APIs to be used) can be done separately from updating
targetSdk (which opts the app in to new runtime behavior) and
minSdk (which determines which devices the app can be installed
on).
在项目新建library build出现上述错误。
也就是要将 compilesdk版本更新至上述指定版本34。 可以更,也可以选择找到androidx.activity:activity:1.8.0
降低版本。
原因应该是,新建的library的依赖版本过高:
implementation("com.google.android.material:material:1.11.0")
改为
implementation("com.google.android.material:material:1.9.0")