Link individual jar files for Android build

I understand that currently cocos console build system will link with whatever jars are in proj.android/libs/. This is quite inconvenient since sometimes I would use different jars for different build arguments(MACRO switchs for C++). Is it possible to specify different build targets or different linking rules in the current cocos console build system?

Having same issue,

How to link specific JAR’s without placing them in lib folder.

One solution we have worked with, we changed build.xml file in proj.android folder:
added following code part

 <target name="-pre-compile">
        <!-- Redefine project.all.jars.path before -compile executes -->
        <path id="project.all.jars.path">
                <fileset file="../cocos2d/cocos/platform/android/java/bin/classes.jar" />
                <fileset file="../third_party/Android/android-support-v4.jar" />
                <fileset file="../third_party/google-play-services_lib/libs/google-play-services.jar" />
                <fileset file="../third_party/Android/android-support-v7-appcompat.jar" />
                <fileset file="../third_party/Android/AudienceNetwork.jar" />
                <fileset file="../third_party/Android/InMobi-4.5.3.jar" />
                <fileset file="../third_party/Android/mopub-volley-1.1.0.jar" />
                <fileset file="../third_party/mopub-sdk/bin/classes.jar" />

                <fileset file="../third_party/Android/Vungle/dagger-1.2.2.jar" />
                <fileset file="../third_party/Android/Vungle/javax.inject-1.jar" />
                <fileset file="../third_party/Android/Vungle/nineoldandroids-2.4.0.jar" />
    
                <fileset file="../third_party/Android/Vungle/vungle-publisher-adaptive-id-3.3.0.jar" />
        </path>
    </target>

This code works, but if we use this construction, we should add there all JAR files used in project otherwise it will crash. Is there other way to add third party JAR’s ?

1 Like

bump for more visibility.

This worked for me, I had to add cocos2d’s jar like your example, and include the support v4 and ACRA jars in my case. Not sure about the android.mk changes I made though, thanks!

Hi,
Are u still using cocos2dx 2.x version? We found the way to add android studio support for older cocos so it is much easier now to compile and maintain jar files thru gradle stuff

Hey, no I’m on 3.10. Have you written it down, maybe I could apply that solution to 3.10. As far as I know, only like 3.13 onwards supports android studio. I’d love to save myself the headache for sure so I’d love to heard what you’ve found.

Yes, it definetly should be possible, in my case I added from 3.15 proj.android-studio folder to project then copied gradle files from cocos2d core, adjusted project android.mk and it was working

1 Like

Oh cool, sounds simple enough, thanks!