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

getIdentifier(name, type, getPackageName())查找不到资源Id问题 #7

Closed
Walkud opened this issue Feb 16, 2016 · 0 comments
Closed

Comments

@Walkud
Copy link

Walkud commented Feb 16, 2016

场景描述

友盟分享库在宿主中,插件使用友盟分享时 友盟库会调用getIdentifier方法,传入的是宿主的包名,找不到资源Id(代码已经查看是最新)

调试

在PluginResourceWrapper --> getIdentifier断点调试

  1. 在执行 rClass = this.getClass().getClassLoader().loadClass(className);出现异常
  2. catch后执行 packageName = mPluginDescriptor.getPackageName();
  3. 最后执行return super.getIdentifier(entry, type, packageName); 未找到资源Id

目前我的临时解决方案为

将return super.getIdentifier(entry, type, packageName);
替换为return superGetIdentifier(entry, type, packageName);

private int superGetIdentifier(String name, String type, String packageName) {
        int id = super.getIdentifier(name, type, packageName);
        if (id <= 0) {//找不到资源
            //切换包名,继续查找资源
            if (PluginLoader.getApplicatoin().getPackageName().equals(packageName)) {
                packageName = mPluginDescriptor.getPackageName();
            } else {
                packageName = PluginLoader.getApplicatoin().getPackageName();
            }
            id = super.getIdentifier(name, type, packageName);
        }
        return id;
 }

目前这个方案能解决现有的问题,但是不知道是否会引起其他问题。

@limpoxe limpoxe closed this as completed Mar 11, 2016
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

No branches or pull requests

2 participants