HujiangTechnology / gradle_plugin_android_aspectjx

A Android gradle plugin that effects AspectJ on Android project and can hook methods in Kotlin, aar and jar file.
Apache License 2.0
3.93k stars 568 forks source link

Hilt兼容问题 #288

Open lk666 opened 4 years ago

lk666 commented 4 years ago

aspectjx版本2.0.10,目前发现主要有两个兼容问题: 1、同kotlin 1.4.10 zip file is empty; 2、Hilt版本2.28-alpha,使用aspectjx插件后,生成的Hilt_Application类不会被替换成项目的application的基类

/**
 *  怀疑是不是aspectJ影响了下面这段执行的问题
 * A generated base class to be extended by the @dagger.hilt.android.HiltAndroidApp annotated class. If using the Gradle plugin, this is swapped as the base class via bytecode transformation.
 */
@Generated("dagger.hilt.android.processor.internal.androidentrypoint.ApplicationGenerator")
public abstract class Hilt_AppContext extends MultiDexApplication implements GeneratedComponentManager<Object> {
  private final ApplicationComponentManager componentManager = new ApplicationComponentManager(new ComponentSupplier() {
    @Override
    public Object get() {
      return DaggerAppContext_HiltComponents_ApplicationC.builder()
          .applicationContextModule(new ApplicationContextModule(Hilt_AppContext.this))
          .build();
    }
  });

  protected final ApplicationComponentManager componentManager() {
    return componentManager;
  }

  @Override
  public final Object generatedComponent() {
    return componentManager().generatedComponent();
  }

  @CallSuper
  @Override
  public void onCreate() {
    // This is a known unsafe cast, but is safe in the only correct use case:
    // AppContext extends Hilt_AppContext
    // 使用aspectjX后不会执行到这里
    ((AppContext_GeneratedInjector) generatedComponent()).injectAppContext(UnsafeCasts.<AppContext>unsafeCast(this));
    super.onCreate();
  }
}
lanjd commented 3 years ago

aspectjx版本2.0.10,目前发现主要有两个兼容问题: 1、同kotlin 1.4.10 zip file is empty; 2、Hilt版本2.28-alpha,使用aspectjx插件后,生成的Hilt_Application类不会被替换成项目的application的基类

/**
 *  怀疑是不是aspectJ影响了下面这段执行的问题
 * A generated base class to be extended by the @dagger.hilt.android.HiltAndroidApp annotated class. If using the Gradle plugin, this is swapped as the base class via bytecode transformation.
 */
@Generated("dagger.hilt.android.processor.internal.androidentrypoint.ApplicationGenerator")
public abstract class Hilt_AppContext extends MultiDexApplication implements GeneratedComponentManager<Object> {
  private final ApplicationComponentManager componentManager = new ApplicationComponentManager(new ComponentSupplier() {
    @Override
    public Object get() {
      return DaggerAppContext_HiltComponents_ApplicationC.builder()
          .applicationContextModule(new ApplicationContextModule(Hilt_AppContext.this))
          .build();
    }
  });

  protected final ApplicationComponentManager componentManager() {
    return componentManager;
  }

  @Override
  public final Object generatedComponent() {
    return componentManager().generatedComponent();
  }

  @CallSuper
  @Override
  public void onCreate() {
    // This is a known unsafe cast, but is safe in the only correct use case:
    // AppContext extends Hilt_AppContext
    // 使用aspectjX后不会执行到这里
    ((AppContext_GeneratedInjector) generatedComponent()).injectAppContext(UnsafeCasts.<AppContext>unsafeCast(this));
    super.onCreate();
  }
}

2、Hilt版本2.28-alpha,使用aspectjx插件后,生成的Hilt_Application类不会被替换成项目的application的基类 这个问题选择有什么解决办法么?

yan-lixin commented 3 years ago

aspectjx版本2.0.10,目前发现主要有两个兼容问题: 1、同kotlin 1.4.10 zip file is empty; 2、Hilt版本2.28-alpha,使用aspectjx插件后,生成的Hilt_Application类不会被替换成项目的application的基类

/**
 *  怀疑是不是aspectJ影响了下面这段执行的问题
 * A generated base class to be extended by the @dagger.hilt.android.HiltAndroidApp annotated class. If using the Gradle plugin, this is swapped as the base class via bytecode transformation.
 */
@Generated("dagger.hilt.android.processor.internal.androidentrypoint.ApplicationGenerator")
public abstract class Hilt_AppContext extends MultiDexApplication implements GeneratedComponentManager<Object> {
  private final ApplicationComponentManager componentManager = new ApplicationComponentManager(new ComponentSupplier() {
    @Override
    public Object get() {
      return DaggerAppContext_HiltComponents_ApplicationC.builder()
          .applicationContextModule(new ApplicationContextModule(Hilt_AppContext.this))
          .build();
    }
  });

  protected final ApplicationComponentManager componentManager() {
    return componentManager;
  }

  @Override
  public final Object generatedComponent() {
    return componentManager().generatedComponent();
  }

  @CallSuper
  @Override
  public void onCreate() {
    // This is a known unsafe cast, but is safe in the only correct use case:
    // AppContext extends Hilt_AppContext
    // 使用aspectjX后不会执行到这里
    ((AppContext_GeneratedInjector) generatedComponent()).injectAppContext(UnsafeCasts.<AppContext>unsafeCast(this));
    super.onCreate();
  }
}

Hilt那个问题解决了不

jiayuan880123 commented 3 years ago

现在有办法解决么?

jiqianwen commented 3 years ago

'dagger.hilt.android.plugin' 插件引用放在 'android-aspectjx'之前试试