wener wener - 10 months ago 77
Android Question

How to call Smali in Java

I want to use Java to smali plugin, but I have to compile Java to class first, this is impossible for project like this

enter image description here



enter image description here

Javac don't understand this, but I just want to compile this java code to class, so I can convert it to smali.

This project is decode by
apktool d my.apk
, I try to inject some code in it, writing smali is harder than java.But I alread done the Inject part,just want to know how to compile java to class.

$ adb logcat -s "Injected"
--------- beginning of main
--------- beginning of system
07-10 19:32:24.013 7689 7689 W Injected: Started
07-10 19:32:24.015 7689 7689 W Injected: Init


The original title is
In Jetbrain can I just compile Java to class and ignore all error?
,but want I want is
How to call Smali in Java
, so I rename the title.



Java requires the definitions of the classes/methods/fields being used in a java program to be able to compile it. Without this information, it doesn't have enough information to be able to produce a class file.

For example, let's say you're trying to compile this program:

public class Main {
    public static int main(String[] args) {
        Blort blort = new Blort();
        return 0;

The exact bytecode that is produced depends on the definition of the Blort.blarg method.

If blarg is defined like this:

public class Blort {
    public void blarg(String blah) {

Then the method call to blarg would be complied to:

invoke-virtual {v0, v1}, LBlort;->blarg(Ljava/lang/String;)V

However, if the blarg method is defined differently:

public class Blort {
    public void blarg(CharSequence blah) {

Then the method call would be compiled to:

invoke-virtual {v0, v1}, LBlort;->blarg(Ljava/lang/CharSequence;)V

These two method calls refer to different methods and are not interchangable. And if the compiler doesn't know at least the declaration of the blarg method, then it can't know the correct method signature to use.

And that's just 1 small example of why the compiler needs to know the definitions of all classes that are being referred to in a java program. There are many other reasons.