It is currently 24 Apr 2024, 17:49
   
Text Size

Compiling Forge for Android in Intellij

Post MTG Forge Related Programming Questions Here

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

Compiling Forge for Android in Intellij

Postby lanshark079 » 07 Mar 2016, 22:51

Hello all! After tinkering with the instructions and trying different methods, I was able to set up and build the Windows/Linux version of Forge using IntelliJ as the dev environment. I attempted to build a debug version of the Android version of Forge so that I could work out a bug that only occurs on my specific tablet (Dell Venue 7040/Android 5.1). I added the run configuration using "Android Application" as the base, with the following tweaks:

- Module > forge-gui-android
- Target Device > USB device (for my tablet)

Here's what IntelliJ reported:

Compile Errors | Open
Error:Android Dex: [forge-gui-android] Unable to execute DX
Error:Android Dex: [forge-gui-android] com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
Error:Android Dex: [forge-gui-android] at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:484)
Error:Android Dex: [forge-gui-android] at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:261)
Error:Android Dex: [forge-gui-android] at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:473)
Error:Android Dex: [forge-gui-android] at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:161)
Error:Android Dex: [forge-gui-android] at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
Error:Android Dex: [forge-gui-android] at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
Error:Android Dex: [forge-gui-android] at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
Error:Android Dex: [forge-gui-android] at com.android.dx.command.dexer.Main.run(Main.java:277)
Error:Android Dex: [forge-gui-android] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Error:Android Dex: [forge-gui-android] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Error:Android Dex: [forge-gui-android] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Error:Android Dex: [forge-gui-android] at java.lang.reflect.Method.invoke(Method.java:497)
Error:Android Dex: [forge-gui-android] at org.jetbrains.android.compiler.tools.AndroidDxRunner.runDex(AndroidDxRunner.java:188)
Error:Android Dex: [forge-gui-android] at org.jetbrains.android.compiler.tools.AndroidDxRunner.main(AndroidDxRunner.java:336)


For reference, here's my versions:

Forge: 1.5.49 (Latest from SDK)
IntelliJ: 15.0.4
IntelliJ Android SDK: Maven Android API 20 Platform
JRE/JDK: 1.8.0_73
Maven: 3.3.9
Windows 10

Any advice for properly setting up my IntelliJ environment would be most appreciated. This error is driving me nuts, and debugging this code might be the only way to make Forge work on my tablet once again. Thanks in advance!

- Paul
lanshark079
 
Posts: 9
Joined: 29 May 2015, 13:26
Has thanked: 0 time
Been thanked: 0 time

Re: Compiling Forge for Android in Intellij

Postby lanshark079 » 09 Mar 2016, 22:02

Okay, so after getting a few moments to dig in further, I noticed that this project seems to use Proguard to deal with the Dex limit issues. I enabled Proguard in the project in the Project Structure > forge-gui-android > Android settings. I added the proguard.cfg to the config file paths, and had to add two warning suppression commands to that config:

-dontwarn org.seamless.swing.**
-dontwarn java.lang.management.**

Once this was done, I was able to build the APK, push it to my device, and replicate the error! Granted, I have a much longer road ahead trying to figure out how Forge internals even work to understand why "No element named Battlefield, Command in enum zone" is occurring, but at least now I can do more than look at that error and be sad. Hopefully, this post might be able to help someone else with the same predicament. Can't wait to figure this out!

- Paul
lanshark079
 
Posts: 9
Joined: 29 May 2015, 13:26
Has thanked: 0 time
Been thanked: 0 time

Re: Compiling Forge for Android in Intellij

Postby friarsol » 10 Mar 2016, 00:46

lanshark079 wrote:Once this was done, I was able to build the APK, push it to my device, and replicate the error! Granted, I have a much longer road ahead trying to figure out how Forge internals even work to understand why "No element named Battlefield, Command in enum zone" is occurring, but at least now I can do more than look at that error and be sad. Hopefully, this post might be able to help someone else with the same predicament. Can't wait to figure this out!
Sounds like a script error. Trying to cast multiple zones into a single zone. But I don't see any occurrences of that string combination in our scripts. Do you have any custom cards that you are using?
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Compiling Forge for Android in Intellij

Postby lanshark079 » 10 Mar 2016, 18:39

friarsol wrote:
lanshark079 wrote:Once this was done, I was able to build the APK, push it to my device, and replicate the error! Granted, I have a much longer road ahead trying to figure out how Forge internals even work to understand why "No element named Battlefield, Command in enum zone" is occurring, but at least now I can do more than look at that error and be sad. Hopefully, this post might be able to help someone else with the same predicament. Can't wait to figure this out!
Sounds like a script error. Trying to cast multiple zones into a single zone. But I don't see any occurrences of that string combination in our scripts. Do you have any custom cards that you are using?
Nothing custom - just the stock Forge application. I was able to figure out why the error occurred, though not exactly why it's happening. In the method "listValueOf" inside of ZoneType enum, it splits up a string of the enums provided (Battlefield,Command) into two separate strings using the comma. For whatever reason (and this makes no sense), sometimes the split doesn't work and when it attempts to take the result through "smartValueOf" method, it passes the string "Battlefield,Command", which of course is not found in the enum. When looking at the source string that is the target of the split, there doesn't seem to be any variance between when the split works and when it does not. I'm puzzled, though I will admit my Java knowledge isn't as strong as I'd like. I wrote this garbage code which fixes the issue, and lets the game continue on:

new listValueOf | Open
public static List<ZoneType> listValueOf(final String values) {
//System.out.println("Zone Contents = " + values);
final List<ZoneType> result = new ArrayList<ZoneType>();
for (final String s : values.split("[, ]+")) {
//System.out.println("[" + s + "]");
if (s == "Battlefield,Command") {
//System.out.println("Caught issue with split - fixing...");
ZoneType ztx = ZoneType.smartValueOf("Battlefield");
if (ztx != null) {
result.add(ztx);
}
ZoneType ztq = ZoneType.smartValueOf("Command");
if(ztq != null) {
result.add(ztq);
}
} else {
ZoneType zt = ZoneType.smartValueOf(s);
if (zt != null) {
result.add(zt);
}
}
}

//System.out.println("Result Output = " + result);

return result;
}


In any case, I wasn't able to find anyone else who reported this issue. I'm using a Dell Venue 7040 (which has a small user base), so I'm naturally suspicious that it is somehow causing problems. Does it make sense? No. But there it is. Odd little issue, but at least the workaround is easy (though not for public distribution). Glad it was easy enough to fix, and I can at least compile updated versions as they come along. Which is good, since half the reason I got this new tablet was for this game.

Thanks for looking it over!
- Paul
lanshark079
 
Posts: 9
Joined: 29 May 2015, 13:26
Has thanked: 0 time
Been thanked: 0 time

Re: Compiling Forge for Android in Intellij

Postby drdev » 11 Mar 2016, 01:22

Is there a reason you cannot use Eclipse? That's what I use and it compiles fine for that.
drdev
Programmer
 
Posts: 1958
Joined: 27 Jul 2013, 02:07
Has thanked: 189 times
Been thanked: 565 times

Re: Compiling Forge for Android in Intellij

Postby KrazyTheFox » 11 Mar 2016, 05:15

This is the command I run to build the .apk in IntelliJ. It should take care of all the proguard stuff, but it does require a keystore.

Maven Only:
Code: Select all
mvn -U -B clean install -P android-release-build,android-release-sign -Dsign.keystore=<keystore_location> -Dsign.alias=Forge -Dsign.storepass=<keystore_password> -Dsign.keypass=<key_password> -Dbuild.max.memory=-Xmx1024m



IntelliJ Build Config (Maven):
Command Line:
Code: Select all
-U -B clean install -Dsign.keystore=<keystore_location> -Dsign.alias=Forge -Dsign.storepass=<keystore_password> -Dsign.keypass=<key_password> -Dbuild.max.memory=-Xmx1024m
Profiles:
Code: Select all
android-release-build android-release-sign
User avatar
KrazyTheFox
Programmer
 
Posts: 725
Joined: 18 Mar 2014, 23:51
Has thanked: 66 times
Been thanked: 226 times

Re: Compiling Forge for Android in Intellij

Postby lanshark079 » 11 Mar 2016, 17:15

I'll definitely give those build goals a try, Krazy. The app now compiles and works, and with those goals I can make a more efficient APK. I noticed the version I made just using "Make Project" runs a bit slow, which I'm sure has to do with perhaps additional debug inputs that are added to the APK when built without those parameters. Hopefully, the APK resulting from those goals will be more streamlined.

drdev - I originally started trying to set up Eclipse. Using the "How to Get Started Developing Forge" guide, I attempted to set up and follow those instructions. However, some of the instructions were no longer valid or slightly different due to the passage of time (i.e. m2e-subclipse plugin), so I most likely failed when trying to interpret how to perform some of the installations using the updated tools. I used IntelliJ because it skipped the plugins and I was able to get much farther along the compilation details than I could with Eclipse. I'm sure there's benefits to using Eclipse, but IntelliJ seems pretty straight forward and works for my immediate needs, so I was happy to work with that. Perhaps, if I ever do any further development (beyond some minor personal bug fixes), I'll give Eclipse another shot.

Since I'll be building my own APKs for the immediate future until I can confirm this bug with my tablet and .split is fixed, I'll always be grateful for any build suggestions that can help speed this process or build a better APK. Thanks for everyone's input and suggestions - glad this is such a helpful community.

- Paul
lanshark079
 
Posts: 9
Joined: 29 May 2015, 13:26
Has thanked: 0 time
Been thanked: 0 time


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 35 guests


Who is online

In total there are 35 users online :: 0 registered, 0 hidden and 35 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 35 guests

Login Form