-
Notifications
You must be signed in to change notification settings - Fork 394
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
Various complications with Java 13 #792
Comments
Just wondering, do you happen to face with the following log entries while attempting to use
? |
@lyubomyr-shaydariv It's been a while since I opened this issue and in the mean time I've worked on some other things, but if I remember correctly I also encountered this message. I don't know, but I guess that the AOSP had modified that binary in the past. (But I haven't had a closer look on it, so I cannot guarantee that this is true.) |
@firefligher thank you for the reply.
This assumption makes sense. I submitted another issue (#793) asking the project members to clarify that point, and I hope they would put comments for both issues. |
I am not sure if Java 13 is supported by the Anddroid SDK but it certainly has never been tested with the Maven plugin. I would strongly suggest to use Java 11. Beyond that I am not sure if it works with a current Android SDK and also do not have time to check that out. |
Just a quick note on this: The d8.bat (located at java -cp d8.jar com.android.tools.r8.D8 |
A somewhat less intrusive interim solution would be
(in your android project).
Running the plugin was tested with JDKs 11 to 15; max source/target was only 9, as nothing higher is supported by the available d8 in platform level 28 or dex in platform level 30. d8 in platform level 29/30 should be able to handle newer java classes (tested: up to Java 11). Edit: On a side note, I tried upgrading the internal android libraries from 2.3.0 (builder) / 25.3.0 (tools) and gave up at 3.5.4 (builder) / 26.5.4 (tools) as some integration tests of the plugin were still complaining about missing tools.jar when running with later JDKs and the API changes in the libraries (Google moved stuff over to Kotlin, for example, and taylored the used APIs more and more to IntelliJ) became just too much. I guess to really bring the plugin up to speed one would have to have a look at the Gradle plugin and basically rewrite large parts of. |
Good evening/night (at least here in Germany 😁),
after a very long debugging session (started around 11:00 PM), I got your Maven plugin finally working together with Java 13 and succeeded building and running a simple app (empty Activity class). Since I thought that my approach may be useful for somebody else, I decided to document it here.
Disclaimer: Heavy patching of JAR files in your local Maven repository is required.
Also note: I used version 4.6.0 of this plugin and built an app with minimumSdkVersion = 26.
Fixing dex
I don't know, if this was the very first problem that I had, but it was one of the first: I needed to pass additional command-line arguments to dex as otherwise it would fail with the same issues as documented here. Aftwards the build section of my pom looked like this:
Adding the XML serialization APIs as dependency
The next problem that occurred is pretty well-known to all developers that migrated from Java 8 to Java 9+: Oracle somehow modularized their platform, this broke a lot of dependencies. In this case, those were the XML serialzation APIs (as already documented here).
The simplest, but also quick-and-dirtiest, solution was to manually patch the pom.xml of your plugin inside my local Maven repository. (Of course, this is only possible after the plugin has been downloaded by Maven.)
In my case, I patched the file at
HOME_DIR\.m2\repository\com\simpligility\maven\plugins\android-maven-plugin\4.6.0\android-maven-plugin-4.6.0.pom
and the pom.xml that is stored inside theandroid-maven-plugin-4.6.0.jar
(same directory). Both times I added the following lines to the dependencies-section:Afterwards, I recomputed the SHA1 checksums of both modified files and stored them in the corresponding .sha1 file (again, in the same directory).
Patching sdklib
After the last step, the next Maven execution resulted in a
ClassNotFoundException
that was not that easy to fix: The android-maven-plugin depends on the sdklib that is part of the AOSP. The plugin depends on the com.android.sdklib.internal.build.SignedJarBuilder class, which importssun.*
classes. Those classes are missing in the newer Java versions as already mentioned here. Unfortunately, I was not able to provide those sun-classes (pun not intended 😄) in an alternative way, because the Java compiler did not let me compile classes of the sun-package.Thus, I decided to patch my local copy of sdklib and created a modified version of the
SignedJarBuilder.java
(diff only):(NOTE: For some reason I used this file as base. (Fastest compatible Google result))
After compiling this class with javac, I patched the
HOME_DIR\.m2\repository\com\android\tools\sdklib\25.3.0\sdklib-25.3.0.jar
in my local Maven repository. Again, this also required replacing the existing SHA1 hash.Manual signature
This time, Maven completed my build successfully. However installing the app on an Android phone did not work because Android noticed the missing signature (the previous file patch removed the signature logic). So, i tried to perform this step manually by entering these shell commands:
keytool -genkey -keyalg RSA -alias CERT -keystore myKeystore -validity 360 jarsigner -keystore myKeystore -verbose target\my.apk CERT
And it worked.
Additional notes:
I attempted to use
d8
instead ofdex
, but the following configuration did not work:The Maven build process always ended with an exception because some command-line argument returned with a non-zero status code. I guess, there's something wrong with the command, but I'm too tired for further investigations...
Maybe I'm going to write a real patch for your project and create a pull request, if I have the time.
Cheers. (It took about 1h to collect and write down all the information 😄)
The text was updated successfully, but these errors were encountered: