EastWoodYang / MicroModule

Rebuild multiple complete module structures within the module.
Other
219 stars 50 forks source link

在 gradle 7.0.2 运行不起来 #17

Open WTree opened 2 years ago

WTree commented 2 years ago

java.lang.NullPointerException at com.android.ide.common.resources.NodeUtils.processSingleNodeNamespace(NodeUtils.java:186) at com.android.ide.common.resources.NodeUtils.updateNamespace(NodeUtils.java:147) ....

achenglike commented 2 years ago

研究了2天吧,最终解决方法就是在 root工程的gradle.properties添加:

systemProp.javax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl

原因:

我觉得是 gradle 或者 agp 的bug,DocumentBuilderFactory#newInstance() 在找底层实现的时候,出现了同一个方法返回了两种实现一个是 com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl 另一个是 org.apache.xerces.jaxp.DocumentBuilderFactoryImpl 然后调用到 NodeUtils#adoptNode(Document document, Node node) 时 document和node来自不同的实现,adoptNode 就直接返回了NULL,后面就空指针了。

解决:

DocumentBuilderFactory#newInstance() 再向下走创建实例的过程中有一步是查看是否设置了SystemProperty

try {
            factoryClassName = SecuritySupport.getSystemProperty(factoryId);
            if (factoryClassName != null) {
                dPrint(() -> {
                    return "found system property, value=" + factoryClassName;
                });
                return newInstance(type, factoryClassName, (ClassLoader)null, true);
            }
        } catch (SecurityException var9) {
            if (debug) {
                var9.printStackTrace();
            }
        }

直接通过gradle.properties定义下这个property,这样获取的实现就一致了

求助:

DocumentBuilderFactory#newInstance() 后面的实例化 DocumentBuilderFactory 的过程中有使用ServiceLoader,

private static <T> T findServiceProvider(final Class<T> type) {
        try {
            return AccessController.doPrivileged(new PrivilegedAction<T>() {
                public T run() {
                    ServiceLoader<T> serviceLoader = ServiceLoader.load(type);
                    Iterator<T> iterator = serviceLoader.iterator();
                    return iterator.hasNext() ? iterator.next() : null;
                }
            });
        } catch (ServiceConfigurationError var4) {
            RuntimeException x = new RuntimeException("Provider for " + type + " cannot be created", var4);
            FactoryConfigurationError error = new FactoryConfigurationError(x, x.getMessage());
            throw error;
        }
    }

就是这个地方,出现了本插件使用流程中实例化查不到实现,其它情况能查到,哪位知道原因的话,烦请回复下。

zhangjibiao commented 11 months ago

我是遇到了这个错误后,从搜索引擎找到这里的,我的情况是资源文件也就是res目录下的文件存在错误。

我是这样子排查的,新建空的AS项目,编译通过后,git init并提交,通过版本控制工具来整理 然后先将res/values/string.xml拷贝过来,编译测试 再拷贝/values/...等其他文件,一个一个(或者一整个目录)编译进行测试,编译成功便说明没有问题,git add . 记录一下

最终找出了很多错误,解决错误后再拷贝回来原项目 ![Uploading 2020-07-26_221719 - 副本.png…]()