美文网首页
AS 3.0+主app moudle引用其他module无法导

AS 3.0+主app moudle引用其他module无法导

作者: 岁月静好浅笑安然 | 来源:发表于2019-08-23 19:18 被阅读0次

主app module的build.gradle 示例

项目结构实例

微信截图_20190823185233.png

AS 3.0 以下,主module和其他被引用的module都使用complie关键字依赖如

dependencies {
    complie fileTree(include: ['*.jar'], dir: 'libs')
    androidTestComplie('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testComplie'junit:junit:4.12'
    complie 'com.android.support:appcompat-v7:25.3.0'
    complie project(':IMKit')
    complie project(':IMLib')
    complie project(':govSDK_lib')
}

被引用IMKit module的build.gradle 示例

dependencies {
    complie fileTree(dir: 'src/main/libs', include: ['*.jar'])
    complie 'com.android.support:support-v4:23.0.1'
    complie project (':IMLib')
}

此时假如我们,as升级3.0+以后,一般按照如下思路更改

  • 1.修改 build.gradle/project,改高版本
 dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
    }
    1. 修改gradl/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
  • 3.修改对应build.gradle,将complie 改为implementation,修改示例(引用的module示例省略)
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testComplie'junit:junit:4.12'
    implementation 'com.android.support:appcompat-v7:25.3.0'
    implementation project(':IMKit')
    implementation project(':IMLib')
    implementation project(':govSDK_lib')

如果你项目没有引用,其他的module恭喜你,修改结束!但是有引用你应该会发现,完全无法导包。此时你需要将被引用的moudle中implementation改为api

代码示例

dependencies {
    api fileTree(dir: 'src/main/libs', include: ['*.jar'])
    api 'com.android.support:support-v4:23.0.1'
    api project (':IMLib')
}

这样一般说来,就没什么问题了。假如还有问题的话一般做法,去除所有引用,再重新引用一遍。或许还有依赖冲突的问题请参考我的另外一篇博文。

相关文章

网友评论

      本文标题:AS 3.0+主app moudle引用其他module无法导

      本文链接:https://www.haomeiwen.com/subject/oetxectx.html