-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile to smali fails on IntelliJ 2021.1 #24
Comments
I resolved the issue on my own, I have updated to Java15 since this is a pure java application except that single class |
I was playing around with different java versions and I noticed that Java11 is working as well under certain circumstances. |
@auermich93 thanks for the follow-up (and the ping). I can probably take a closer look tomorrow. |
Unfortunately, the issue is more severe than I thought. It was a false conclusion that Java11 is working out-of-the-box within IntelliJ. I have created a new class containing a single field and a single method that prints something via |
I was able to reproduce your findings and you're right with the cached result that is being used by java2smali. The plugin operates in 3 sequential steps:
Step 1 fails, if IDEA is unable to compile the project / module. Step 3 fails whenever there's no dex file available from step 2 (this is the error from your first message). Unfortunately step 2 seems to fail silently, so baksmali may run on a previously emitted .dex file instead of throwing an error. First, I'm going to fix the silent failing of step 2. Next I'll take a look what I can do to better support new language features. Are you actually running java2smali's smali code on Android devices? I expect it to be rather hard to produce executable code in all scenarios. |
Nice that you can confirm my results. Yes, the code is actually running on Android devices. My java application is instrumenting an APK. In particular, I inject a custom tracer class, which is nothing else than a broadcast receiver. I am using dexlib2 under the hood, which allows me to read directly from smali files and emits dalvik bytecode. |
This will prevent dx from failing with SimException messages and allows baksmali to use a wider set of opcodes
@auermich93 The first part is done, so the plugin no longer falls back to cached dex files. I've also played a bit with improved language support and there might be a small but powerful fix for this: Explicitly setting an API level. dx also asks for this but before #25 this information got lost because of the silent failures. I introduced the API level change on another branch, see here. It would be amazing if you could try this out before I publish a new release. Here's a fresh build of that branch java2smali-2.1.0-SNAPSHOT.zip, of course you could also build it from the sources. Thanks again for the detailed report and investigation. |
Thanks for investing your time into this issue. I tested the following within IntelliJ and Java15 as compiler: I created dummy methods and included in each a specific language feature. In particular, I tested Java8 (Optional, Stream), Java11 (var keyword, isBlank()), Java12 (Collectors.teeing()), Java13 (new switch case) and Java15 (new instance of check). This corresponds to the smali code: This @ollide: Regarding determining the API version, you could use Btw, I didn't test the silent failure fix. |
I tested the same thing on API 30. It's not anymore the verification error, but a warning followed by a NoSuchMethodError:
And I have to correct above statements about Java8. I included logs and noticed that only the first part was executed successfully and the remaining instructions fail. In particular, the Stream-API stuff of my test method didn't work:
@ollide: Are you checking whether |
I made some progress already. The basis is the following Test.java file:
You have to compile this file with Java11 (Java15 is not recognized by
The output is as follows:
If you drop the I tried the same thing with the
However, the output is as follows:
As we can observe, the
|
@auermich93 thanks again for your thorough tests. I'll try to comment on all relevant aspects, let me know if I miss anything.
This is good to know, but won't help here as java2smali creates the dex file itself (and thereby dictates the opcodes version) and later reverses the dex file using the same API version.
I'm using a self-contained version of
Language SupportNow let's switch to the most important part: How can we support all new language features or more precisely, all language features that modern Android versions support? Preface: I'm by no means an expert on this topic, so there will be some inaccuracies or even misinformation. In the old days, Android was very slow with the support of new Java language features and new features were only introduced with new Android versions and without any backward compatibility. This comes down to the opcode versions of the dex bytecode (produced by Desugaring just means that the syntactic sugar of new language features is replaced with standard expressions that are functionally identical. So if we introduce When I've first looked at
But in your tests you were able to use Java 8 language features and run them on a device without specifying it?
If we can run |
@ollide: The attached screenshot should prove that The latest version of
However, the latest version of
Android-Studio says that |
@auermich93 D8 desugaring indeed seems to work without any I've introduced D8 on the feature branch here: 698c3f7. When running the plugin on your Test class, the plugin will emit 3 smali files and none of them contains any
I think it will be necessary to test the D8 build a little more before I can remove |
@ollide If I run One question is what's the dex version of the generated classes.dex file. Independent, whether I use the Java11 or Java15 compiled But still one urgent question for me is why As shown in my previous post, dx can't handle Java15. I even picked the
So there is some magic involved in the background of |
There seems to be some issue related to IntelliJ 2021.1 and the java2smali plugin:
The issue was not present on earlier versions of IntelliJ.
The text was updated successfully, but these errors were encountered: