Issues running obfuscated DEX modules - AbstractMethodError - android

I'm developing an Android application based on a main APK installed on the mobile device, and some android modules that are compiled to a .dex file. These files are loaded at runtime by the main application and the classes inside the .dex files are instantiated via Dynamic Dex Loading.
I'm facing some issues related to proguard, as even if I use the #Keep annotation on exposed methods in the modules and the main APK and I tell to proguard to keep interfaces methods, when I call one of the methods implemented in a module i get:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.myproject, PID: 13893
java.lang.AbstractMethodError: abstract method "z.a com.android.myproject.MyClass.mymethod()"
at com.android.myproject.MainService.H(:784)
at com.android.myproject.MainService.M(:258)
at com.android.myproject.MainService.a0(:198)
at com.android.myproject.MainService.U(:148)
at com.android.myproject.MainService.C(:133)
at com.android.myproject.MainService.onServiceConnected(:90)...
If i try to debug, and i place a breakpoint right on the method call, using the "Evaluate Expression" tool in Android Studio I'm able to call the method with success, but if I let it execute on its own it crashes with the previous exception.
Can someone help me please? Thank you very much

Related

Shadow PackageParser.call ParsePackage PackageParser$Packageparserexception

I am trying to move my code to dynamic feature and while moving the test cases i created a test package inside dynamic feature module and moved related test classes there.
The test cases are not running and failing with below exception
java.lang.RuntimeException: android.content.pm.PackageParser$PackageParserException: Failed to parse /Users/anujjha/../build/intermediates/apk_for_local_test/debugUnitTest/packageDebugUnitTestForUnitTest/apk-for-local-test.ap_
at org.robolectric.shadows.ShadowPackageParser.callParsePackage(ShadowPackageParser.java:69)
at org.robolectric.android.internal.AndroidTestEnvironment.loadAppPackage_measured(AndroidTestEnvironment.java:314)
at org.robolectric.android.internal.AndroidTestEnvironment.lambda$loadAppPackage$1(AndroidTestEnvironment.java:284)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:53)
at org.robolectric.android.internal.AndroidTestEnvironment.loadAppPackage(AndroidTestEnvironment.java:282)
at org.robolectric.android.internal.AndroidTestEnvironment.installAndCreateApplication(AndroidTestEnvironment.java:178)
at org.robolectric.android.internal.AndroidTestEnvironment.setUpApplicationState(AndroidTestEnvironment.java:169)
at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:301)
There are all junit test cases. Any idea how to make it work.and what can i check in code or gradle.

NoClassDefFoundError ObjenesisStd on Android API 19

I'm getting the following crashing during an instrumentation test ONLY on emulators running API v19. If I run on newer versions everything works fine.
03-01 20:26:18.781 2878-2878/? E/MonitoringInstrumentation: Exception
encountered by: Thread[main,5,main]. Dumping thread state to outputs
and pining for the fjords.
java.lang.NoClassDefFoundError: org.objenesis.ObjenesisStd
at org.mockito.internal.creation.jmock.ClassImposterizer.(ClassImposterizer.java:36)
at org.mockito.internal.creation.jmock.ClassImposterizer.(ClassImposterizer.java:29)
at org.mockito.internal.util.MockCreationValidator.isTypeMockable(MockCreationValidator.java:17)
at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:21)
at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:133)
at org.mockito.internal.creation.MockSettingsImpl.confirm(MockSettingsImpl.java:127)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:50)
at org.mockito.Mockito.mock(Mockito.java:1243)
at org.mockito.Mockito.mock(Mockito.java:1120)
The problem is this line:
java.lang.NoClassDefFoundError: org.objenesis.ObjenesisStd
My app is multi-dex, and I'm using dexmaker-mockito for androidTestCompile. I'm at a complete loss why this only breaks on an older API. It started happening when I added another module to my project, which is a pure java module with no dependency on mockito.
This exception (ClassNotFoundException) tells you about a unmet dependency at runtime: the JVM needs to load a class; which is not present in the class path.
Here it is Mockito that needs Objenesis. Normally that library should be pulled automatically when you a system like maven and give the correct dependency to Mockito.

VerifyError in multidex app when injecting dependency with Dagger

A sample app for library has ~67k methods. It has multidex enabled to overcome the 65k method limit. Unfortunately with multidex enabled the app crashes on VerifyError when trying to inject EndpointAdapter in main activity.
This issue doesn't occur when the app is proguarded and the multidex is disabled, so it must be caused by multidex and Dagger 1 problems.
I'm sure EndpointAdapter is in the main dex file, but some classes generated by Dagger are located in the second dex file generated by multidex. This issue occurs on devices with API < 21 (eg. on genymotion with KitKat 4.4.4).
Any idea why it crashes with VerifyError?
FATAL EXCEPTION: main
Process: pl.toro.libsample.debug, PID: 11775
java.lang.VerifyError: pl/toro/lib/network/EndpointAdapter
at java.lang.Class.getDeclaredConstructors(Native Method)
at java.lang.Class.getDeclaredConstructors(Class.java:574)
at dagger.internal.loaders.ReflectiveAtInjectBinding.getConstructorsForType(ReflectiveAtInjectBinding.java:232)
at dagger.internal.loaders.ReflectiveAtInjectBinding.create(ReflectiveAtInjectBinding.java:168)
at dagger.internal.FailoverLoader.getAtInjectBinding(FailoverLoader.java:74)
at dagger.internal.Linker.createBinding(Linker.java:224)
at dagger.internal.Linker.linkRequested(Linker.java:141)
at dagger.ObjectGraph$DaggerObjectGraph.getInjectableTypeBinding(ObjectGraph.java:309)
at dagger.ObjectGraph$DaggerObjectGraph.inject(ObjectGraph.java:279)
at pl.toro.lib.app.BaseApplication.inject(BaseApplication.java:135)
...
Here's output of the MultiDex tag
VM with version 1.6.0 does not have multidex support
install
MultiDexExtractor.load(/data/app/pl.toro.libsample.debug-1.apk, false)
Detected that extraction must be performed.
Extraction is needed for file /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes2.zip
Extracting /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes-1477675005.zip
Renaming to /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes2.zip
Extraction success - length /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes2.zip: 187777
load found 1 secondary dex files
install done
EDIT
I've switched to Dagger 2 and this issue is resolved as of now. Dagger 2 no longer uses reflection which is the major factor of this issue.
As pointed out in this blog post[1], are you creating the dagger graph after installing the multi-dex. So in MultiDexApplication#attachBaseContext after the call to super (or calling MultiDex.install() yourself).
[1] https://developers.soundcloud.com/blog/congratulations-you-have-a-lot-of-code-remedying-androids-method-limit-part-2

Native application crashes on Android L

I have a native application that always worked on Android KitKat with both Dalivik and ART runtimes, but it now crashes on Android L with the following trace:
E/art(12810): dlopen("/data/app-lib/com.mylib.example", RTLD_LAZY) failed: dlopen failed: cannot locate symbol "issetugid" referenced by "mylib.so"...
D/AndroidRuntime(12810): Shutting down VM
E/AndroidRuntime(12810): FATAL EXCEPTION: main
E/AndroidRuntime(12810): Process: com.mylib.example, PID: 12810
E/AndroidRuntime(12810): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "issetugid" referenced by "mylib.so"...
E/AndroidRuntime(12810): at java.lang.Runtime.loadLibrary(Runtime.java:364)
E/AndroidRuntime(12810): at java.lang.System.loadLibrary(System.java:610)
Is ART runtime in Android L different from KitKat? There is no new NDK available yet, therefore, how to avoid this crash, because it seems that the function issetugid is no longer supported.
The issue has been fixed in the final Android 5.0 release. There is no need to re-compile existing binaries.
However, if the native lib is compiled with target android-21, it fails on previous Android versions (< 5.0)
I think i may have the answer, please correct me if iam wrong.I had faced similar issue and now its fixed (or i have found a workaround rather)
while registering native method to JNI, there are two ways of doing it.
1) Implement JNI_OnLoad() method in your .cpp file and register your native methods with the
appropriate classes.
Check- http://developer.android.com/training/articles/perf-jni.html#native_libraries
example - https://android.googlesource.com/platform/development/+/master/samples/SimpleJNI/jni/native.cpp
2) there is a particular naming convention to follow for the native methods, where the class path (including package) have to be added.
Check - http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/design.html#wp615
Here we need not implement any method. The JVM discovers the native method from the symbol names it self from the binary.
The first method doesn't seem to work in Android ART runtime (ART is Optional in kitkat and it will be the only runtime in Lolipop).I am not not sure why it doesnt work. but i think the reason is because the way ART performs.(The bytecodes are converted and cached during install time itself instead of runtime, so that app runs faster). So since the native libs are not loaded (on_load is not called) the conversion to machine code fails at some point
Use the second method to register natives. it should work.
Only disadvantage is now your function names will be and long and will look horrible (i bet none of the function will fit in 100char limit).bye bye function name readability.
Hope this helps
Cheers,
Shrish

Android NoClassDefFound when referencing class from external libraries (IntelliJ IDEA 12)

I'm having an issue with IntelliJ's dependency handling in regards to external modules. Here's some context:
I'm writing an Android app which implements Google Maps. For my current feature set, I require two external libraries-- Google's Play Services Library and mapex (A third party google map extension library located here https://code.google.com/p/mapex/). I actually built most of this project in Android Studio before I was recommended to move to IntelliJ due to the easier dependency handling. But now I'm here and still having problems.
My Error
When trying to build an object from a class located in the mapex package (com.androidnatic.maps), I get this error when starting the activity the view is contained in (object has not been created yet):
07-03 11:40:35.837: ERROR/dalvikvm(3585): Could not find class 'com.androidnatic.maps.SimpleMapView', referenced from method com.example.myproject.MapActivity.showHeatMap
And then, upon creation, my app force closes and leaves this behind in logcat:
7-03 11:40:45.467: ERROR/AndroidRuntime(3585): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.androidnatic.maps.SimpleMapView
at com.example.myproject.MapActivity.showHeatMap(MapActivity.java:492)
Yet I'm completely stumped because my IDE gives me no sign that anything is wrong! Classes are auto-filled in when trying to access them from MyProject.
ide-fill-in http://www.tonyandrys.com/img/fillin.jpg
No build errors about missing classes, missing modules, class definitions, or anything related.
I get the same results if I try to access the class via its full package name as well.
// No dice.
final SimpleMapView mapView = new SimpleMapView(this, "apikey");
final com.androidnatic.maps.SimpleMapView mapView = new com.androidnatic.maps.SimpleMapView(this, "apikey");
It seems that there's only an issue when the application is running on my phone, as far as my IDE is concerned.
Here's the structure of MyProject:
main-project-structure http://www.tonyandrys.com/img/mainstructure.jpg
Here's my main project's dependency settings (where I assume I screwed up somewhere):
project-structure http://www.tonyandrys.com/img/projectstructure.jpg
And here is the structure of the mapex library module:
mapex-lib http://www.tonyandrys.com/img/mapexstructure.jpg
The class files that I'm trying to access live in MapExLib/gen and MapExLib/src, which are currently marked as source directories (blue).
Does anyone have any ideas on how to proceed from here?
Try to do this :
Android, IntelliJ Idea, changing module type
I had the same error "Could not find class XXX from referenced method XXX" with Intellij, involving an Android Test Module and a test which could not find the Activity class anywhere.
I set inside the Project Structure the main Module's Facet Android to Library Module (checkbox) and it worked...
Let us know

Categories

Resources