Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format <declare-styleable/> #392

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Format <declare-styleable/> #392

wants to merge 3 commits into from

Conversation

monkeydbobo
Copy link

在 android.disableResourceValidation=true的时候
多个依赖中存在 declare-styleable 中重复声明了同一个attr,
导致使用打出来的aar会提示—Error: Found item Attr/** more than one time,

这个问题本该在assemble aar的时候由duplicate resource暴露,但是因为disableResourceValidation的缘故,会导致最终的aar包里res/values/出现类似以下定义,会在最终打包成apk的时候出现Error: Found item Attr/** more than one time

 <declare-styleable name="DeclareStyleableDefault">
    <attr format="color" name="exampleTextColor"/>
    <attr format="color" name="exampleBackground"/>
  </declare-styleable>
  <declare-styleable name="DeclareStyleableNew">
    <attr format="color" name="exampleTextColor"/>
    <attr format="color" name="exampleTintTitle"/>
  </declare-styleable>

期望的正确写法应该是, 只被声明一次,如下

 <declare-styleable name="DeclareStyleableDefault">
    <attr format="color" name="exampleTextColor"/>
    <attr format="color" name="exampleBackground"/>
  </declare-styleable>
  <declare-styleable name="DeclareStyleableNew">
    <attr name="exampleTextColor" />
    <attr format="color" name="exampleTintTitle"/>
  </declare-styleable>

@monkeydbobo
Copy link
Author

monkeydbobo commented Jul 18, 2022

提供一种extension去解决disableResourceValidation=true的时候出现的该问题

fataar {
    formatDeclareStyleable = true
}

其实在子库定义属性的时候应当加上前缀避免此类问题,但是目前任然有很多库会有重复的属性名称定义

#328
#256
#236
#73

@monkeydbobo monkeydbobo reopened this Aug 22, 2022
@monkeydbobo
Copy link
Author

fix some bug

@monkeydbobo monkeydbobo reopened this Aug 22, 2022
@mikaelzero
Copy link

实测可用

@denghanhao
Copy link

提供一种extension去解决disableResourceValidation=true的时候出现的该问题

fataar {
    formatDeclareStyleable = true
}

其实在子库定义属性的时候应当加上前缀避免此类问题,但是目前任然有很多库会有重复的属性名称定义

#328 #256 #236 #73

Could not set unknown property 'formatDeclareStyleable' for extension 'fataar' of type com.kezong.fataar.FatAarExtension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants