kezong / fat-aar-android

A gradle plugin that merge dependencies into the final aar file works with AGP 3.+

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add support for AS code intelligent 增加主 lib 和 sub lib 之间的代码联系

wkmcyz opened this issue · comments

As now we can not link code in main lib and sub libs while in development , AS can not do this because implementation is replaced by embed (Gradle plugin : 3.4.2 , Gradle : 5.5.1). This is very inconvenient because you need to switch between implementation and embed when in development or when publishing. Maybe we can find some ways to do with this and make it more convenenient 💯 .

希望增加一个方法来避免开发期间 main lib 和 sub lib 无法被 IDE 自动关联的问题(因为没有用 implementation , Gradle plugin : 3.4.2 , Gradle : 5.5.1) , 这就很苦恼了啊,必须在开发期间手动修改 embed 为 implementation , 然后等到要发布的时候在修改这些为 embed , 我寻思能不能找个办法来给它整整。

这个应该是可以天然支持的,插件内部为了解决这个问题,为每一个embed的模块都添加了compileOnly关联。
你可以看看是不是自己的配置有什么问题,或者清空一下.idea/中的内容试试。

@kezong
我说的不是这个意思, 我指的是 main lib 关联到 sub lib 的源码( .java, .kt 的文件), 编译成功以后跳转到的是打好的 sub lib 的 classes.jar 文件中的代码。

不过我发现有一个解决方法 :在 main lib 中用 flavor 进行区分, e.g.


android {
    flavorDimensions("type")
    productFlavors {
        dev {
            dimension "type"
        }
        pub {
            dimension "type"
        }
    }
}

dependencies {
    pubEmbed project(path: ':main-lib:sub-lib', configuration: 'default')
    devImplementation project(':main-lib:sub-lib')
}

缺点是需要在源码依赖 main lib 的地方,设置 app 的 missingDimensionStrategy
see https://developer.android.google.cn/studio/build/dependencies#variant_aware

@kezong kezong 你觉得这个方法如何, 有别的好的方法吗? 或者说你指的那个自动关联已经可以完成我想要的这种关联到源码的功能的话,请告诉我一下,那就不需要这么麻烦的操作了。

@wkmcyz 我这边的工程main-lib引用了sub-lib,是可以直接关联到源码的,并不是关联到.class文件。

你可以试一下example,看是否能够关联。

@wkmcyz 我这边的工程main-lib引用了sub-lib,是可以直接关联到源码的,并不是关联到.class文件。

你可以试一下example,看是否能够关联。

No, 我试了,但是并不行。mainlib 引用 aar2 的类使用 embed 是不能被 IDE 解析的,改成 implementation 后可以。
不过现在项目代码 example 里 mainlib 没有实际引用 aar2 的类,需要修改 MainLibClass 的内容 :

package com.kezong.demo.lib;

import com.kezong.demo.libaar2.Aar2LibClass;
/**
 * @author kezong on 2018/12/25.
 */
public class MainLibClass {

    public static final String TAG = Aar2LibClass.TAG;
}

我的 AS 版本 :
Android Studio 4.0
Build #AI-193.6911.18.40.6514223, built on May 20, 2020
Runtime version: 1.8.0_242-release-1644-b3-6222593 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.5
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 12
Registry: ide.new.welcome.screen.force=true, debugger.watches.in.variables=false
Non-Bundled Plugins: ASM Bytecode Viewer, BashSupport, CheckStyle-IDEA, Code Iris, IdeaVIM, IdeaVimExtension, PlantUML integration, PythonCore, com.kaygisiz.dependencygraph, mobi.hsz.idea.gitignore, org.intellij.plugins.markdown, org.pmesmeur.sketchit

@wkmcyz
Android Studio 4.0上兼容有问题,我在1.2.15版本中修改了一下,你可以升级一下。

可以是可以了, 但是我测试 1.2.13 也可以, 不过还没细看具体哪个 commit 修复的。 反正不是你修改的那个 commit ( 除非你 1.2.13 也发成了 1.2.15 的代码了)
我关了啊