dalvikvm类找不到错误解决方案

运行官方的helloworld.smali报错找不到类,好奇怪,经过一番google后才发现,原来要在root权限下才可以执行。

报错:

Dalvik VM unable to locate class 'Helloworld'
java.lang.NoClassDefFoundError: Helloworld
	at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "Helloworld" on path: /data/local/HelloWorld.zip

smali代码

.class public LHelloWorld;

#Ye olde hello world application
#To assemble and run this on a phone or emulator:
#
#java -jar smali.jar -o classes.dex HelloWorld.smali
#zip HelloWorld.zip classes.dex
#adb push HelloWorld.zip /data/local
#adb shell dalvikvm -cp /data/local/HelloWorld.zip HelloWorld
#
#if you get out of memory type errors when running smali.jar, try
#java -Xmx512m -jar smali.jar HelloWorld.smali
#instead

.super Ljava/lang/Object;

.method public static main([Ljava/lang/String;)V
    .registers 2

    sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

    const-string	v1, "Hello World!"

    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    return-void
.end method


shell脚本

#!/bin/bash

java -jar smali-2.0.3.jar -o classes.dex HelloWorld.smali
zip HelloWorld.zip classes.dex
adb shell su -c 'chmod 777 /data/local'
adb push HelloWorld.zip /data/local
adb shell su -c 'dalvikvm -cp /data/local/HelloWorld.zip HelloWorld'







你可能感兴趣的:(dalvikvm类找不到错误解决方案)