匕首+ Proguard的混淆,错误创建对象图 [英] Dagger + Proguard obfuscation, Errors creating object graph

查看:305
本文介绍了匕首+ Proguard的混淆,错误创建对象图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行我的应用程序的模糊版本引发以下堆栈跟踪

Running an obfuscated version of my application throws the following stacktrace

java.lang.RuntimeException: Unable to create service com.mycompany.myapp.async.alarms.AlarmIntentService: java.lang.IllegalStateException: Errors creating object graph:
    dagger.Lazy could not be bound with key dagger.Lazy required by dagger.Lazy  com.mycompany.scheduler.c.mNotificationDisplayer

如果我加-dontobfuscate,它运行顺利

If I add -dontobfuscate, it runs smoothly

下面是包含字段类

public abstract class AbstractAlarmSchedulerService extends IntentService {

  @Inject
  Lazy<AbstractAlarmSchedulerNotificationDisplayer> mNotificationDisplayer;

我从这个类在我的应用程序扩展,但它属于外部库。

I extend from this class in my application, but it belongs to an external library.

这些都是我的匕首ProGuard的规则,从 http://stackoverflow.com/a/18177491/218473 <复制/ P>

These are my dagger proguard rules, copied from http://stackoverflow.com/a/18177491/218473

#Dagger
-keepattributes *Annotation*

-keepclassmembers,allowobfuscation class * {
    @javax.inject.* *;
    @dagger.* *;
    <init>();
}

-keep class * extends dagger.internal.Binding
-keep class * extends dagger.internal.ModuleAdapter

-keep class **$$ModuleAdapter
-keep class **$$InjectAdapter
-keep class **$$StaticInjection

-keep class dagger.* { *; }

-keep class javax.inject.* { *; }
-keep class * extends dagger.internal.Binding
-keep class * extends dagger.internal.ModuleAdapter
-keep class * extends dagger.internal.StaticInjection

-keep !abstract class com.mycompany.** { *; }

-keepnames class dagger.Lazy

我试图保持所有类别和所有成员如果固定的东西看,但错误依然存在。

I've tried keeping all classes and all members to see if that fixed anything, but the error persisted

-keep class * { *; }

com.mycompany.scheduler是一个外部库,而com.mycompany.myapp包含源的实际应用。

com.mycompany.scheduler is an external library, while com.mycompany.myapp contains the source for the actual application.

在情况下,它需要的,这里是我使用的模块

In case it's needed, here's the Module I'm using

@Module(injects = {AlarmIntentService.class, ReminderNotificationDisplayer.class, AlarmsBroadcastReceiver.class})
public class AndroidModule {
  private final AbstractMyApplication application;

  public AndroidModule(AbstractMyApplication application) {
    this.application = application;
  }

  /**
   * Allow the application context to be injected
   */
  @Provides @Singleton
  Context provideApplicationContext() {
    return application;
  }

  @Provides
  public AlarmManager provideAlarmManager(Context context){
    return (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
  }

  @Provides
  @Singleton
  public NotificationManager provideNotificationManager(Context context){
    return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  }

  @Provides
  @Singleton
  public AbstractAlarmSchedulerNotificationDisplayer provideNotificationDisplayer() {
    return new ReminderNotificationDisplayer();
  }
}

我用匕首和放大器;匕首编译器1.2 +依赖

I'm using dagger & dagger-compiler 1.2.+ dependencies

谢谢!

推荐答案

匕首1.x中具有混淆的问题。它可以做code缩水适当-keep语句,但模糊变,因为使用字符串键的问题。以proguarding前的字符串中产生,但proguarding后食用,不要用新重命名的类型排队。

Dagger 1.x has issues with obfuscation. It can do code-shrinking with appropriate -keep statements, but obfuscation becomes problematic because of the use of String keys. The Strings are generated prior to proguarding, but consumed after proguarding, and do not line up with the newly-renamed types.

匕首1.x的(大约1.0.0)之前,我们禁用反射模块适配器将工作,作为纯粹的反射导致双方提供和注射型被认为是及时(即proguarding后),因此模糊处理类型匹配。如果code-混淆是一个更高的优先级比性能,请考虑使用此稍旧版本。

Dagger 1.x (around 1.0.0) before we disabled reflective module adapters will work, as pure-reflection results in both provision and injection of a type to be considered "just in time" (i.e. after proguarding) so obfuscated types match up. If code-obfuscation is a higher priority than performance, do consider using this slightly older version.

匕首2.X(进行中)是免费的字符串键,并且直接类引用的结果,而且应该发挥非常漂亮的Proguard的。敬请关注匕首名单和项目。我们预计2.X的早期版本周本贴内下降。

Dagger 2.x (in progress) is free of string keys, and results in direct class references, and should play very nicely with Proguard. Stay tuned to the dagger lists and project. We expect early versions of 2.x to drop within weeks of this posting.

此外,更具体,确保您 -keepattributes签名。您所看到特定的错误是因为JDK5 +仿制药正在被ProGuard的剥离。一个从来没有注入延迟,一是其注入延迟&LT;富&GT; 。这将解决这个特定的错误,虽然你会再有问题上面提到的。

Also, and more specifically, make sure you -keepattributes Signature. The specific error you are seeing is because JDK5+ generics are being stripped by proguard. One never injects Lazy, one injects Lazy<Foo>. That will fix this specific error, though you will then have the problem mentioned above.

这篇关于匕首+ Proguard的混淆,错误创建对象图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆