You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
private Id elementToId(Element element, Class<Page> annotation, int value) {
JCTree tree = (JCTree) trees.getTree(element, getMirror(element, annotation));
if (tree != null) { // tree can be null if the references are compiled types and not source
rScanner.reset();
tree.accept(rScanner);
if (!rScanner.resourceIds.isEmpty()) {
return rScanner.resourceIds.values().iterator().next();
}
}
return new Id(value);
}
然后通过该方法拿到R
Page page = element.getAnnotation(Page.class);
name = StringUtils.isEmpty(page.name()) ? element.getSimpleName().toString() : page.name();
extra = page.extra();
Id id = elementToId(element, Page.class, extra);
@page在app模块中不存在问题,如果在lib中使用,由于生成的R是静态变量,不能直接使用,参考butterknife中的R2复制一份R.
但只能保证在该模块中相同,与app中的并不一定相同,这里我借鉴了butterKnife 中的方法,通过jct来替换R.
然后通过该方法拿到R
最后在创建的时候替换即可:
暂时只找到这一中方法,如有更好的方法,请作者大大分享一下。
The text was updated successfully, but these errors were encountered: