Android Studio support


#81

No, it’s an older project. I created a test project and copied the cocos2d folder into the old project, as I usually do…


#82

that why it didnt worked - u replaced cocos2d folder inside it located new build.gradle for cocos2dx core where was changed little syntax for TARGET_SDK before it was like TARGET_SDK: 22 and in 3.15 it is TARGET_SDK: PROP_TARGET_SDK_VERSION.

PROP_TARGET_SDK_VERSION definition is located in android-studio project folder , but as u using old version u missing this setup there - so create new project in 3.15 open it in android studio and check gradle config files what was changed there or manually change in cocos2d folder that gradle file to old one where is not used this variable - or just replace it by number.


#83

Thank you! That info solved my problem :slight_smile: :slight_smile:


#84

I created Sample game using Cocos2dx 3.15 and it’s running fine in studio. I’m able to compile, run and debug as well. But my problem is after I copied all my classes, resources from my other project (it’s running fine another system) and updated Android.mk file according to that. Now I’m not able to build from Android Studio. and in External Build Files Application.mk file also not showing.


#85

I’ve had the same issue with Application.mk disappearing and then the whole build stops working. This is my solution so far: After creating a new Cocos project from the command line (cocos new…) don’t add your classes right away! Instead, open up the new project in Android Studio, let it set up, test it out, then quit Android Studio. Now you can add all your files to the project, open up Android Studio, and it should work. I’m not sure if the project can become broken later on… but for me anyways, adding source code before opening a new project in Android Studio results in a broken project every time. (I don’t understand the Android setup enough to figure what is actually going on but I have it working right now :frowning:)


#86

I tried like that also no use. if I add classes 50 by 50 it’s compiling at certain point Application.mk disappearing and then the whole build stops working. I think it’s serious issue. Please help anyone in this.


#87

@zhangxm Hi Please look into this issue.
I created Sample game using Cocos2dx 3.15 and it’s running fine in studio. I’m able to compile, run and debug as well. But my problem is after I copied all my classes, resources from my other project (it’s running fine another system) and updated Android.mk file according to that. Now I’m not able to build from Android Studio. and in External Build Files Application.mk file also not showing.


#88

I think you should clean and recompile the project to have a try. May be should clean cache too. I am not sure, but i think Android Studio cached something and cause the issue.


#89

@zhangxm I created new project using 3.15 and copied my classes and resources then built and ran from command line. It’s successfully running. I opened corresponding studio project. Here in Android Studio I’m able to compile, run and debug till here everything is fine. After that I uploaded to Bitbucket. I cloned opened with android studio in another system. Here build failed in External build files Application.mk is not showing.
So I created new project from this system. I opened new project in Android Studio here also I’m able to compile, run and debug. If I copy my classes and resources and try to build, build is failed it’s not showing Application.mk file. I don’t know where I’m doing wrong.


#90

Does it failed only change classes and resources?


#91

Yes. and I updated the Android.mk file mentioning all my classes.


#92

Ok, i will try to add some dummy cpp files into cpp-empty-test to have a try.


#93

I tested with cpp-empty-test, no problem.


#94

Did built directly from studio or command-line?


#95

Directly from Android Studio.


#96

Hi it’s working fine in Mac. I opened same project opened Mac there it’s fine. I’m facing this issue with Ubuntu. is that a configuration issue?


#97

@zhangxm Or else can you tell me the process what is the proper way to add Classes, Resources and updating Android.mk file using sAndroid Studio?


#98

@zhangxm This is the error I’m getting if I’m adding classes
Error while executing process /home/prasanna/Documents/Prasanna/android-sdks/ndk-bundle/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/home/prasanna/Desktop/Demo/proj.android-studio/app/jni/Android.mk NDK_APPLICATION_MK=/home/prasanna/Desktop/Demo/proj.android-studio/app/jni/Application.mk APP_ABI=armeabi NDK_ALL_ABIS=armeabi NDK_DEBUG=1 APP_PLATFORM=android-9 NDK_OUT=/home/prasanna/Desktop/Demo/proj.android-studio/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/home/prasanna/Desktop/Demo/proj.android-studio/app/build/intermediates/ndkBuild/debug/lib NDK_TOOLCHAIN_VERSION=4.9 APP_PLATFORM=android-13 NDK_MODULE_PATH=/home/prasanna/Desktop/Demo/cocos2d:/home/prasanna/Desktop/Demo/cocos2d/cocos:/home/prasanna/Desktop/Demo/cocos2d/external -j4 NDK_DEBUG=1 APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}


#99

Does the currently shipped project template in 3.15 work?

Creating a new project with
cocos new Test -p com.asd.test -l cpp -d ~/test

That neither contains a cpp directory in project navigator when build/synced

nor runs on simulator (the library does not seem to be built
java.lang.UnsatisfiedLinkError: Couldn't load MyGame: findLibrary returned null

I’ve tried reading the thread and switching compileSdkVersion to 25 and buildToolsVersion to 25.0.1 with no effect.

Tested on both Android Studio 2.3.1 and 3.0 Canary 1 on MacOS
Attempted with both NDK 10e and 14b (not sure if this makes a difference)

I was hoping to switch an existing project to this but it doesn’t look like even the sample project works with stable android versions…


#100

@prasannaboppe adding resources is free, you don’t have to modify anything, just add resources into the folder. Adding .cpp files, you should just modify proj.android-studio/app/jni/Application.mk to add new files.

@Guykun yep, it should work, the QA team tested before releasing. You can try cpp-empty-test first. cocos command will copy engine when generating a new project, have you run setup.py to update environment variables?