I'm trying the Hello World example from https://android.googlesource.com/platform/dalvik/+/gingerbread/docs/hello-world.html
However, my Foo program did not run; dalvikvm complained about the following:
Dalvik VM unable to locate class 'Foo'
java.lang.NoClassDefFoundError: Foo
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Foo in loader dalvik.system.PathClassLoader[/mnt/sdcard/foo.jar]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
... 1 more
Logcat gave more information during the dalvikvm invocation:
D/dalvikvm( 1361): creating instr width table
E/dalvikvm( 1361): Can't open dex cache '/data/dalvik-cache/mnt#sdcard#foo.jar#classes.dex': No such file or directory
I/dalvikvm( 1361): Unable to open or create cache for /mnt/sdcard/foo.jar (/data
/dalvik-cache/mnt#sdcard#foo.jar#classes.dex)
W/dalvikvm( 1361): threadid=1: thread exiting with uncaught exception (group=0x4
001e9a8)
Does anyone out there know what I did wrong?
The author of the article, Andy McFadden, give me a tip:
It's trying to create a .odex file in /data/dalvik-cache. You'll
need to be running as root, or have an unprotected
/data/dalvik-cache.
Once I rooted my device (e.g. using SuperOneClick), it worked!
Comment by #domen: You don't actually have to be root. You can set ANDROID_DATA environment variable and it will put cache there. I.e. mkdir /data/local/tmp/dalvik-cache, export ANDROID_DATA=/data/local/tmp.
It seems like you are trying to run it as a jar file from the sdcard. You need to use the tools to build it as an apk file. This converts from Java bytecodes to Dalvik codes, and reorganizes the contents of the file.
Related
For the purpose of developing an Anti-malware on Android, I need to have the smali representation of an APK.
I'm trying to execute the the baksmali.jar directly on the device. I asked the author of the tool GitHub: Executing baksmali on an Android device.
I followed the steps according to the post
Stack overflow: How to execute the dex file in android with command?
I downloaded the v2.2b4 version
dx --dex --output=classes.dex baksmali.jar I used the dx tool from android/Sdk/build-tools/25.0.2
zip baksmali.zip classes.dex
adb push baksmali.zip /sdcard/ I'm using a genymotion emulator custom phone-4.4.4 API 19
adb shell mkdir /sdcard/dalvik-cache
adb shell ANDROID_DATA=/sdcard dalvikvm -cp /sdcard/baksmali.zip org.jf.baksmali.Main
After that, I'm getting this error message Unable to locate class 'org/jf/baksmali/Main'
Precisely
Unable to locate class 'org/jf/baksmali/Main'
java.lang.NoClassDefFoundError: org/jf/baksmali/Main
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jf.baksmali.Main" on path: DexPathList[[zip file "/sdcard/baksmali.zip"],nativeLibraryDirectories=[/system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
... 1 more
Suppressed: java.io.IOException: unable to open DEX file
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:296)
at dalvik.system.DexFile.<init>(DexFile.java:80)
at dalvik.system.DexFile.<init>(DexFile.java:59)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:263)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:230)
at dalvik.system.DexPathList.<init>(DexPathList.java:112)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:38)
at java.lang.ClassLoader.createSystemClassLoader(ClassLoader.java:116)
at java.lang.ClassLoader.access$000(ClassLoader.java:65)
at java.lang.ClassLoader$SystemClassLoader.<clinit>(ClassLoader.java:81)
at java.lang.ClassLoader.getSystemClassLoader(ClassLoader.java:125)
... 1 more
I don't understand this error, the classe path is correct.
How can I fix this ?
Thank you in advance.
After moving around, I finally found the solution to the following problem:
" execute the baksmali.jar in an android device, ideally the execution is launched by an application targeting another application."
So, lets say we wont to develop an application that is able to "baksmali" (disassemble) another application, without requiring any special permission.
These are the steps to get the job done:
download the baksmali.jar v1.2.3
add the jar to the app/libs directory of the android studio project
right click on the jar and select the option "Add it as a Library"
(use the "Project->project" view to see the libs directory, you may not see it in the "Project->android" view)
you can use the org.jf.baksmali.main.mainmethode by passing the CLIarguments to that method using a String[]
Here is a helloWorld App illustrating the use cas:
GitHub: Baksmali Hello world
After launchig the application you should see folders in the /data/data/com.example.bartman.baksmalihelloworld/<name_of_baksmali_output>
I'm developing for 2.2 (minSdkVersion=8) and suddenly I'm getting this error:
arbitrarily rejecting large method (regs=75 count=28584)
rejected Lcom/Demo/Loyalty/SelectType;.onClick (Landroid/view/View;)V
Verifier rejected class Lcom/Demo/Loyalty/SelectType;
Class init failed in newInstance call (Lcom/Demo/Loyalty/SelectType;)
java.lang.VerifyError: com.Demo.Loyalty.SelectType
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1429)
at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
It was working fine until now.
Note : SelectType class has around 16000 lines of code but that is not that large I guess.
I search a lot on net and from answers, I did following:
Clean the project
Reset the ADB
Restart emulator/device/eclipse
Checked that third party library field is checked in build path
But I'm still getting that error.
Any help appreciated.
The steps you've described probably won't help.
The thing is, it's not a Dalvik issue. Similar verifier is employed in the Oracle Java VM for example. Simple answer: your method is too complex. The error you see is mainly caused by too many:
parameters
local variables
exception handlers
code instructions
More precisely, the issue has been described in this thread: https://groups.google.com/forum/?fromgroups=#!topic/android-developers/4qNoIdBHYFc
To quote:
The value of (number of registers * number of instruction words) is
larger than 2^21. (...)
it's intended to
prevent the verifier from bloating up an app's native heap.
You can also see similar report here: http://www.mentby.com/Group/android-developers/verifyerror-arbitrarily-rejecting-large-method.html with pointers on how to resolve the issue:
Yep, the Dalvik compiler attempts to assign a "register" to every
local variable in the method. It should be able to handle that many,
but apparently can't. By making them instance variables you remove
the compiler's need/desire to "manage" them (and also make the method
a fair amount smaller).
So to solve it, you should generally break the large method (probably onClick()?) into smaller pieces. Also, converting local variables to class fields seemed to help some people with the same issue.
I am trying to use Xuggler on Android to convert WAV files to M4A.
I have used the xuggle-xuggler-noarch-5.4.jar in my java build path
and copied the libxuggler.so file out of xuggle-xuggler-arch-i686-pc-linux-gnu.jar to my libs folder within my android application.
in my main activity i have a static initialiser that attempts to System.loadlibrary("libxuggler")
however i just get these set of info and error messages
I/dalvikvm(27614): Could not find method com.xuggle.mediatool.ToolFactory.makeReader, referenced from method com.example.quality.MainActivity.convertToMP3
W/dalvikvm(27614): VFY: unable to resolve static method 3376: Lcom/xuggle/mediatool/ToolFactory;.makeReader (Ljava/lang/String;)Lcom/xuggle/mediatool/IMediaReader;
W/dalvikvm(27614): Unable to resolve superclass of Lcom/example/quality/MainActivity$6; (485)
W/dalvikvm(27614): Link of class 'Lcom/example/quality/MainActivity$6;' failed
W/dalvikvm(27614): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/example/quality/MainActivity;
W/dalvikvm(27614): Class init failed in newInstance call (Lcom/example/quality/MainActivity;)
W/dalvikvm(27614): threadid=1: thread exiting with uncaught exception (group=0x40acf228)
My System.loadlibrary called failed with
UnsatisfiedLinkError: Couldn't load libxuggle: findLibrary returned null
is it possible to use Xuggler on Android
What have i done wrong?
What havent i done?
There is an explanation on xuggler-users group from Art Clarke :
I have not attempted to port xuggler to android, but if someone is interested all jvm related code is in the 'ferry' module. Memory mgmt is particularly complicated and hard, but in theory a port would be possible.
Ok so i've installed everything that should be needed in order for APV and/or MuPDF to work, but it still crashes.
I'm not very good at using shells to install programs and all that, but i did follow the instructions included in the readme files as good as i was able to.
When i try to run the program now (APV) It works fine until i try to open a pdf file, where i get the errors:
FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
cx.hell.android.pdfview.OpenFileActivity.getPDF(OpenFileActivity.java:442)
cx.hell.android.pdfview.OpenFileActivity.startPDF(OpenFileActivity.java:403)
cx.hell.android.pdfview.OpenFileActivity.onCreate(OpenFileActivity.java:169)
android.app.Activity.performCreate(Activity.java:4465)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
android.app.ActivityThread.access$600(ActivityThread.java:123)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
android.os.Handler.dispatchMessage(Handler.java:99)
android.app.ActivityThread.main(ActivityThread.java:4424)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load pdfview2: findLibrary returned null
java.lang.Runtime.loadLibrary(Runtime.java:365)
java.lang.System.loadLibrary(System.java:535) at cx.hell.android.pdfview.PDF.<clinit>(PDF.java:15)
I've installed everything in D:\Android , where i have the following subfolders:
apache-ant-1.8.3
android-ndk-r7c
android-sdk
Cygwin
apv (containing : pdfview\jni\ libraries like freetype, mupdf, jpeg, openjpg etc. also another version of android-ndk-r7c)
i've tried running all the build files included in the scrip documents like: build-native, scale-images, ndk-build![enter image description here][2]
This is a screen dump from build-native just before it finishes.
succesfull stuff happening
cp: cannot create regular file '../jni/freetype/include/freetype/config/ftoption.h': Permission denied
cp: cannot create regular file '../jni/freetype/include/freetype/config/sed008052': Permission denied
cp: cannot create regular file '../jni/freetype/include/freetype/config/sed007576': Permission denied
D:\Android\apv\pdfview\scripts\build-native.sh: line 31: gcc: command not found
D:\Android\apv\pdfview\scripts\build-native.sh: line 34: ../../scripts/fontdumpt: No such file or directory
I honestly have no idea how else to attack this and the tutorial at : http://mupdf.com/repos/mupdf/android/ReadMe.txt didn't do much for me. If anyone else have any experience using this then i'd really appreciate any help you could offer.
The application i'm making will be open source so by helping me you can get a good laugh at my code later on! :)
also, sorry for the shitty text but can't post images until i have 10 reputation
Thanks, Anders
A short history. please bear with me :)
I have an Android project that uses JNI which works very good.
I've decided to create out of the source of this jni project an external jar (for distribution)
In order to create this jar I've taken the advice of others and created a new Java project that holds the few jni classes I need to store in the jar. I've exported this java project to a jar (not as a runnable jar)
I've created a new Android Project in which I try to use the jar file in question.
After I've played with this new android project I came to realize that the .so file which should accompany the jni classes can't reside inside the jar file itself (Eclipse complained about it..) So I've created a lib directory inside the new Android Project which holds the .so file.
When I run this new Android project I can't work with any of the classes which has native methods, And I can only work with those classes which are pure java implementation.
I keep getting "ExceptionInInitializerError" when trying to create an instance of one of jni based objects.
Update:
It seems that the error comes from trying to load the jni library in line
System.loadLibrary("lib-jni");
Here is the logcat:
> ERROR/SightEngine(2479): About to load the lib-jni.so
ERROR/SightExample(2479): WARNING: Could not init SightEngine java.lang.ExceptionInInitializerError
ERROR/AndroidRuntime(2479): Uncaught handler: thread main exiting due to uncaught exception
ERROR/AndroidRuntime(2479): java.lang.RuntimeException: Unable to start activity ComponentInfo{eyesight.android.example/eyesight.android.example.SightExample}: java.lang.NullPointerException: println needs a message
ERROR/AndroidRuntime(2479): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
ERROR/AndroidRuntime(2479): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
ERROR/AndroidRuntime(2479): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
ERROR/AndroidRuntime(2479): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
ERROR/AndroidRuntime(2479): at android.os.Handler.dispatchMessage(Handler.java:99)
ERROR/AndroidRuntime(2479): at android.os.Looper.loop(Looper.java:123)
ERROR/AndroidRuntime(2479): at android.app.ActivityThread.main(ActivityThread.java:4363)
ERROR/AndroidRuntime(2479): at java.lang.reflect.Method.invokeNative(Native Method)
ERROR/AndroidRuntime(2479): at java.lang.reflect.Method.invoke(Method.java:521)
ERROR/AndroidRuntime(2479): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
ERROR/AndroidRuntime(2479): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
ERROR/AndroidRuntime(2479): at dalvik.system.NativeStart.main(Native Method)
ERROR/AndroidRuntime(2479): Caused by: java.lang.NullPointerException: println needs a message
ERROR/AndroidRuntime(2479): at android.util.Log.println(Native Method)
ERROR/AndroidRuntime(2479): at android.util.Log.e(Log.java:208)
ERROR/AndroidRuntime(2479): at eyesight.android.example.SightExample.onCreate(SightExample.java:28)
ERROR/AndroidRuntime(2479): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
ERROR/AndroidRuntime(2479): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
ERROR/AndroidRuntime(2479): ... 11 more
ERROR/dalvikvm(2479): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
A few pointers:
I can see the .so file inside the .apk file.
I've tried defining the external jar file in the JNI Android.mk but nothing exciting happened. here are the lines I used (it compiled without a problem..)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libtestjar:lib/testJar.jar
include $(BUILD_MULTI_PREBUILT)
I'm able to work with regular java classes that exist only in jar file. (I know I'm repeating myself.. :) ) which means I've correctly defined this jar in the project.
The java project that holds the jni based classes has a reference to the android.jar (sdk level 7)
Does anyone has any suggestions has to how this task can be accomplished? I feel like I'm almost there...
Thank you for your time and effort :)
Itamar
In the android project, did you put your .so files under lib/armeabi ?
by the way, i have the same setup as you (java project that builds a jar and an android project that uses the jar).
I managed to package the .so files in the jar ... here's what I did:
-when building the library JAR, I zip the .so files into a file (say armeabi.zip) and put it inside an 'assets' folder in the jar.
-when building the android project, the armeabi.zip will be in the 'assets' folder inside your apk.
-at runtime (first start) I extract the contents of armeabi.zip from the assets into "/data/data/" + context.getPackageName().
-finally load the extracted .so libs using System.load(/data/data//libfilename.so)
hope this helps.
Fadi
Looks like an error log call is missing a message.
ERROR/AndroidRuntime(2479): Caused by: java.lang.NullPointerException: println needs a message
ERROR/AndroidRuntime(2479): at android.util.Log.println(Native Method)
ERROR/AndroidRuntime(2479): at android.util.Log.e(Log.java:208)
ERROR/AndroidRuntime(2479): at eyesight.android.example.SightExample.onCreate(SightExample.java:28)