问题
I am following this link I have first executed this command successfully.
javac <path + filename>.java
Then after when I am trying to execute following command I facing an error "class name does not match path".
dx --dex --output=<path + filename>.dex <path + filename>.class
I have same name for .class and .java but I think I have to write explicit path of .class file name. So what to do now. There is some minor mistake that I am doing but not able to find.
回答1:
To avoid magic number problem ,First check your jdk version ,it seems there is a problem with jdk 1.7* . i reverted to jdk 1.6 .
Instead of using dx --dex --output=<path + filename>.dex <path + filename>.class
we can do one thing put one or all your .classes files in one folder say classFolder
now issue following command :
dx --dex --output=YourClass.dex absolutePath/classFolder
dx command will pick one or all class files in that folder .
回答2:
Your command seems to be wrong:
dx --dex --output=.dex .class
Have you tried this?
dx --dex --output=YourClass.dex YourClass.class
回答3:
dx is picky about the paths that you give it - the relative path of the class file relative to your working directory has to match the package of the class.
For example, if your command is
dx --dex --output=classes.dex out/com/example/HelloWorld.class
Then dx assumes that the package name of HelloWorld should be out.com.example, and complains if it isn't.
However, there is a trick - you can add a /./
path component in the path you give dx, to specify where the "root" is, with respect to the java package. If the package in the previous example is actually com.example, then you can do:
dx --dex --output=classes.dex out/./com/example/HelloWorld.class
Another option is to use the --no-strict option, which disables dx's path checks.
来源:https://stackoverflow.com/questions/15089370/unable-to-execute-java-file-through-davik-vm