javaandroidsmali

Convert .java to .smali


As mentioned in the title I am trying to convert a java file into a .smali file, so these are the commands I am trying to launch from Android studio terminal:

javac HelloWorld.java

dx --dex --output=classes.dex HelloWorld.class

baksmali classes.dex

But when I launch the second command I get this error:

bash: dx : command not found

Also, I've tried to compile my file directly to smali, by going to: Build/compile to smali on Android studio and this is the error I get:

Error:Internal error: (java.lang.ClassNotFoundException) com.google.wireless.android.sdk.stats.IntellijIndexingStats$Index java.lang.ClassNotFoundException: com.google.wireless.android.sdk.stats.IntellijIndexingStats$Index> at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at com.intellij.util.indexing.counters.IndexCounters.(IndexCounters.java:34) at com.intellij.util.indexing.impl.MapReduceIndex.(MapReduceIndex.java:86) at org.jetbrains.jps.backwardRefs.index.CompilerReferenceIndex$CompilerMapReduceIndex.(CompilerReferenceIndex.java:214) at org.jetbrains.jps.backwardRefs.index.CompilerReferenceIndex.(CompilerReferenceIndex.java:73) at org.jetbrains.jps.backwardRefs.JavaCompilerBackwardReferenceIndex.(JavaCompilerBackwardReferenceIndex.java:12) at org.jetbrains.jps.backwardRefs.JavaBackwardReferenceIndexWriter.initialize(JavaBackwardReferenceIndexWriter.java:74) at org.jetbrains.jps.backwardRefs.JavaBackwardReferenceIndexBuilder.buildStarted(JavaBackwardReferenceIndexBuilder.java:40) at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:358) at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:178) at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:138) at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:302) at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:135) at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:229) at org.jetbrains.jps.service.impl.SharedThreadPoolImpl.lambda$executeOnPooledThread$0(SharedThreadPoolImpl.java:42) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

Any ideas on how I can make this work? or any other tool to convert .java to .smali?


Solution

  • This worked for me:

    I just had to find the command dx which is located in ~/Android/Sdk/build-tools/$version on Linux, but first make sure android-sdk is installed (usually located in ~/android/sdk on Linux) then run dx using

    ./dx --dex --output=classes.dex path_to_source_file.class if you are in the same directory as dx