Android Studio support

Android Studio support
0.0 0

#21

But to what value PROP_NDK_MODE should be set?


#22

cocos command will pass parameters to gradle build system to make it compatible as before.


#23

But I’m launching project directly from Android Studio. So I don’t really use cocos command a lot.


#24

No problem, the value is defined in gradle.properties. If using Android Studio, the value comes from gradle.properties, if using cocos command, it comes from cocos command.


#25

https://github.com/cocos2d/cocos2d-x/blob/v3/tests/cpp-empty-test/proj.android-studio/gradle.properties

I don’t see PROP_NDK_MODE here, what are possible values of this?


#26

PROP_TARGET_SDK_VERSION is the target version. PROP_APP_ABI is the ABI setting. I think the file has detail information. Use these variables is because cocos command need to support Android Studio projects too.


#27

Hi @zhangxm

I’m trying to run cpp-tests in v3 branch but when i run the project in android studio i get the following error , i’m building with android studio 2.3 and ndk-r13b :

Build command failed.
Error while executing process E:\android-ndk-r13b\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\cocos2d-x\tests\cpp-tests\proj.android-studio\app\jni\Android.mk NDK_APPLICATION_MK=C:\cocos2d-x\tests\cpp-tests\proj.android-studio\app\jni\Application.mk APP_ABI=armeabi NDK_ALL_ABIS=armeabi NDK_DEBUG=0 APP_PLATFORM=android-9 NDK_OUT=C:/cocos2d-x/tests/cpp-tests/proj.android-studio/app/build/intermediates/ndkBuild/release/obj NDK_LIBS_OUT=C:\cocos2d-x\tests\cpp-tests\proj.android-studio\app\build\intermediates\ndkBuild\release\lib NDK_TOOLCHAIN_VERSION=4.9 APP_PLATFORM=android-13 NDK_MODULE_PATH=../../../..:../../../../cocos:../../../../external -j8 APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
Android NDK: WARNING: Ignoring unknown import directory: ../../../..:../../../../cocos:../../../../external    
Android NDK: C:\cocos2d-x\tests\cpp-tests\proj.android-studio\app\jni\Android.mk: Cannot find module with tag 'cocos' in import path    
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?    
Android NDK: The following directories were searched:    
Android NDK:         
process_begin: CreateProcess(NULL, "", ...) failed.
Build command failed.
Error while executing process E:\android-ndk-r13b\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\cocos2d-x\tests\cpp-tests\proj.android-studio\app\jni\Android.mk NDK_APPLICATION_MK=C:\cocos2d-x\tests\cpp-tests\proj.android-studio\app\jni\Application.mk APP_ABI=armeabi NDK_ALL_ABIS=armeabi NDK_DEBUG=1 APP_PLATFORM=android-9 NDK_OUT=C:/cocos2d-x/tests/cpp-tests/proj.android-studio/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=C:\cocos2d-x\tests\cpp-tests\proj.android-studio\app\build\intermediates\ndkBuild\debug\lib NDK_TOOLCHAIN_VERSION=4.9 APP_PLATFORM=android-13 NDK_MODULE_PATH=../../../..:../../../../cocos:../../../../external -j8 APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
Android NDK: WARNING: Ignoring unknown import directory: ../../../..:../../../../cocos:../../../../external    
Android NDK: C:\cocos2d-x\tests\cpp-tests\proj.android-studio\app\jni\Android.mk: Cannot find module with tag 'cocos' in import path    
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?    
Android NDK: The following directories were searched:    
Android NDK:         
process_begin: CreateProcess(NULL, "", ...) failed. 

can you help me here please?


#28

I haven’t tested on windows. It seems the path separator is error, how about change the contents of tests/cpp-tests/proj.android-studio/app/build.gradle from

arguments 'NDK_MODULE_PATH=../../../..:../../../../cocos:../../../../external'

to

arguments 'NDK_MODULE_PATH=../../../..;../../../../cocos;../../../../external'

then try again.


#29

Thank you sir @zhangxm , it’s working now :slight_smile:


#30

@zhangxm,

Are the changes for Android Studio already in 3.14-1 from cocos2d-x.org? Or only on github?
I tried to open cpp-tests, cpp-empty-tests and one HelloWorld project but I don’t see the c++ files anywhere.


#31

I think it is only in repository - 3.14.1 was released without such functionality.


#32

Yep, it is in github repo. Will be included in next version.


#33

Glad to hear that. I will check if it works in Mac after this modification.


#34

Great work! Can’t wait for it!


#35

I have a suggestion (didn’t check github, so maybe it’s already in)… Would it be possible to mark the places where to add include files and libraries to the project with a few comments. Like:
// uncomment this line/block to add curl headers to your project
// …
// uncomment this line/block to add the curl library to your project
// …

Would ease the learning curve for new users.


#36

@samo_dadela now the Android Studio use ndk-build to build the codes. Which means you can modify Application.mk Android.mk as before to add a lib link.


#37

@michio
Use ; for path separator can not work on Mac. I will try to fix it.


#38

@michio i sent a PR to fix it: https://github.com/cocos2d/cocos2d-x/pull/17542. Could you please try it on Windows? I haven’t download Android Studio on windows. The speed is slow.


#39

@zhangxm yeah sure , i will test it now.

i havet to say the problem is with the cpp-tests , i mean i can’t run them in android studio , but any project that i made with v3 branch is ok with android studio.

Thank you for fixing this issue :slight_smile:


#40

This is great news. Do you have an estimated release date?