kanyun-inc / Kace

Kace: Kotlin Android Compatible Extensions, a framework for assisting in the seamless migration from kotlin-android-extensions
Apache License 2.0
261 stars 11 forks source link

DexArchiveMergerException throws when there are multiple layout files with the same name. #32

Closed zhangzhenxi closed 1 year ago

zhangzhenxi commented 1 year ago

Background

ProjectXXX has an Application module :app, and a library module :library :library2

:app depends on :library :library depends on :library2

image

There is a activity_base_list.xml layout file in each module(including app)

Env

buildscript {
  repositories {
    google()
    mavenCentral()
  }
  dependencies {
    classpath 'com.kanyun.kace:kace-gradle-plugin:1.8.0-1.0.4'
  }
}

plugins {
  id 'com.android.application' version '7.4.1' apply false
  id 'com.android.library' version '7.4.1' apply false
  id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}

Issue

Build error because of dex merge failed Multiple layout files with the same name will generate multiple class(with same name) in one package: kotlinx.android.synthetic.main

Excpect

Should compile without any error like kotlin-extensions plugin.

zhangzhenxi commented 1 year ago

This issue is only happens when: :app -> :lib1 -> :lib2 And all those modules all has a layout file with same name.

If there is no module :lib2(transive dependency layer less then three), then this issue won't happen.

RicardoJiang commented 1 year ago

Why do you have layouts with the same name in different modules? Only one will take effect in the end, right? Why not just keep one?

zhangzhenxi commented 1 year ago

These libraries are basic components such as ListPage VideoPlayer and so on, I can use these components in app with a customized ui layout when necessary.

RicardoJiang commented 1 year ago

Since the kace plugin is compatible with the kotlin-extensions plugin by generating source code, it cannot support duplicate classes. Maybe you can try to use blackList, so that the app module or lib1 module does not generate code

zhangzhenxi commented 1 year ago

Maybe I'll try some kotlinx.android.synthetic.main.${layout}.view to ${package}.main.${layout}.view thing

zhangzhenxi commented 1 year ago

Here is an example:

image image