Error when referencing Sugar

Disclaimer : total noob, attempting to use Sugar

I have a working very basic Android app and attempting to use a Shared project. I have some Sugar code in the shared class which will be called from the Android project. As soon as I add a reference to Sugar.jar in Android, the app will no longer compile:

C:\Program Files (x86)\MSBuild\RemObjects Software\Oxygene\RemObjects.Oxygene.Cooper.Android.targets(96,5): error : Uncaught translation error: com.android.dex.util.ExceptionWithContext: 2
Uncaught translation error: com.android.dex.util.ExceptionWithContext: 2
2 errors; aborting

C:\Program Files (x86)\MSBuild\RemObjects Software\Oxygene\RemObjects.Oxygene.Cooper.Android.targets(96,5): error AP1: Error while running Android tool: dx.bat
Done building project "Droid.elements" -- FAILED.

I can’t add a reference in the Shared project as VS2015 reports ‘Unknown Project Type’ when I click on Add Reference.

Are there any basic Sugar/Shared project samples?

Thanks, logged as bugs://73898

Hrmm that shouldn’t happen. I’ll take a look at the exception. As for the references:

The way it works is you have a shared project with all files you want shared between multiple projects.

Then a set of real projects (1 for each platform you want) that all reference this shared project, which will make them link it in.

So this bug is already fixed in the beta. You can join the beta by joining here: https://secure.remobjects.com/portal/silver.aspx

you will have to recompile Sugar/Android to fix this error though.

bugs://73898 got closed with status fixed.

Hi ck -

Thanks for the beta invite, downloaded and installed, but still having issues. Running 8.3.92.1903 - created a new Android project, changed enough to get it to compile (archive name, namespace on MainActivity).

------ Rebuild All started: Project: SugarTest, Configuration: Debug ------
	JDKRoot:C:\Program Files (x86)\Java\jdk1.7.0_55
	JRERoot:C:\Program Files (x86)\Java\jre7
	SugarTest -> c:\users\jens\documents\visual studio 2015\Projects\SugarTest\SugarTest\bin\Debug\com.ratsey.SugarTest.jar
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Then added a reference to Sugar, recompile:

------ Rebuild All started: Project: SugarTest, Configuration: Debug ------
	JDKRoot:C:\Program Files (x86)\Java\jdk1.7.0_55
	JRERoot:C:\Program Files (x86)\Java\jre7
	SugarTest -> c:\users\jens\documents\visual studio 2015\Projects\SugarTest\SugarTest\bin\Debug\com.ratsey.SugarTest.jar
C:\Program Files (x86)\MSBuild\RemObjects Software\Oxygene\RemObjects.Oxygene.Cooper.Android.targets(100,5): error : UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.util.ExceptionWithContext: 2
	at com.android.dex.util.ExceptionWithContext.withContext(ExceptionWithContext.java:45)
	at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:369)
	at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:137)
	at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:93)
	at com.android.dx.command.dexer.Main.processClass(Main.java:729)
	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
	at com.android.dx.command.dexer.Main.access$300(Main.java:83)
	at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
	at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
	at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
	at com.android.dx.command.dexer.Main.processOne(Main.java:632)
	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
	at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
	at com.android.dx.command.dexer.Main.run(Main.java:246)
	at com.android.dx.command.dexer.Main.main(Main.java:215)
	at com.android.dx.command.Main.main(Main.java:106)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
	at com.android.dx.cf.code.OneLocalsArray.set(OneLocalsArray.java:121)
	at com.android.dx.cf.code.Frame.initializeWithParameters(Frame.java:164)
	at com.android.dx.cf.code.Ropper.setFirstFrame(Ropper.java:765)
	at com.android.dx.cf.code.Ropper.doit(Ropper.java:731)
	at com.android.dx.cf.code.Ropper.convert(Ropper.java:349)
	at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:280)
	... 15 more
...while processing Add (J)J
...while processing sugar/TimeSpan.class
1 error; aborting

C:\Program Files (x86)\MSBuild\RemObjects Software\Oxygene\RemObjects.Oxygene.Cooper.Android.targets(100,5): error AP1: Error while running Android tool: dx.bat
Done building project "SugarTest.elements" -- FAILED.

Build FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Did you recompile sugar itself?

Ah, no, I did not. I’ll need to read up on how to do that. Thanks!

Grab the source from https://github.com/remobjects/sugar/tree/stable , then just open the SLN.

Bingo! :smile:

@ck I’m facing this same issue, but compiling the stable sugar source failed.

/Users/eric/Desktop/sugar-stable/Sugar.sln (Build) ->
(Build target) ->
/Users/eric/Desktop/sugar-stable/Sugar/Sugar.Cooper.oxygene (default targets) ->
/Applications/Fire.app/Contents/Resources/XbuildTargets/RemObjects Software/Oxygene/RemObjects.Oxygene.Cooper.Common.targets (CoreCompile target) ->

        : error E289: The "future" helper type "com.remobjects.elements.system.FutureHelper" does not have the required "class method Execute<T>(aFuture: future T): future T" method

/Users/eric/Desktop/sugar-stable/Sugar.sln (Build) ->
(Build target) ->
/Users/eric/Desktop/sugar-stable/Sugar/Sugar.Cooper.Android.oxygene (default targets) ->
/Applications/Fire.app/Contents/Resources/XbuildTargets/RemObjects Software/Oxygene/RemObjects.Oxygene.Cooper.Common.targets (CoreCompile target) ->

        : error E289: The "future" helper type "com.remobjects.elements.system.FutureHelper" does not have the required "class method Execute<T>(aFuture: future T): future T" method

What is my recourse?

Are you using beta or release? If release make sure you use beta.

I’m fairly confident I am using release. How do I get the beta?

You can join the beta via https://secure.remobjects.com/portal/silver.

Yes, I saw that link higher up in this topic and followed it and joined. I, however, don’t have any beta downloads available:

Strange. What’s your username? If it’s ericf, then i see no beta license in our account. Are you sure you went thru the application for the beta? howe you go to https://secure.remobjects.com/portal/silver again, does it say you are eon the beta, or not? (if yes, maybe you’re using two different accounts?)