Stripping out AWT references from Android Dex file at compile time - android

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.

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.

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.

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.

Won't add 8th library

Eclipse is seemingly having intense difficulties adding** 8 libraries to my project. Is there an unspoken maximum of 7 libraries per project that I haven't heard of?
I am getting issues saying that the compiler "Could not find class *"
An example is this:
favorite
I have a project that runs perfectly fine on newer devices and API levels, however, I'm getting some issues on emulators. When I load up the application on an emulator, I get this issue:
02-22 18:36:11.584: W/dalvikvm(652): VFY: unable to resolve exception class 872 (Lcom/google/zxing/WriterException;)
02-22 18:36:11.584: W/dalvikvm(652): VFY: unable to find exception handler at addr 0x7da
02-22 18:36:11.584: W/dalvikvm(652): VFY: rejected Lcom/example/myapp/Card;.getFrontView (Landroid/content/Context;)Landroid/widget/LinearLayout;
02-22 18:36:11.584: W/dalvikvm(652): VFY: rejecting opcode 0x0d at 0x07da
02-22 18:36:11.584: W/dalvikvm(652): VFY: rejected Lcom/example/myapp/Card;.getFrontView (Landroid/content/Context;)Landroid/widget/LinearLayout;
02-22 18:36:11.584: W/dalvikvm(652): Verifier rejected class Lcom/example/myapp/Card;
At first I thought it may have been either my library or how I was adding** it, but I've recently cleared*** all of my libraries and readded them and I'm getting the same issues on a different library.
02-25 21:03:45.379: E/dalvikvm(12018): Could not find class 'org.apache.commons.validator.routines.UrlValidator', referenced from method com.example.myapp.Card
02-25 21:03:45.379: W/dalvikvm(12018): VFY: unable to resolve new-instance 1054 (Lorg/apache/commons/validator/routines/UrlValidator;) in Lcom/example/myapp/Card;
These errors mean that the project doesn't have proper access to my library's classes, right? But why is the error inconsistent for which library it is? I've tried removing*** and readding the libraries the exact same way that the other libraries were added, but there's no luck on library #8.
What do I do?
** Adding: I've tried adding the libraries to a User Library (includes all of the existing documents that I have) and just simply copying the .jar to the libs folder.
* Removing: To get rid of the library, if it is inside a User Library, I will edit my User Library containing the .jar I'm looking to remove and use the "remove" option. Otherwise, I will simply right click and "delete" the library from the libs directory.
As for a "User Library"

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