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

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.

Related

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

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.

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.

VFY: unable to resolve virtual method 4258: Android/view/View;.setAlpha (F)V

I am getting this error:-
VFY: unable to resolve virtual method 4258: Landroid/view/View;.setAlpha (F)V, VFY: unable to resolve virtual method 4276: Landroid/view/View;.setTranslationX (F)V
this message in my logcat:-
Could not find method android.view.View.setTranslationX, referenced from method com.learning.animation.ZoomOutPageTransfer.transformPage.
I am trying to add ZoomOut page transfer animation using viewpager and for this I follow this link for Zoom out Page transfer, my application is running but it is not zooming out the page as it is shown in the above mentioned link to be.Please if anyone know the solution kindly tell.
Thank you in advance.
setTranslationX method is available only on android 3.0 ( api level 11) and up. Are sure you're using device/emulator with proper android version?

Android library calls setContentView using its own resource, but fails with "unable to resolve static field"

I've written + imported my own library that includes an OAuth login feature. It needs to call "setContentView(R.layout.authorize)" on its own layout resource, authorize.xml which is defined in the library's res/layout folder. If I run the library as a regular project (using a test Activity), everything works fine. However, if I use the library in another project, I get the following error, indicating my authorize.xml layout cannot be found.
05-17 16:56:10.436: W/dalvikvm(212): VFY: unable to resolve static field 29 (twitter_authorize_webview) in Lcom/skworks/twitter/R$layout;
05-17 16:56:10.436: W/dalvikvm(212): VFY: rejecting opcode 0x60 at 0x0003
05-17 16:56:10.436: W/dalvikvm(212): VFY: rejected Lcom/skworks/twitter/AuthorizeActivity;.onCreate (Landroid/os/Bundle;)V
05-17 16:56:10.436: W/dalvikvm(212): Verifier rejected class Lcom/skworks/twitter/AuthorizeActivity;
05-17 16:56:10.436: W/dalvikvm(212): Class init failed in newInstance call (Lcom/skworks/twitter/AuthorizeActivity;)
Here is the code in my main activity
Intent i = new Intent(this, AuthorizeActivity.class);
i.putExtra("URL", mRequestToken.getAuthenticationURL());
this.startActivityForResult(i, TWITTER_AUTH);
And obviously this is in onCreate of my AuthorizeActivity class, found in the library.
setContentView(R.layout.authorize);
I'm sure something is not setup correctly to expose resources defined in my library. Any ideas?
You may need to check the build settings for your library. It could be that it is not packaging up the layout file into your jar/apk. It could also be that the project using the library is not bundling the files into the deliverable apk. That's where I would start looking.
Check imports, that you havnt imported the android.R.
Else as mtmurdock said, check that your project is being build, try clean it.
You might have an xml error.

Categories

Resources