0

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.

Community
  • 1
  • 1
Yash
  • 634
  • 1
  • 6
  • 17

3 Answers3

5

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.

JesusFreke
  • 19,784
  • 5
  • 65
  • 68
2

Your command seems to be wrong:

dx --dex --output=.dex .class

Have you tried this?

dx --dex --output=YourClass.dex YourClass.class
Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101
  • Its showing as a warning. Class name dont match path (path + filename.class). – Yash Feb 26 '13 at 12:57
  • @YashRajDave call `javac` and `dex` in the same folder where your file is. Are you using any package, what is it name? – Nikolay Kuznetsov Feb 26 '13 at 13:00
  • Package name is com.hello.java. – Yash Feb 26 '13 at 13:07
  • I called javac and dex in same folder as you suggested. After executing dex command its showing "bad class file magic (cafebabe) or verison(0033.0000) while parsing .class".1 warning. no classfiles specified. – Yash Feb 26 '13 at 13:14
  • `` what is that? Why are keep using that notation, it makes more confusing. – Nikolay Kuznetsov Feb 26 '13 at 13:27
  • dx --dex --output=E:\ProjectsJava\Android\HelloWorld\src\com\hello\world\HelloWorld.dex E:\ProjectsJava\Android\HelloWorld\src\com\hello\world\HelloWorld.class – Yash Feb 26 '13 at 14:19
  • I am facing the problem executing last command shown in that link. It is showing that "dalvik: permission denied", when I typed this command: adb shell ANDROID_DATA=/sdcard dalvikvm -cp /sdcard/HelloWorld.zip HelloWorld – Yash Mar 10 '13 at 09:13
2

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 .

Imposter
  • 2,666
  • 1
  • 21
  • 31
  • I have checked ma version is 1.6.0.27. And I made one folder and put .class file into in and executed the command but I am facing the same error sir. – Yash Feb 27 '13 at 13:12
  • trouble processing : bad class file magic(cafebabe) or version (0033.0000) ...while parsing absolute path/helloworld.class 1 warning no classfiles specified. – Yash Feb 27 '13 at 13:49
  • Try editing proguard.bat file in (Android SDK\tools\proguard\bin) , instead of "call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %*" change it to "call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %1 %2 %3 %4 %5 %6 %7 %8 %9" . – Imposter Feb 27 '13 at 14:00
  • My proguard.bat file is -> @ECHO OFF REM Start-up script for ProGuard -- free class file shrinker, optimizer,REM obfuscator, and preverifier for Java bytecode. REMREM Note: when passing file names containing spaces to this script,REM you'll have to add escaped quotes around them, e.g. REM "\"C:/My Directory/My File.txt\""IF EXIST "%PROGUARD_HOME%" GOTO homeSET PROGUARD_HOME=..:home java -jar "%PROGUARD_HOME%"\lib\proguard.jar %* – Yash Feb 27 '13 at 14:41
  • In the last line "java -jar "%PROGUARD_HOME%"\lib\proguard.jar %" . – Imposter Feb 27 '13 at 15:10
  • trouble processing: bad class file magic (cafebabe) or version (0033.0000) ...while parsing E:/Projects/Java/Android/HelloWorld/src/com/hello/world/HelloWo rld.class ...while processing E:/Projects/Java/Android/HelloWorld/src/com/hello/world/Hell oWorld.class 1 warning no classfiles specified – Yash Feb 27 '13 at 15:59
  • this my proguard.bat @ECHO OFF REM Start-up script for ProGuard -- free class file shrinker, optimizer, REM obfuscator, and preverifier for Java bytecode. REM REM Note: when passing file names containing spaces to this script, REM you'll have to add escaped quotes around them, e.g. REM "\"C:/My Directory/My File.txt\"" IF EXIST "%PROGUARD_HOME%" GOTO home SET PROGUARD_HOME=.. :home "call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %1 %2 %3 %4 %5 %6 %7 %8 %9" – Yash Feb 27 '13 at 16:00
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/25239/discussion-between-imposter-and-yash-raj-dave) – Imposter Feb 27 '13 at 17:47