How to enable multidex on Android builds?

That seems to have done the trick for me.  

Although it wasn’t just the Corona.jar file I had to copy, I also had to copy:

All contents of armeabi-v7a

JNLua.jar

network.jar

res>raw folder

and also comment out this line in project.properties file:

android.library.reference.1=${CoronaEnterpriseDir}/Corona/android/lib/Corona

It seems to have built and ran correctly, but I’ve only tested it a little bit since I got it working so can’t say for sure.

Can someone from Corona comment on whether making these changes is likely to break anything that I may have overlooked?

Sorry, I thought the only jar needed to resolve your issue the Corona.jar, I too, indeed, had to go through the steps you described.

We have been releasing games this way for almost a year and everything is fine.

What you have to remember is to update the Corona libraries every time you update Corona Enterprise.

Ok that’s great, thanks for letting me know.  

@krystian6  

Have you integrated Facebook login into your app? As soon as I tested FB my app crashed, this was to be expected as my project.properties still had this in it:

android.library.reference.1=../../../../mainrepo/enterprise/Plugins/sdk-facebook/android

which is where I had the facebook project stored.  

I’ve tried taking the libs + res files from the facebook proj and moving them into my project as I did with the Corona files but I then had this error:

06-18 12:03:34.847: I/dalvikvm(24494): Could not find method com.facebook.Session.getActiveSession, referenced from method facebook.FacebookController.facebookLogin 06-18 12:03:34.847: W/dalvikvm(24494): VFY: unable to resolve static method 17239: Lcom/facebook/Session;.getActiveSession ()Lcom/facebook/Session; 06-18 12:03:34.847: D/dalvikvm(24494): VFY: replacing opcode 0x71 at 0x0015 06-18 12:03:34.847: I/dalvikvm(24494): Could not find method com.facebook.Session.getActiveSession, referenced from method facebook.FacebookController.facebookLogout 06-18 12:03:34.847: W/dalvikvm(24494): VFY: unable to resolve static method 17239: Lcom/facebook/Session;.getActiveSession ()Lcom/facebook/Session; 06-18 12:03:34.847: D/dalvikvm(24494): VFY: replacing opcode 0x71 at 0x0000 06-18 12:03:34.847: I/dalvikvm(24494): Could not find method com.facebook.Session.getActiveSession, referenced from method facebook.FacebookController.facebookRequest 06-18 12:03:34.847: W/dalvikvm(24494): VFY: unable to resolve static method 17239: Lcom/facebook/Session;.getActiveSession ()Lcom/facebook/Session; 06-18 12:03:34.847: D/dalvikvm(24494): VFY: replacing opcode 0x71 at 0x0007 06-18 12:03:34.847: I/dalvikvm(24494): Could not find method com.facebook.AppEventsLogger.activateApp, referenced from method facebook.FacebookController.publishInstall 06-18 12:03:34.847: W/dalvikvm(24494): VFY: unable to resolve static method 17217: Lcom/facebook/AppEventsLogger;.activateApp (Landroid/content/Context;Ljava/lang/String;)V 06-18 12:03:34.847: D/dalvikvm(24494): VFY: replacing opcode 0x71 at 0x0004 06-18 12:03:34.847: D/dalvikvm(24494): DexOpt: unable to opt direct call 0x434a at 0x27 in Lfacebook/FacebookController;.facebookLogin 06-18 12:03:34.847: D/dalvikvm(24494): DexOpt: unable to opt direct call 0x4351 at 0x37 in Lfacebook/FacebookController;.facebookLogin 06-18 12:03:34.857: I/dalvikvm(24494): DexOpt: unable to optimize static field ref 0x1857 at 0x3a in Lfacebook/FacebookController;.facebookLogin 06-18 12:03:34.857: I/dalvikvm(24494): Failed resolving Lfacebook/FacebookController$FacebookEventHandler; interface 2555 'Lcom/facebook/Session$StatusCallback;' 06-18 12:03:34.857: W/dalvikvm(24494): Link of class 'Lfacebook/FacebookController$FacebookEventHandler;' failed 06-18 12:03:34.857: D/dalvikvm(24494): DexOpt: unable to opt direct call 0xdfa5 at 0x4d in Lfacebook/FacebookController;.facebookLogin 06-18 12:03:34.857: I/dalvikvm(24494): Failed resolving Lfacebook/FacebookController$FacebookEventHandler; interface 2555 'Lcom/facebook/Session$StatusCallback;' 06-18 12:03:34.857: W/dalvikvm(24494): Link of class 'Lfacebook/FacebookController$FacebookEventHandler;' failed 06-18 12:03:34.857: D/dalvikvm(24494): DexOpt: unable to opt direct call 0xdfa5 at 0x72 in Lfacebook/FacebookController;.facebookLogin 06-18 12:03:34.857: D/dalvikvm(24494): DexOpt: unable to opt direct call 0x4345 at 0x15 in Lfacebook/FacebookController;.facebookRequest 06-18 12:03:34.857: I/dalvikvm(24494): Failed resolving Lfacebook/FacebookController$FacebookRequestCallbackListener; interface 2548 'Lcom/facebook/Request$Callback;' 06-18 12:03:34.857: W/dalvikvm(24494): Link of class 'Lfacebook/FacebookController$FacebookRequestCallbackListener;' failed 06-18 12:03:34.857: D/dalvikvm(24494): DexOpt: unable to opt direct call 0xdfaa at 0x1a in Lfacebook/FacebookController;.facebookRequest 06-18 12:03:34.867: I/Corona(24494): Runtime error 06-18 12:03:34.867: I/Corona(24494): java.lang.NoClassDefFoundError: com.facebook.Session 06-18 12:03:34.867: I/Corona(24494): Java Stack Trace: 06-18 12:03:34.867: I/Corona(24494): facebook.FacebookController.facebookLogin(FacebookController.java:143) 06-18 12:03:34.867: I/Corona(24494): facebook.LuaLoader$LoginWrapper.invoke(LuaLoader.java:98) 06-18 12:03:34.867: I/Corona(24494): com.ansca.corona.JavaToNativeShim.nativeTapEvent(Native Method) 06-18 12:03:34.867: I/Corona(24494): com.ansca.corona.JavaToNativeShim.tapEvent(JavaToNativeShim.java:387) 06-18 12:03:34.867: I/Corona(24494): com.ansca.corona.input.RaiseTapEventTask.executeUsing(RaiseTapEventTask.java:43) 06-18 12:03:34.867: I/Corona(24494): com.ansca.corona.CoronaRuntimeTaskDispatcher$TaskEvent.Send(CoronaRuntimeTaskDispatcher.java:148) 06-18 12:03:34.867: I/Corona(24494): com.ansca.corona.events.EventManager.sendEvents(EventManager.java:91) 06-18 12:03:34.867: I/Corona(24494): com.ansca.corona.Controller.updateRuntimeState(Controller.java:285) 06-18 12:03:34.867: I/Corona(24494): com.ansca.corona.graphics.opengl.CoronaGLSurfaceView$CoronaRenderer.onDrawFrame(CoronaGLSurfaceView.java:417) 06-18 12:03:34.867: I/Corona(24494): com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1622) 06-18 12:03:34.867: I/Corona(24494): com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1377) 06-18 12:03:34.867: I/Corona(24494): stack traceback: 06-18 12:03:34.867: I/Corona(24494): [C]: in function 'newLogin' 06-18 12:03:34.867: I/Corona(24494): ?: in functio

I figured that maybe I needed to copy the src/com/facebook folder into my project but that hasn’t worked either.

The only other thing I can think is to copy those files into src/com/myproj and rename package com.facebook; to package com.quiztix.myapp;  

Thought I’d ask first, in case you have any advice on this.  

Thanks,

Alan

Yeah, I do.

I have facebook sdk copied to a enterprise/plugins/sdk-facebook directory

Then I reference this directory in my project properties:

android.library.reference.1=${CoronaEnterpriseDir}/Plugins/<path to sdk>

and it seems to be working ok.

Please remember to add in the facebook sdk’s project.properties

android.library=true

Also you have to have in your project’s libs directory:

facebook.jar

from Corona’s plugins.

Hmmm. That’s exactly how I had it all setup before implementing multidex. 

I’ve just undone all of today’s changes so that my project matches your description, but I still get the errors posted above. It’s as if it hasn’t linked that facebook project correctly to my own project.

Before implementing multidexing my project.properties contained this:

android.library.reference.1=${CoronaEnterpriseDir}/Corona/android/lib/Corona android.library.reference.2=../../../../mainrepo/enterprise/Plugins/sdk-facebook/android

When I copied across the Corona files as you first suggested, I had to comment out the Corona line above (leaving just the facebook line) otherwise it wouldn’t work. I’m a bit confused why the Facebook line still works for you if you had to manually copy across the Corona files, and why it doesn’t work for me. 

Is there perhaps another setting in your build.xml file or elsewhere that I may have missed out?

Did you have to add the multidex stuff to your facebook sdk’s build.xml file as well?   

I’m running out of ideas about how to get this to work  :frowning:

Sorry Alan,

please bring it to private if you still have issues.

Uhmm… have you actually got the facebook sdk there?

I had to download it manually I think, or get it from some old corona enterprise plugins, now whenever I update corona I have to copy it manually.

PM me and we can take it to skype if you have more issues.

Krystian was kind enough to take a look at this for me, but we’ve had no joy yet.  

Can someone from Corona maybe comment on anything that could be causing this problem?  

There’s more detail in the earlier posts, but to sum it up:

  1. Needed to use multidexing due to dalvik 65536 method limit.

  2. Added multidexing, the apk built successfully but on running it said that some Corona files were missing.  

  3. @krystian6 suggested copying the Corona files from the Enterprise folder into the project, instead of referencing them in project.properties - this worked and the app would run. 

  4. Facebook login now fails - it seems for the same reason that the Corona files did. However I do not seem to be able to just copy the Facebook SDK files into my project, because there are some src/com/facebook files which require the AndroidManifest that is in the Facebook SDK project and I cannot have 2 in my project (unless I’m missing something).

  5. Now stuck as I cannot work out how to include the referenced project in my multidex build.

My CoronaApplication.java contains this:

package com.quiztix.mygame; import android.util.Log; import com.naef.jnlua.LuaState; import android.os.\*; import android.content.Context; import android.support.multidex.\*; public class CoronaApplication extends MultiDexApplication { /\*\* Called when your application has started. \*/ @Override public void onCreate() { // Set up a Corona runtime listener used to add custom APIs to Lua. com.ansca.corona.CoronaEnvironment.addRuntimeListener(new CoronaApplication.CoronaRuntimeEventHandler()); } @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(base); }

I’ve added the android-support-multidex.jar library to my project, and my build.xml is unchanged from my earlier post, and I’ve tried with and without having 

android.library.reference.1=../../../../quiztixmain/enterprise/Plugins/sdk-facebook/android

in my project.properties file (the location of the SDK is valid btw, it’s worked in my project for over a year when not using multidexing).

After trying lots of different things I still can’t get it to detect the FB-sdk project files (for all I know it’s not actually building them in as it would when not using multi-dexing).

If a Corona engineer could give some advice that would be a huge help.

Is anyone from Corona please able to offer some advice on how to get multidex working with Corona+ant?

Again I ended up having to circumvent the problem by removing some lesser used libs, but now I’m at the point where I’m trying to add some more libs but that is causing me to go over the 65536 limit.  

I’m sure one of Corona’s Android engineers will have experience in this, and will know how to get multi-dex working in a project which also has references in it’s project.properties file…but no one from Corona has replied at all to this topic since it was first posted back in January.