与twitter4j的android Proguard混淆

时间:2014-12-22 10:24:27

标签: android proguard obfuscation twitter4j

我正在尝试将proguard与twitter4j一起使用,并在调用new TwitterFactory(configuration)时不断收到noMethodFound异常。这是例外:

java.lang.AssertionError: java.lang.NoSuchMethodException: <init> [interface twitter4j.conf.Configuration, interface twitter4j.auth.Authorization]
        at twitter4j.TwitterFactory.<clinit>(TwitterFactory.java:73)
        at com.applicaster.util.twitter.TwitterAuthenticationUtil.getServiceInstance(Unknown Source)
        at com.applicaster.util.twitter.TwitterAuthenticationUtil.logIn(Unknown Source)
        at feed.x.b(Unknown Source)
        at feed.A.onClick(Unknown Source)
        at android.view.View.performClick(View.java:4442)
        at android.view.View$PerformClick.run(View.java:18473)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5105)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.NoSuchMethodException: <init> [interface twitter4j.conf.Configuration, interface twitter4j.auth.Authorization]
        at java.lang.Class.getConstructorOrMethod(Class.java:472)
        at java.lang.Class.getDeclaredConstructor(Class.java:562)
        at twitter4j.TwitterFactory.<clinit>(TwitterFactory.java:71)
            at com.applicaster.util.twitter.TwitterAuthenticationUtil.getServiceInstance(Unknown Source)
            at com.applicaster.util.twitter.TwitterAuthenticationUtil.logIn(Unknown Source)
            at feed.x.b(Unknown Source)
            at feed.A.onClick(Unknown Source)
            at android.view.View.performClick(View.java:4442)
            at android.view.View$PerformClick.run(View.java:18473)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5105)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
            at dalvik.system.NativeStart.main(Native Method)

在我的proguard配置中(与twitter相关)是:

    -dontoptimize
    -dontpreverify
    -dontobfuscate

    -optimizations !code/simplification/arithmetic
    -allowaccessmodification
    -repackageclasses ''
    -keepattributes *Annotation*
    -keepattributes InnerClasses
    -keepattributes Signature
    -keepattributes Exceptions
    -keepattributes JavascriptInterface
    -dontnote
    -dontwarn twitter4j.**
    -keep class twitter4j.**
    -keep public class twitter4j.TwitterFactory
    -keep interface twitter4j.**

问题是,TwitterFactory没有使用Configuration和Authorization对象作为参数的构造函数。我不知道为什么要找这样的方法......

请帮忙吗?

1 个答案:

答案 0 :(得分:12)

我对Twitter 4j的proguard配置如下: -

-dontwarn twitter4j.**
-keep  class twitter4j.conf.PropertyConfigurationFactory
-keep class twitter4j.** { *; }

我也使用compile 'org.twitter4j:twitter4j-core:4.0.2'

让我知道它是否适合你。