appium / appium-espresso-driver

Espresso integration for Appium
Apache License 2.0
191 stars 75 forks source link

Error while starting instrumentation with Obfuscated apk (with proguard) #232

Open rajdeepv opened 6 years ago

rajdeepv commented 6 years ago

Details Espresso server has gson as dependancy. In many cases gson is a dependancy of the app under test as well. When the app is obfuscated, Its complains NoSuchMethodError for obfuscated methods as below:

09-25 13:45:02.818  9721  9721 E MonitoringInstr: java.lang.NoSuchMethodError: No static method d(Ljava/lang/reflect/Type;)Ljava/lang/reflect/Type; in class Lcom/google/gson/internal/$Gson$Types; or its super classes (declaration of 'com.google.gson.internal.$Gson$Types' appears in /data/app/io.appium.espressoserver.test-1/base.apk)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at com.google.gson.b.a.<init>(TypeToken.java:72)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at com.google.gson.b.a.b(TypeToken.java:303)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at com.google.gson.e.<clinit>(Gson.java:112)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at com.google.gson.f.b(GsonBuilder.java:572)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at com.badoo.mobile.eventbus.a.c.<clinit>(EventLoggerImpl.java:29)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at com.badoo.mobile.eventbus.a.b.a(EventLoggerFactory.java:12)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at com.bumble.app.application.BumbleApplicationLogic.onPreCreate(BumbleApplicationLogic.java:73)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at com.bumble.app.application.BumbleDebugApplicationLogic.onPreCreate(BumbleDebugApplicationLogic.java:53)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at com.badoo.mobile.b.c.onCreate(BadooBaseApplication.java:85)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at com.supernova.app.application.d.onCreate(NextGenApplication.kt:25)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at com.bumble.app.application.BumbleDebugApplication.onCreate(BumbleDebugApplication.kt:23)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1032)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at android.support.test.runner.MonitoringInstrumentation.callApplicationOnCreate(MonitoringInstrumentation.java:382)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5876)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at android.app.ActivityThread.-wrap3(ActivityThread.java)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1699)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at android.os.Handler.dispatchMessage(Handler.java:102)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at android.os.Looper.loop(Looper.java:154)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at android.app.ActivityThread.main(ActivityThread.java:6682)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at java.lang.reflect.Method.invoke(Native Method)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
09-25 13:45:02.818  9721  9721 E MonitoringInstr:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
dpgraham commented 6 years ago

So the app gets obfuscated but espresso-server doesn't, and that still happens?

rajdeepv commented 6 years ago

Yes, App under test is obfuscated but Espresso server is not. If I build unobfuscated app, I do not get above error.

dpgraham commented 5 years ago

I'm going to look at this.... @mykola-mokhnach do you have any ideas, off the top of your head, why this would be happening?

rajdeepv commented 5 years ago

@dpgraham I have found a way to avoid this. In the application code, we need to make sure that we don't obfuscate com.google.gson

Thanks!

dpgraham commented 5 years ago

Okay good to know @rajdeepv! We'll still keep it open though. For other users who have this same problem we'll need to either come up with a solution or list it as a "Known Issue" and provide a recommended workaround.

KazuCocoa commented 5 years ago

Maybe, this is also a similar issue. I would leave the log here.

05-08 10:01:18.336 E/AndroidRuntime(24598): java.lang.NoSuchMethodError: No direct method <init>(Lkotlin/reflect/d;Ljava/lang/String;Ljava/lang/String;)V in class Lkotlin/jvm/internal/PropertyReference1Impl; or its super classes (declaration of 'kotlin.jvm.internal.PropertyReference1Impl' appears in /data/app/io.appium.espressoserver.test-JDAO30jOyu-UyGfxC1cicw==/base.apk)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at com.aspiro.wamp.debugoptions.a.<clinit>(Unknown Source:15)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at com.aspiro.wamp.eventtracking.a.b.a(EventsNetworkModule_ProvideHttpLoggingInterceptorFactory.java:1047)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at dagger.internal.b.a(DoubleCheck.java:47)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at com.aspiro.wamp.eventtracking.a.d.a(EventsNetworkModule_ProvideOkHttpClientFactory.java:1056)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at dagger.internal.b.a(DoubleCheck.java:47)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at com.aspiro.wamp.eventtracking.a.h.a(EventsTrackingModule_ProvidesEventsFactory.java:1029)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at dagger.internal.b.a(DoubleCheck.java:47)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at com.aspiro.wamp.eventtracking.a.g.a(EventsTrackingModule_ProvideEventServiceFactory.java:1024)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at dagger.internal.b.a(DoubleCheck.java:47)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at com.aspiro.wamp.h.g$c.a(DaggerApplicationComponent.java:1155)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at com.aspiro.wamp.App.f(App.java:181)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at com.aspiro.wamp.App.c(App.java:165)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at com.aspiro.wamp.App.onCreate(App.java:7161)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at androidx.test.runner.MonitoringInstrumentation.callApplicationOnCreate(MonitoringInstrumentation.java:413)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5822)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at android.app.ActivityThread.-wrap1(Unknown Source:0)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1666)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at android.os.Handler.dispatchMessage(Handler.java:105)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at android.os.Looper.loop(Looper.java:251)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at android.app.ActivityThread.main(ActivityThread.java:6572)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at java.lang.reflect.Method.invoke(Native Method)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
05-08 10:01:18.336 E/AndroidRuntime(24598):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)