how to easily convert code .java to .dex in android to directly execute via adb

552 Views Asked by At

I have just started learning android. I want to run .java code directly via adb. I found a simple media player code here. Using android studio. converted it into .class as mentioned here & linking android.jar by copying it into libs folder. Then converting into .dex using dx tool in SDK-Android\build-tools\25.0.3 by ./dx --dex --output=Beep.dex Beep.class. Ran on my android running Android 7.1.2 in terminal ::

export CLASSPATH=./Beep.dex
app_process /system/bin Beep /system/media/audio/ringtones/Phobos.ogg

Got Output :: Killed . Then viewed its output using logcat ::

07-30 12:55:09.760 11704 11704 D AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
07-30 12:55:09.763 11704 11704 D AndroidRuntime: CheckJNI is OFF
07-30 12:55:09.834 11704 11704 D ICU     : No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
07-30 12:55:09.886 11704 11704 I Radio-JNI: register_android_hardware_Radio DONE
07-30 12:55:09.896 11704 11704 D AndroidRuntime: Calling main entry Beep
07-30 12:55:09.901 11704 11704 I art     : Thread[1,tid=11704,Native,Thread*=0x798ac40a00,peer=0x12c070d0,"main"] recursive attempt to load library "/system/lib64/libmedia_jni.so"
07-30 12:55:09.901 11704 11704 D MtpDeviceJNI: register_android_mtp_MtpDevice
07-30 12:55:09.901 11704 11704 I art     : Thread[1,tid=11704,Native,Thread*=0x798ac40a00,peer=0x12c070d0,"main"] recursive attempt to load library "/system/lib64/libmedia_jni.so"
07-30 12:55:09.901 11704 11704 I art     : Thread[1,tid=11704,Native,Thread*=0x798ac40a00,peer=0x12c070d0,"main"] recursive attempt to load library "/system/lib64/libmedia_jni.so"
07-30 12:55:09.976   534 11715 D NuPlayerDriver: notifyListener_l(0xeae20a80), (1, 0, 0), loop setting(0, 0)
07-30 12:55:09.982 11704 11718 E AndroidRuntime: *** FATAL EXCEPTION IN SYSTEM PROCESS: SetSubtitleAnchorThread
07-30 12:55:09.982 11704 11718 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
07-30 12:55:09.982 11704 11718 E AndroidRuntime:        at android.media.SubtitleController.<init>(SubtitleController.java:105)
07-30 12:55:09.982 11704 11718 E AndroidRuntime:        at android.media.MediaPlayer$2.run(MediaPlayer.java:2195)
07-30 12:55:09.982 11704 11718 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:751)
07-30 12:55:09.982 11704 11718 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:95)
07-30 12:55:09.982 11704 11718 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:154)
07-30 12:55:09.982 11704 11718 E AndroidRuntime:        at android.os.HandlerThread.run(HandlerThread.java:61)
07-30 12:55:09.992  1288  3721 W DropBoxManagerService: Dropping: system_server_crash (612 > 0 bytes)
07-30 12:55:09.994 11704 11718 I Process : Sending signal. PID: 11704 SIG: 9
07-30 12:55:10.011   534  2929 D NuPlayerDriver: reset(0xeae20a80) at state 4
07-30 12:55:10.011   534  2929 D NuPlayerDriver: notifyListener_l(0xeae20a80), (8, 0, 0), loop setting(1, 0)
07-30 12:55:10.012   534 11715 D NuPlayerDriver: notifyResetComplete(0xeae20a80)
07-30 12:55:10.897  3609  3670 W QCNEJ   : |CORE| CNE received unexpected action: android.intent.action.BATTERY_CHANGED

What is the cause of this error ?

Is this the correct way of converting into .dex for running directly via adb.

Can't this be done using just dx tool or other simple & straightforward method ?

0

There are 0 best solutions below