It is currently 11 Nov 2019, 20:32
   
Text Size

Building forge android apk in Eclipse or IntelliJ

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, friarsol, Blacksmith, KrazyTheFox, Agetian, CCGHQ Admins

Building forge android apk in Eclipse or IntelliJ

Postby austinio7116 » 08 Apr 2017, 12:18

Hi,

I've been trying for the last day or so to get the android version running from the latest svn checkout. I seem to be at the same point in either IntelliJ or Eclipse where there is a java 7/8 conflict that I cannot resolve. Either I compile and build in Java 8 and the proguard step says that it does not support Java 8, or I compile and build in Java 7 and proguard runs fine, but then I get the following error converting to DEX:

[INFO] --- android-maven-plugin:4.2.1:dex (default-dex) @ forge-gui-android ---
[INFO] Convert classes to Dex : C:\Users\maustin\workspace\forge\forge-gui-android\target\classes.dex
[INFO] java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0

Does anyone have any suggestions or have you experienced these issues?

Thanks

Mark
User avatar
austinio7116
 
Posts: 421
Joined: 10 Mar 2017, 11:59
Has thanked: 47 times
Been thanked: 149 times

Re: Building forge android apk in Eclipse or IntelliJ

Postby austinio7116 » 08 Apr 2017, 13:01

Just for completeness here is the Java 8 error:

[INFO] --- android-maven-plugin:4.2.1:proguard (default-proguard) @ forge-gui-android ---
[INFO] Proguarding output
[INFO] java.io.IOException: Can't read [C:\Program Files\Java\jdk1.8.0_91\jre\lib\rt.jar] (Can't process class [com/oracle/net/Sdp$1.class] (Unsupported class version number [52.0] (maximum 51.0, Java 1.7)))
[INFO] at proguard.InputReader.readInput(InputReader.java:230)
[INFO] at proguard.InputReader.readInput(InputReader.java:200)
[INFO] at proguard.InputReader.readInput(InputReader.java:178)
[INFO] at proguard.InputReader.execute(InputReader.java:100)
[INFO] at proguard.ProGuard.readInput(ProGuard.java:196)
[INFO] at proguard.ProGuard.execute(ProGuard.java:78)
[INFO] at proguard.ProGuard.main(ProGuard.java:492)
[INFO] Caused by: java.io.IOException: Can't process class [com/oracle/net/Sdp$1.class] (Unsupported class version number [52.0] (maximum 51.0, Java 1.7))
[INFO] at proguard.io.ClassReader.read(ClassReader.java:112)
User avatar
austinio7116
 
Posts: 421
Joined: 10 Mar 2017, 11:59
Has thanked: 47 times
Been thanked: 149 times

Re: Building forge android apk in Eclipse or IntelliJ

Postby austinio7116 » 10 Apr 2017, 13:50

I'm fairly sure it relates to trying to run on Android SDK version 25 rather than 23 - if I can work out how to force it to revert to version 23 I may make some progress.
User avatar
austinio7116
 
Posts: 421
Joined: 10 Mar 2017, 11:59
Has thanked: 47 times
Been thanked: 149 times

Re: Building forge android apk in Eclipse or IntelliJ

Postby austinio7116 » 10 Apr 2017, 14:39

Yes - that was it - by removing the android API revision 25 build tools in Android Studio and installing revision 23 instead I finally got the apk built and running in the launcher.

Hopefully this will help others that download the latest of everything and run into these issues. So finally I have everything working using these tools:

IntelliJ IDEA 15.06 (newer versions do not support android SDK running with JDK 1.7 as far as I could see)
JDK 1.7_80 ( Java 1.8 is not compatible with the Proguard tools used to optimize/obfuscate the java libraries for the APK)
Android SDK API 23 rev 3 (24 and later are Java 8 only)
User avatar
austinio7116
 
Posts: 421
Joined: 10 Mar 2017, 11:59
Has thanked: 47 times
Been thanked: 149 times

Re: Building forge android apk in Eclipse or IntelliJ

Postby Agetian » 26 Apr 2017, 05:39

Hmm, this actually brings an important point going forward with the development of Forge for Android: how do we handle things in the future? I'm pretty sure that eventually we'll want to upgrade the Forge code base to Java 8 (especially as Java 9 is released in the nearest future and the older versions of Java get deprecated and unmaintained). I know that both XMage and Magarena are already targeting Java 8. We're not there yet (and we can happily keep using and targeting Java 7 for the time being), but we'll get to the point when this will become a more pressing issue as the development continues forward.

Is it a straightforward enough procedure to upgrade Android SDK to a newer version? Is there an alternative to Proguard that can be used? (I'm pretty sure that one of the reasons we're using it is because it massively reduces the number of methods and classes in the resulting file, pushing it below the limits of the Android platform - without it I think the compilation fails with an error about too many methods and/or classes or something along those lines).

Also, what would upgrading the Android SDK to a newer build (e.g. 25) mean for the Android version support? Would it require a version of Android newer than 4.x which were are currently targeting as the bare minimum?

Sadly, I'm not very well-versed with these things, and Dan is no longer around (at least for the time being). Do you have any ideas about all this?

- Agetian
Agetian
Programmer
 
Posts: 3358
Joined: 14 Mar 2011, 05:58
Has thanked: 644 times
Been thanked: 499 times

Re: Building forge android apk in Eclipse or IntelliJ

Postby austinio7116 » 26 Apr 2017, 08:44

I'm no expert - I've created a few android apps in the past but pretty basic stuff and I've never used ProGuard. When I was looking into this before though I found that the new beta version of ProGuard 5 supports java 8 - so as long as we work out how to integrate the new ProGuard into the config that may well be the solution when we are ready to move to Java 8. Happy to try it out when the time comes. Upgrading to the newer Android API versions should then be straightforward I think.
User avatar
austinio7116
 
Posts: 421
Joined: 10 Mar 2017, 11:59
Has thanked: 47 times
Been thanked: 149 times

Re: Building forge android apk in Eclipse or IntelliJ

Postby Agetian » 26 Apr 2017, 17:41

That's good! thanks for the info! :)

- Agetian
Agetian
Programmer
 
Posts: 3358
Joined: 14 Mar 2011, 05:58
Has thanked: 644 times
Been thanked: 499 times

Re: Building forge android apk in Eclipse or IntelliJ

Postby austinio7116 » 14 May 2017, 20:27

Just to confirm, upgrading to proguard 5 solves the problem. I am now building my apk files with Java 8 and Android API 25 and all is working well. In fact the apk is 10% smaller.
User avatar
austinio7116
 
Posts: 421
Joined: 10 Mar 2017, 11:59
Has thanked: 47 times
Been thanked: 149 times

Re: Building forge android apk in Eclipse or IntelliJ

Postby Agetian » 16 May 2017, 14:39

austinio7116 wrote:Just to confirm, upgrading to proguard 5 solves the problem. I am now building my apk files with Java 8 and Android API 25 and all is working well. In fact the apk is 10% smaller.
Which Android version would this configuration be targeting? Is it still compatible with the 4.x series or does it need a newer device with Android 5/6/etc.?

- Agetian
Agetian
Programmer
 
Posts: 3358
Joined: 14 Mar 2011, 05:58
Has thanked: 644 times
Been thanked: 499 times

Re: Building forge android apk in Eclipse or IntelliJ

Postby austinio7116 » 16 May 2017, 14:44

I'll run some tests, I did not have to change the target API, but there may be a java 8 issue on the older APIs
User avatar
austinio7116
 
Posts: 421
Joined: 10 Mar 2017, 11:59
Has thanked: 47 times
Been thanked: 149 times

Re: Building forge android apk in Eclipse or IntelliJ

Postby Agetian » 17 May 2017, 04:46

Ok, please let me know what you find out! :)

- Agetian
Agetian
Programmer
 
Posts: 3358
Joined: 14 Mar 2011, 05:58
Has thanked: 644 times
Been thanked: 499 times

Re: Building forge android apk in Eclipse or IntelliJ

Postby austinio7116 » 18 May 2017, 18:46

I was able to install the APK that I built with JDK 8 on my old Android 4.2.2 phone and it ran fine. The next thing to test I suppose is whether adding any Java 8 specific features to the code will cause any trouble.
User avatar
austinio7116
 
Posts: 421
Joined: 10 Mar 2017, 11:59
Has thanked: 47 times
Been thanked: 149 times

Re: Building forge android apk in Eclipse or IntelliJ

Postby Agetian » 19 May 2017, 07:33

So far so good! :) Glad to hear it!

- Agetian
Agetian
Programmer
 
Posts: 3358
Joined: 14 Mar 2011, 05:58
Has thanked: 644 times
Been thanked: 499 times

Re: Building forge android apk in Eclipse or IntelliJ

Postby austinio7116 » 22 May 2017, 20:26

I added a Java 8 Iterator forEach with a lambda expression to see what happens when we actually use the new Java 8 features. The proguard config needed some persuading to ignore the new syntax, but then it compiled fine and the apk ran on my Android 4.2.2 phone. So we are looking good if that is sufficient back-support. It may be that Android only supports some parts of the new features - but even if that was the case it may still not be enough to stop us from moving to Java 8 anyway.
User avatar
austinio7116
 
Posts: 421
Joined: 10 Mar 2017, 11:59
Has thanked: 47 times
Been thanked: 149 times

Re: Building forge android apk in Eclipse or IntelliJ

Postby Agetian » 23 May 2017, 03:48

Sounds good to me, Austinio! :) Also, I have lots of old and new Android devices to figure out if things work fine or not as we go along.

P.S. Personally I am all for Java 8 support. Java 7 is quickly becoming dated and soon after Java 9 is released I think it'll become unmaintained/unsupported... :/ Plus, Java 8 offers some nice new syntax and stuff.

- Agetian
Agetian
Programmer
 
Posts: 3358
Joined: 14 Mar 2011, 05:58
Has thanked: 644 times
Been thanked: 499 times


Return to Developer's Corner

Who is online

Users browsing this forum: Bing [Bot] and 9 guests


Who is online

In total there are 10 users online :: 1 registered, 0 hidden and 9 guests (based on users active over the past 10 minutes)
Most users ever online was 427 on 11 Nov 2019, 13:00

Users browsing this forum: Bing [Bot] and 9 guests

Login Form