dalvik couldnt found methods, although they exist in classes.dex - android

Starting my android-apk on the device, dalvik complains not to find some methods although all this methods are contained in classes.dex to see using
apkanalyser dex packages ....
These methods are from platform base android.jar
Why dalvik can not find them?
Background:
This apk is built using the command line tools without gradle.
(To understand the processes basically)
Platform is android-25 excactly 25.3.1
build_tools_version="27.0.3"
The dalvik messages:
I/dalvikvm(17763): Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
W/dalvikvm(17763): VFY: unable to resolve virtual method 535: Landroid/content/res/TypedArray;.getType (I)I
D/dalvikvm(17763): VFY: replacing opcode 0x6e at 0x0008
but contained in classes.dex:
M d 1 1 133 android.support.v7.widget.TintTypedArray int getType(int)
M r 0 1 26 android.content.res.TypedArray int getType(int)
I do not expect souch warning because the methods are listed in classes.dex

Any method that is referenced (i.e. used by an invoke instruction) will "exist" in the dex file. e.g. there will be an entry in the method id list for that method. That doesn't mean that the method itself exists.
If you look at the api documentation for TypedArray, you'll notice that the getType() method was only added as of api 21. api 19/20 (kitkat) was the last platform version that included dalvik, so your device is definitely less than api 21, and thus won't have the TypedArray.getType() method.

Related

Dalvik Verifier: register1 v25 type 0, wanted ref

I have the following Smali code:
.method private k(I)V
.registers 27 (original) 29 (after)
...
##68a
invoke-direct/range {v24 .. v25}, Landroid/widget/LinearLayout;-><init>(Landroid/content/Context;)V
...
This is rejected by the Dalvik verifier. 0x76 is invoke-direct/range.
dalvikvm: VFY: register1 v25 type 0, wanted ref
dalvikvm: VFY: bad arg 1 (into Landroid/content/Context;)
dalvikvm: VFY: rejecting call to Landroid/widget/LinearLayout;.<init> (Landroid/content/Context;)V
dalvikvm: VFY: rejecting opcode 0x76 at 0x068a
dalvikvm: VFY: rejected Lcom/pocketwood/myav/MyAV;.k (I)V
dalvikvm: Verifier rejected class Lcom/pocketwood/myav/MyAV;
dalvikvm: Class init failed in newInstance call (Lcom/pocketwood/myav/MyAV;)
Interestingly v25 is not used in any instruction above 68a! The original APK runs fine, but repacked with smali the verifier rejects class MyAV.
I suspect you have the wrong code location. If you look at the error message, it mentions opcode 0x76, which is invoke-direct/range. The code snippet you provided does not have an invoke-direct/range instruction, so, unless something really screwy is going on, that can't be the code that's causing the issue.
Also, take a look at the name of the method in the error message: Lcom/pocketwood/myav/MyAV;.k (I)V. There is what looks like a space after the k. The space character itself isn't a valid character in a method name, but maybe it's actually some other space-like unicode character?
Nevermind. That space appears to be baked into the error message.
Finally, the offset mentioned in the error message (at 0x068a) should be the code offset of the instruction within the containing method. You can use baksmali's --offsets option when disassembling the dex file, and baksmali will add a comment with the code offset before each instruction. Although, I'm not sure offhand if the offset is in bytes or code units, which are 16 bits, so it may be off by a factor of 2.
The solution is: v26 is p1 and v25 is p0. Due to modification, the register count has been extended to 29 and due to that v25 is no longer p0.

What will happen if i run a apk with high api compiled in a low api device?

now i have a project, which is compiled with API 14. By "is compiled", i mean the project.properties file has a line "target=android-14". But, i defined the android:minSDK=8 in the AndroidManifest.xml.
In this project, i used the high api features, like android.animation.ValueAnimator, android.app.ActionBar. The project, of course, will run perfectly in high api device.
Since the minSDK is 8, so we can install the apk in 2.x devices, but what will happen then? the ValueAnimator and ActionBar will be erased? or we actually cannot install the apk in 2.x devices?
if your app is loaded into memory the logcat will get warnings if classes/methods cannot be resolved. Example:
I/dalvikvm﹕ Could not find method java.lang.String.isEmpty, referenced from method eu.lp0.slf4j.android.LoggerFactory.getConfig
W/dalvikvm﹕ VFY: unable to resolve virtual method 524: Ljava/lang/String;.isEmpty ()Z
D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0010
D/dalvikvm﹕ VFY: dead code 0x0013-0044 in Leu/lp0/slf4j/android/LoggerFactory;.getConfig (Ljava/lang/String;)Leu/lp0/slf4j/android/LoggerConfig;
If your app is trying to execute code that is not supported by your device you get an exception NoSuchMethodError or ClassNotFoundException
W/dalvikvm﹕ Exception Ljava/lang/NoSuchMethodError; thrown during Lde/k3b/android/cellinfo/demo/CellInfoDemoActivity;.
Here is a complete example logcat: https://github.com/lp0/slf4j-android/issues/2
To avoid calling methods/classes that your device does not support
you can use code like this
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// call method/class that is only available in HONEYCOMB and later
}
For more details see https://developer.android.com/guide/practices/compatibility.html
If you are not using the corresponding classes from the support library, but the native ones that are only included in later versions of Android, your app will crash with a ClassNotFoundException or a NoSuchMethodError.
A workaround would be to either switch to the support libraries (if there are any depending on what features you use), or disable certain functionality of the app depending of the API version the app runs on.

Android warning - Could not find method android.widget.LinearLayout$LayoutParams.<init> ref from Android.Support.V7

I'm not sure where this error is generating from. My application works fine and I've not come across any crashing; however I receive the below in my LogCat.
My application uses an ActionBar and ListView. Anyone come across this before?
EDIT: Seems to be only happening when running on Android 2.x
Could not find method android.widget.LinearLayout$LayoutParams., referenced from method android.support.v7.internal.view.menu.ActionMenuView$LayoutParams.
VFY: unable to resolve direct method 8309: Landroid/widget/LinearLayout$LayoutParams;. (Landroid/widget/LinearLayout$LayoutParams;)V
VFY: replacing opcode 0x70 at 0x0000
VFY: dead code 0x0003-0007 in Landroid/support/v7/internal/view/menu/ActionMenuView$LayoutParams;. (Landroid/support/v7/internal/view/menu/ActionMenuView$LayoutParams;)V
This sounds like those classes are missing from your apk. Make sure to include the necessary Jars into your Apk (sounds like the support library).
Also in relation to this error, this is due to the Class Loader trying to resolve the reference in your code to actual operation codes (opcode) that the OS can recognize.
I had somewhat a similar issue. But later I found that I was trying to call a menu which does not exist.

Stripping out AWT references from Android Dex file at compile time

I am getting warnings in my Android app saying that my bytecode makes illegal references to java.awt and in some cases the runtime seems to replace invalid opcodes.
09-22 19:36:41.688: W/dalvikvm(831): VFY: unable to find class referenced in signature (Ljava/awt/Component;)
09-22 19:36:41.688: W/dalvikvm(831): VFY: unable to resolve virtual method 523: Ljava/awt/Component;.isLightweight ()Z
09-22 19:36:41.688: D/dalvikvm(831): VFY: replacing opcode 0x6e at 0x0000
Is there something I can do to tell the DX tool to clean out or replace these references earlier (like at compile time) so that the generated dex file no longer has those references?
You might try proguard. I don't know offhand if it can strip out unused methods inside a class, or if it only strips out entire classes. If it's the former, it will likely be able to get rid of the offending references. If it's the latter, probably not.
But in any case, these are just warnings, and are mostly harmless. The only "harm" is that it adds a bit of bloat to your dex file, which requires a bit of extra memory/disk space.

"VFY: dead code" when attempting to use getBytes(Charset)

Everything was working fine in my app. Then, I did a small refactoring and a key component stopped working. When I looked at the LogCat output, this is what I found:
WARN/dalvikvm(488): VFY: unable to resolve virtual method 10830: Ljava/lang/String;.getBytes (Ljava/nio/charset/Charset;)[B
DEBUG/dalvikvm(488): VFY: replacing opcode 0x6e at 0x000e
DEBUG/dalvikvm(488): VFY: dead code 0x0011-0015 in Lcom/appiancorp/tempo/android/service/CommentXmlHttpMessageConverter;.writeInternal (Lcom/appiancorp/tempo/android/model/EntryComment;Lorg/springframework/http/HttpOutputMessage;)V
This was ... surprising, to say the least. I looked at the documentation and the method is there, what gives?
The getBytes(Charset) exists in API9 and later. Make sure you are building against this version of the SDK or use the getBytes(String charsetName) which exists in API1.
You can also you the "filter by API level" checkbox in online SDK documentation to gray out methods not available in the version you are building against.

Categories

Resources