Android developers: use Visual Studio!

If you so, can you post the solution back here for everyone to benefit from?

@IanHu Thanks for this.
After updating few things(CLang, android related) from VS-2015 i am able to get intellisense and also able to build apk :smile:
Now we need SDKBOX support :stuck_out_tongue_winking_eye: then its perfect.

1 Like

Can someone create setup project for Cocos2d-x 3.11.1 same as for 3.12?:slight_smile:

Right now it is tied to 3.12, AFAIK. Maybe @IanHu will make more projects for other versions in the future.

Hi @slackmoehrle

Thanks for your quick answer. I’m aware that SDKBOX isn’t supported on windows platform, either desktop or mobile. I’m currently developing my game using Visual Studio 2015 Community as I’m used to it and love it, and when I need to do specific android stuff such as sdkbox develop, I use cocos console + tools (ndk, sdk, ant…) but I miss powerful/visual debugging interface that VS gives.

So, what I’m asking it’s not supporting windows stuff (that would be a request to SDKBOX team), I’m asking the possibility to compile and run/debug with the tools that @ianhu provided. I haven’t done any research, but being so close, my guess is that it may just be find the right place to append SDKBOX’s JAR files (and these files are listed in the ‘manual integration’ section of documentation for each plugin) and add search paths too or copy .H files (again, steps are documented both for xcode and console).

This is my wish list to be the perfect tool for me, but anyway, must say it’s a great wonderful job, and it’s just his first release, so i’m sure more will come and we can only THANK him for that, but being a truly noob when diving in android’s world, i just thought an expert would find it easier to solve it.

@smitpatel88 Glad to see that it’s working for you with Clang installed.

@ishmar I’m pretty sure that your guess is close (adding some new file path locations and .jar files) for SDKBOX integration as I was starting to take a peek at this. While I’m a bit familiar with Cocos SDKBOX is pretty new to me. My slight worry here is that SDKBOX expects to update all the dependences apart from Cocos. Meaning that my template would have to be customized to both a specific version of Cocos as well as each specific version of each SDKBOX component. I think that I’ll probably just start by manually integrating a single plugin bundle (IAP or something) to see what is involved here. Just to set expectations though, this work is kinda a side project to my main work. So progress from me is going to be of the slow but hopefully steady variety for a while.

Hey everyone. Hopefully not too late, but I got a chance this AM to look at the SDKBOX manual integration steps. It’s obviously not as optimal as integration with the command line tool, but with a small bit of finagling I was able to integrate the SDKBOX IAP plugin with the existing template proj.visualstudio project that I provided via manual steps.

This link here has an edited proj.visualstudio template project that can be used like the previous one to show how to manually link in an SDKBOX plugin.

https://aka.ms/vscocosandroidsamplesdkbox

The project is more of an example to look back at, as the steps would be different for each different plugin. So I’ve also provided the process of how I edited the basic proj.visualstudio project to create this so that folks could do the same steps for other plugins.

Note that these steps are all relative to the existing base proj.visualstudio project in the VC++ team blog not the edited one here.

  1. Unzip the plugin .zip file

  2. From pluginzipdirectory/plugin/android/libs copy PluginGooglePlay.jar PluginIAP.jar sdkbox.jar to proj.visualstudio/Cocos2d/libs

  3. In Visual Studio right click the libs folder under the Cocos2d project. Use the “Add Existing Item” command to add in those new .jar files into the Java project. Should be in with android-async-http-1.4.8.jar

  4. From pluginzipdirectory/plugin/android/jni copy folders pluginiap and sdkbox into proj.VisualStudio/Cocos2dcpp/jni

  5. Add android.permission.INTERNET, android.permission.ACCESS_NETWORK_STATE, com.android.vending.BILLING into permissions in AndroidManifest.xml

  6. In the project properties for the Cocos2dcpp project in the Configuration Properties->VC++ Directories section. Add the paths to $(ProjectDir)\jni\sdkbox and $(ProjectDir)\jni\pluginiap into the list of Include Directories

  7. Same project properties. In Linker->General into the Additional Library Directories list add in $(ProjectDir)\jni\pluginiap\libs\armeabi-v7a and $(ProjectDir)\jni\sdkbox\libs\armeabi-v7a.

  8. Same project properties. In Linker->Input in the Library Dependencies section add in (at the end of the list) PluginIAP and sdkbox. Note that ordering matters here, PluginIAP needs to be first in the list or you will get unresolved references.

  9. In the Cocos2d java project in Visual Studio open Cocos2dxActivity.java and add in “import android.content.Intent” and import “com.sdkbox.plugin.SDKBox.”

  10. This last step was a bit funky (Integration of Google Play Services) I’m a VS guy not an android expert so there might have been a better way to do this. But with my installed Android SDK there didn’t seem to be the correct extras folder to supply the Google Play Services .jar, even when I installed them from the Android SDK Manager. What I ended up doing was downloading the R28 version of Google Play Services via this thread: http://stackoverflow.com/questions/37310684/missing-sdk-extras-google-google-play-services-libproject-folder-after-updat

  11. From the zipped R28 project I took the google-play-services.jar file, added it to the proj.visualstudio/Cocos2d/libs, then included it in VS via Add Existing Item like I did with the other libs

At this point I was able to add in some sample code from the GitHub repository for the IAP plugin. https://github.com/sdkbox/sdkbox-sample-iap
And get it all compiling, building, debugging, and running on the phone. Obviously this isn’t all as slick as the command line integrations for the existing project, but should give anyone else looking to add SDKBOX plugins to Visual Studio a bit of a head start.

5 Likes

Hey everyone. I’ve created a new project for this to work with Cocos2d-x version 3.13.1. Download it here.

https://aka.ms/vscocosandroidsample3_13_1

The blogs.msdn.com post has also been updated with this info. As a note here. I’m talking with my team here about putting this project up on the Microsoft GitHub. I plan on keeping on it for some time, but I feel that putting it online would help folks to upgrade it quicker if I’m slow off the mark like this time.

3 Likes

Thanks for the great work!

Sorry we were unaware of VS users. Since google is pushing really hard for Android Studio, unfortunately AS’s native support is still lacking after so many versions. We’ll take a look at your project and see if we can improve the SDKBOX integration, BTW is there a good library to manipulate VS project files?

Really thanks a lot… At last I succeed to compile your pattern project for Android in VS-2015, even debug works! (but very slow…) Next I tried to migrate my project:

Q-1: Can your 3.13.1-pattern be added into your previous “vscocosandroidsamplesdkbox” pattern for 3.12+SDK - to use 3.13.1 VS project with SDK function?

Q-2: If I’m not mistaken, @nite said it is possible to create Cocos2dx based app for win32, using google-play-services; if so, then @IanHu, when could we have the same pattern sets to create google-play-services app for win32? :slight_smile: …if that’s possible.

Q-3: Looks like I’ve missed “editor-support” folder in your Cocos2dcpp.vcxproj and Cocos2dcpp.vcxproj.filters ;
– fixed Looks like I do not need it anymore; wonder why.

Q-4: Also “size_t” and “malloc” can’t be found in my project; but
“$(VS_NdkRoot)\platforms\android-19\arch-arm\usr\include” is added ->
“C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r11c\platforms\android-19\arch-arm\usr\include” - what am I doing wrong during the migration of my project? I used same cpp+h files to compile for win32 (in VS-2015) and for android (from command prompt).
– fixed by adding into the cpp file #include "malloc.h" - I wonder why it was not need in win32 project version…

Q-5: In your “Cocos2dcpp.vcxproj” I see
$(VS_NdkRoot)\platforms\android-19\arch-arm\usr\include; Creating empty project that gives me double “.h” files in “Cocos2dcpp (android-19)” “External Dependencies” tree-list, for example:
c:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r11c\platforms\android-19\arch-arm\usr\include\sys\_types.h and
c:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r11c\platforms\android-19\arch-arm\usr\include\machine\_types.h - is it ok?

Step-6: A pre-last milestone for me was to realize, what I really need to replace pattern files+folders in Cocos2d/res tree-list to my files+folders.

Q-7: @IanHu, I have a big question for you about the apk release version build (selecting “Release” in VS): there appear CocosVisualStudio.apk file in ARM\Release only (or in ARM\Debug only - if “Debug” is selected in VS). Release apk is 1.2 Mb smaller than debug. But:
7.A. I still can start “Release” apk version in VS to debug it on device (step-by-step or with breakpoints);
7.B. Google Play do not accept that 1.2 Mb smaller “Release” apk, saying it is in debug mode; Also SHA1 is different than in my previous apk, released with command-prompt.
7.C. Release apk can be build without “.keystore” file - so builder does not use it in Release mode;
7.D. apk files sizes - in megabytes: :frowning:
command prompt: 6.5-release, 7.5-debug;
Visual Studio: 7.9-release, 9.1-debug;

@IanHu

First of all, thank you for working on this setup for our community. This could be the way to go in the future.

Two more questions about the whole Visual Studio Setup:

  1. I’ve seen that you use Ant in the project. Many modern frameworks (like the Facebook / Firebase / etc.) require Gradle to work. Also Android Studio uses Gradle and Google greatly pushes it for Android. Is it possible to use Gradle in Visual Studio for this Setup?

  2. Is it possible to use this together with the Visual Studio Xcode syncing feature (https://msdn.microsoft.com/en-us/library/mt748656.aspx) to have one project for Android and iOS in Visual Studio?
    This would be really awesome and be a revolution for cocos2d-x developers.

Many thanks for this extension.

Had to change the default values for android sdk, ndk, java and ant in visual studio / tools / options / cross platform, but now works great!!

Using cocos13.3.1. Can deploy to android device, do remote debugging, intellisense also works well, i’m sharing the source files with the other builds and also sharing the assets, to do this deleted the assets folder and created a hard folder link (junction), from windows command type: mklink /J assets C:\wherever\you\have\cocos\project\Resources

I can deploy to my arm device with no problem but i can’t deploy to any avd x86 emulator, visual studio does not detect it, don’t really know if this is expected to work. Anyway, many thanks again.

@IanHu Thanks a lot, commander; but seems your vscocosandroidsamplesdkbox is for sdkbox V2.2.5.3 ; and there appeared newer: V2.3.2.0 could we please have newer pack? :slight_smile:

Hello @nite and @IanHu, I think I’m close to use SDKbox & Visual Studio, but I need help.
Windows-7, VS-2015, cpp, Android:
I successfully build & run my apk (it uses AdMob ) in both cmd and VS. In cmd it works properly, if there is a line <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> in AndroidManifest.xml; but I can’t build it in VS - it needs google_play_services_version value, Q: how should I properly input that value into my VS project? Thank you.
Upd: I’ve get it; anyway my “AdMob” app shows the result (test advertising), if apk created with cocos compile ... and do not even try to download test advertising if apk created with VS :frowning:
Upd: I’ve got it working (in VS-2015); going to update after max cleaning.

Please check file proj.visualstudio\Cocos2dcpp\Cocos2dcpp.vcxproj : string
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
$(VS_NdkRoot)\sources\android\cpufeatures;$(VS_NdkRoot)\platforms\android-19\arch-arm\ - I think it should be x86 instead of arm
The same for …$(Platform)'=='Release|x86'"> string.

I did it, it costed me a week: SDKbox V2.3.2.0 for Visual Studio for cocos2d-x-3.13.1 : https://drive.google.com/file/d/0BwFbYJJmjqIkR1RraWJ0djE4eUE/view?usp=sharing

How you can play with it:

  1. Create Cocos empty cpp project;
  2. With console=cmd import into project sdkbox AdMob;
  3. Merge project with “sdkbox-sample-admob” example (google for it);
  4. Make sure you can successfully build and run it on the device - (test) advertising should appear;
  5. Then you can add unzipped proj.visualstudio_sdkbox_for_cocos2d-x-3.13.1 (make its name shorter) folder into project.

https://drive.google.com/file/d/0BwFbYJJmjqIkaEZaOTNIRXZONDQ/view?usp=sharing - here is very short zip with key differences, with test AdMob id.

Upd: but my AdMob sample doesn’t work on my Android 2.3.6 devices… :frowning:

Hello, I’m tying to add fmod precompiled library. I’ve added the libfmodL.so and libfmodstudioL.so libraries to linker addtional dependencies, also updated the include paths and everithing compiles fine but hangs after deploy because libraries are not installed in the system.

Also added fmod.jar to the project and project libs folder, same place android-async and other .jar

dlopen("/data/app/com.CocosVisualStudio-2/lib/arm/libcocos2dcpp.so", RTLD_LAZY) failed dlopen failed: could not load library "libfomdstudioL.so" needed by "libcocos2dcpp.so"; caused by library "libfmodstudioL.so" not foud.
FATAL EXCEPTION: main

So my quiestion is wich Android.mk and or Application.mk or whatever have to edit to deploy the library with my project. I’m not Android expert at all and really struggling with this. Thanks a lot.

Is there some sort of android simulator like when using eclipse? I mean right now it is just making a window that has the design size…

Answered myself in a new thread think is big enough:

http://discuss.cocos2d-x.org/t/setting-up-a-precompiled-library-fmod-with-visual-studio-win32-and-visual-studio-android/