How to use v3.7 pro.android-studio?

Hell everyone. Yesterday I downloaded the 3.7 version and when I create a new project with cocos command line tool, I realized there is a new proj folder named android-studio with gradle and everything.

Bu I can’t find any tutorial about it, well normally with the proj.android, we use cocos command line tool to build and deploy for android, but it seems there is no script like build_native.py in proj.android-studio, and when I try to make and run it with Android Studio, it gives me some missing library errors.

Here what is like;

07-22 11:24:35.860  22141-22141/com.oms.impact E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Couldn't load cocos2dcpp from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.example.hello-2.apk,libraryPath=/data/app-lib/com.example.hello-2]: findLibrary returned null
        at java.lang.Runtime.loadLibrary(Runtime.java:355)
        at java.lang.System.loadLibrary(System.java:525)
        at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:207)
        at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:222)
        at android.app.Activity.performCreate(Activity.java:5372)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
        at android.app.ActivityThread.access$700(ActivityThread.java:159)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:176)
        at android.app.ActivityThread.main(ActivityThread.java:5419)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
        at dalvik.system.NativeStart.main(Native Method)

I think it’s related with the missing .so files. How can I natively build libraries for proj.android-studio and run my application with it?

Thank you!

To compile for android studio there was a new flag added for cocos commandline.

Try this:
cocos compile -p android --android-studio

Tomorrow we will be creating a setup video for Cocos2d-x v3.7 with Android studio§

3 Likes

Did you make the video? Can you share the link please?
Thanks!

We have not made it yet but will be very soon.

Great :smile:
Put also some part of integrating some third party SDK’s, thru gradle

+1 for the integration. I’m having trouble with simple plugin compilation (no code integrated yet, just module compilation).
See my post here: [Android Studio] NDK not configured when cocos plugin is used

Thanks!

First video will be just setting it up and getting it working but more videos will follow as per usual :smiley:

1 Like

It would be great to explain the basic principles how AndroidStudio co-exists with cocos console and with android make files.

  1. What is actually used by the compilation. Gradle configs or the Android make files?

  2. What is the configuration life-cycle? Where do I make configuration changes: android makefiles, gradle configs, android studio settings? When/what do I synchronize?

  3. What is the proper way of importing dependent modules e.g. Facebook plugins?

    a. When I’ve imported the plugin then AndroidStudio copied all the
    Java files to proj.android-studio folder. I’ve ended up with extra folders libPluginFacebook and libPluginProtocol. This might be desirable
    but not always. Sometimes you want to shared the big dependencies.

    b. where do I set the classpath? When I compile the project the I receive compilation errors shown bellow. You can see that compiling libPluginProtocol is completed and now I’m receiving the errors from libPluginFacebook:compileReleaseJava where most of them relate to dependencies to libPluginProtocol. Where do I set it? Is not sufficient to say that libPluginFacebook depends on libPluginProtocol?

Mentioned compilation errors:

Skipping task ':libPluginProtocol:assembleDebug' as it has no actions.
:libPluginProtocol:assembleDebug UP-TO-DATE
:libPluginProtocol:assembleDebug (Thread[Task worker Thread 3,5,main]) completed. Took 0.001 secs.
/pp/src/tests/testAS/TestAS/frameworks/runtime-src/proj.android-studio/libPluginFacebook/src/main/java/org/cocos2dx/plugin/FacebookWrapper.java:7: error: cannot find symbol
import com.facebook.AppEventsLogger;
                   ^
  symbol:   class AppEventsLogger
  location: package com.facebook
/pp/src/tests/testAS/TestAS/frameworks/runtime-src/proj.android-studio/libPluginFacebook/src/main/java/org/cocos2dx/plugin/FacebookWrapper.java:8: error: cannot find symbol
import com.facebook.UiLifecycleHelper;
                   ^
  symbol:   class UiLifecycleHelper
  location: package com.facebook
/pp/src/tests/testAS/TestAS/frameworks/runtime-src/proj.android-studio/libPluginFacebook/src/main/java/org/cocos2dx/plugin/FacebookWrapper.java:9: error: package com.facebook.widget does not exist
import com.facebook.widget.FacebookDialog;

Thanks a lot for giving some light into all this!
–Josef

Thanks!! I had the same problem but this command line solve it!!! :slight_smile:

Hello, do you have a progress on the videos? Perhaps it is done and we don’t know where to find them…

Is there any document describing the cocos/Android Studio cooperation?
There is much more questions like the above and still un-answered…

Thanks!

No we haven’t created the video yet, been busy on other Cocos2d-x endeavours but will look at it soon.

We have created the Android Studio video, it is uploading right now and we will post a link very soon :smiley:

Here it is, Cocos2d-x Android Studio video tutorial:

http://www.sonarlearning.co.uk/questions.php?question-topic=300

thanks, just wanted to blame on you that you doing this video to long :slight_smile: as this is is most useful feature of 3.7 cocos.

Ok, watched video - why you not adding gradle command which will execute “cocos compile …” in command line automatically when you press run in Android Studio, so you nod need to run separately this command in terminal.

I tried to compile my app using the instructions in your video. Compilations does not succeed because of the following error:

make: Entering directory /Users/power/Documents/Projects/spacegame/proj.android-studio/app' /Applications/android-ndk-r10c/build/core/build-binary.mk:449: warning: overriding commands for targetobj/local/armeabi/objs-debug/bullet_static/BulletMultiThreaded/SpuLibspe2Support.o’
/Applications/android-ndk-r10c/build/core/build-binary.mk:449: warning: ignoring old commands for target obj/local/armeabi/objs-debug/bullet_static/BulletMultiThreaded/SpuLibspe2Support.o' make: *** No rule to make targetjni/…/…/Classes/AppDelegate.cpp’, needed by obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/AppDelegate.o'. Stop. make: *** Waiting for unfinished jobs.... [armeabi] Compile++ thumb: cocos2dcpp_shared <= main.cpp make: Leaving directory/Users/power/Documents/Projects/spacegame/proj.android-studio/app’
Error running command, return code: 2.

What rules are they talking about ? My app compiles for android fine (if I run cocos compile -p android).

The command line build works for a new project. But doesn’t seem to work for my existing project. Where should the rules for making the target be added?

I copied all the files listed in Android.mk in proj.android to Android.mk in proj.android-studio.
Otherwise the files look similar. Any changes to be made ?

  • I can compile for android fine. Just not android studio

EDIT: The problem was that the paths I specified in Android.mk for proj.android-studio was incorrect. As it is one more folder down, I should have put …/…/…/ instead of …/…/ . Its compiling now. But its taking forever for android studio to open.

Hi,

I’ve just downloaded v3.7, yesterday. However when I tried to create new project with command line tool or even with Cocos app, I don’t see any project names proj.android-studio

Is it removed from latest version ?

Regards,

I’m using 3.7 right now. It is not removed. I create a new project by doing:

cocos new MyProjectName -p com.chumbyfuzz.myprojectname -l cpp

Make sure, you really using 3.7 console not older version.