我刚开始学习安卓。我想直接通过 adb 运行 .java 代码。我在这里找到了一个简单的媒体播放器代码。使用安卓工作室。将其转换为此处提到的 .class 并通过将其复制到 libs 文件夹来链接 android.jar。SDK-Android\build-tools\25.0.3
然后在by 中使用 dx 工具转换成 .dex ./dx --dex --output=Beep.dex Beep.class
。在终端运行 Android 7.1.2 的我的 android 上运行::
export CLASSPATH=./Beep.dex
app_process /system/bin Beep /system/media/audio/ringtones/Phobos.ogg
得到输出 :: Killed
。然后使用 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
这个错误的原因是什么?
这是转换为 .dex 以直接通过 adb 运行的正确方法吗?
这不能仅使用 dx 工具或其他简单直接的方法来完成吗?