コード例 #1
0
  @SuppressWarnings("rawtypes")
  public static Class loadPluginClassByName(String clazzName) {

    PluginDescriptor pluginDescriptor = getPluginDescriptorByClassName(clazzName);

    if (pluginDescriptor != null) {

      ensurePluginInited(pluginDescriptor);

      DexClassLoader pluginClassLoader = pluginDescriptor.getPluginClassLoader();

      try {
        Class pluginClazz = ((ClassLoader) pluginClassLoader).loadClass(clazzName);
        LogUtil.d("loadPluginClass Success for clazzName ", clazzName);
        return pluginClazz;
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (java.lang.IllegalAccessError illegalAccessError) {
        illegalAccessError.printStackTrace();
        throw new IllegalAccessError(
            "出现这个异常最大的可能是插件dex和" + "宿主dex包含了相同的class导致冲突, " + "请检查插件的编译脚本,确保排除了所有公共依赖库的jar");
      }
    }

    LogUtil.e("loadPluginClass Fail for clazzName ", clazzName);

    return null;
  }
コード例 #2
0
  @SuppressWarnings("rawtypes")
  public static Class loadPluginClassByName(String clazzName) {

    PluginDescriptor pluginDescriptor = getPluginDescriptorByClassName(clazzName);

    if (pluginDescriptor != null) {

      ensurePluginInited(pluginDescriptor);

      DexClassLoader pluginClassLoader = pluginDescriptor.getPluginClassLoader();

      try {
        Class pluginClazz = ((ClassLoader) pluginClassLoader).loadClass(clazzName);
        LogUtil.d("loadPluginClass Success for clazzName ", clazzName);
        return pluginClazz;
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (java.lang.IllegalAccessError illegalAccessError) {
        illegalAccessError.printStackTrace();
      }
    }

    LogUtil.e("loadPluginClass Fail for clazzName ", clazzName);

    return null;
  }