The Android main module references the dependent module, but cannot use the dependent library inside
If you encounter problems in modular development
When the multi module androidmanifest.xml is not merged, or the multi module resource file is not merged, or module a includes module B and cannot use the classes in other AAR packages that module B depends on, or you will be prompted that the support package version is inconsistent. This article may be the solution you want~
For example, chestnuts:
For example, we now have an app module designed as: main project: app module: UI, framework
How to introduce a module: specify the correct module path in settings.gradle
include ':app', ':framework', ':ui' project(':framework').projectDir = new File('../framework') project(':ui').projectDir = new File('../ui')
If some dependency libraries are introduced into the framework, the following assumptions are made:
// Retrofit 网络框架依赖 implementation "com.squareup.retrofit2:retrofit:2.5.0" // Gson 依赖 implementation 'com.google.code.gson:gson:2.8.5' // ARouter解耦框架 implementation 'com.alibaba:arouter-api:1.4.1' annotationProcessor 'com.alibaba:arouter-compiler:1.2.2'
If so, the main project app will not be able to call the classes in these dependent libraries. Because the dependency of the implementation declaration can only be used in this module, the API declaration must be used for cross module use (in fact, it was once compile, but if it is set to compile, the as will call you)!! Change to the following
// Retrofit 网络框架依赖 api "com.squareup.retrofit2:retrofit:2.5.0" // Gson 依赖 api 'com.google.code.gson:gson:2.8.5' // ARouter解耦框架 api 'com.alibaba:arouter-api:1.4.1' annotationProcessor 'com.alibaba:arouter-compiler:1.2.2'
Similarly, other AARS are referenced in the module. After this configuration, you need to add the corresponding introduction in the dependency of build.gradle in the app module that depends on the framework.
api project(":framework")
Of course, if you finish all of them, because different support versions are used in many AARS, you will be prompted that the versions are incompatible (the same as other AAR incompatible solutions). Specify in build.gradle of the main project app:
android { ..... ..... //指定jdk版本 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } // 如果提示多个重复文件,加这属性 packagingOptions { exclude 'Meta-INF/proguard/androidx-annotations.pro' } } // 用于指定所有aar引用同样版本的support包 configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> def requested = details.requested if (requested.group == 'com.android.support') { if (!requested.name.startsWith("multidex")) { details.useVersion '28.0.0' } } } }
————————————————Copyright notice: This is the original article of CSDN blogger "fat tiger", which follows the CC 4.0 by-sa copyright agreement. Please attach the original source link and this notice for reprint. Original link: https://blog.csdn.net/ljphhj/article/details/86262031